File size: 1,866 Bytes
acb3380
084fe8e
acb3380
 
084fe8e
acb3380
 
084fe8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
acb3380
 
 
084fe8e
acb3380
 
 
 
084fe8e
 
 
acb3380
 
 
 
 
 
084fe8e
acb3380
 
 
 
 
 
084fe8e
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
46
47
48
49
import json
from typing import Any, Dict, Optional


class BaseConsciousnessTuringMachineConfig:
    def __init__(
        self,
        ctm_name: Optional[str] = None,
        max_iter_num: int = 3,
        output_threshold: float = 0.5,
        groups_of_processors: Dict[
            str, Any
        ] = {},  # Better to avoid mutable default arguments
        supervisor: str = "gpt4_supervisor",
        **kwargs: Any,
    ) -> None:
        self.ctm_name: Optional[str] = ctm_name
        self.max_iter_num: int = max_iter_num
        self.output_threshold: float = output_threshold
        self.groups_of_processors: Dict[str, Any] = groups_of_processors
        self.supervisor: str = supervisor
        # Handle additional, possibly unknown configuration parameters
        for key, value in kwargs.items():
            setattr(self, key, value)

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

    @classmethod
    def from_json_file(
        cls, json_file: str
    ) -> "BaseConsciousnessTuringMachineConfig":
        """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: str) -> "BaseConsciousnessTuringMachineConfig":
        """
        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_conf/{ctm_name}_config.json"
        return cls.from_json_file(config_file)