alter_ego.structure package¶
Submodules¶
alter_ego.structure.Relay module¶
- class alter_ego.structure.Relay.Relay(source: Any, targets: List[Any])[source]¶
Bases:
object
The Relay class serves as a mediator that forwards method calls and attribute settings from a source object to multiple target objects.
- Variables:
_source – The source object.
_targets – A list of target objects.
- call_all(methodname: str, *args: Any, **kwargs: Any) None [source]¶
Invoke a method on all target objects using provided arguments.
- Parameters:
methodname (str) – The method’s name to be called on target objects.
args (Any) – Positional arguments for the method.
kwargs (Any) – Keyword arguments for the method.
Module contents¶
- class alter_ego.structure.Conversation(*threads: Thread, **named_threads: Thread)[source]¶
Bases:
object
Class encapsulating a Conversation consisting of multiple Threads.
- class alter_ego.structure.Thread(**params: Any)[source]¶
Bases:
ABC
Abstract base class representing a Thread.
- assistant(message: str, **kwargs: Any) Any [source]¶
Sends an assistant-level message.
- Parameters:
message – The message to send.
kwargs – Additional keyword arguments for message preparation.
- Returns:
Return value from the send method.
- cost() float [source]¶
Computes and returns the cost associated with the Thread.
- Returns:
The cost, 0.0 for this base implementation. Adjust in subclasses.
- property history: List[Dict[str, str]]¶
- Returns:
Deep copy of message history.
- memorize(role: str, message: str) None [source]¶
Memorizes a message and its associated role.
- Parameters:
role – Role of the message (‘system’, ‘user’, or ‘assistant’).
message – Message content.
- Raises:
ValueError – If the role is invalid or if a system message already exists.
- prepare(template: str, **extra: Any) str [source]¶
Prepare a template with additional parameters.
- Parameters:
template – Template string.
extra – Additional parameters to inject into the template.
- Returns:
Rendered template string.
- save(subdir: str = '.', outdir: str = 'out', full_save: bool = True) None [source]¶
Saves the current Thread into a file.
- Parameters:
subdir – The sub-directory to save the file in.
outdir – The main directory to save the file in.
full_save – Whether to save as pickle (True) or JSON (False).
- Raises:
ValueError – If the Thread is not part of a Conversation.
- abstract send(role: str, message: str, **kwargs: Any) Any [source]¶
Abstract method that must be implemented by subclasses to send messages.
- Parameters:
role – Role of the sender, can be ‘system’, ‘user’, or ‘assistant’.
message – The message to be sent.
kwargs – Additional keyword arguments.
- Returns:
Implementation dependent.
- submit(message: str, **kwargs: Any) Any [source]¶
Submits a message as a user and sends it after preparation.
- Parameters:
message – The message to submit.
kwargs – Additional keyword arguments for message preparation.
- Returns:
Return value from the send method.