ctm-space / ctm /configs /ctm_config_base.py
Haofei Yu
Feature/support ctm (#16)
acb3380 unverified
raw
history blame
No virus
1.63 kB
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)