File size: 1,627 Bytes
acb3380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json


class BaseConsciousnessTuringMachineConfig(object):
    # Initialize with default values or those passed to the constructor
    def __init__(
        self,
        ctm_name=None,
        max_iter_num=3,
        output_threshold=0.5,
        groups_of_processors={},
        supervisor="gpt4_supervisor",
        **kwargs,
    ):
        self.ctm_name = ctm_name
        self.max_iter_num = max_iter_num
        self.output_threshold = output_threshold
        self.groups_of_processors = groups_of_processors
        self.supervisor = supervisor
        # This allows for handling additional, possibly unknown configuration parameters
        for key, value in kwargs.items():
            setattr(self, key, value)

    def to_json_string(self):
        """Serializes this instance to a JSON string."""
        return json.dumps(self.__dict__, indent=2) + "\n"

    @classmethod
    def from_json_file(cls, json_file):
        """Creates an instance from a JSON file."""
        with open(json_file, "r", encoding="utf-8") as reader:
            text = reader.read()
        return cls(**json.loads(text))

    @classmethod
    def from_ctm(cls, ctm_name):
        """
        Simulate fetching a model configuration from a ctm model repository.
        This example assumes the configuration is already downloaded and saved locally.
        """
        # This path would be generated dynamically based on `model_name_or_path`
        # For simplicity, we're directly using it as a path to a local file
        config_file = f"../ctm/configs/{ctm_name}_config.json"
        return cls.from_json_file(config_file)