aboutsummaryrefslogtreecommitdiff
path: root/autogpts/autogpt/autogpt/config/ai_profile.py
diff options
context:
space:
mode:
Diffstat (limited to 'autogpts/autogpt/autogpt/config/ai_profile.py')
-rw-r--r--autogpts/autogpt/autogpt/config/ai_profile.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/autogpts/autogpt/autogpt/config/ai_profile.py b/autogpts/autogpt/autogpt/config/ai_profile.py
new file mode 100644
index 000000000..970f8278c
--- /dev/null
+++ b/autogpts/autogpt/autogpt/config/ai_profile.py
@@ -0,0 +1,68 @@
+from pathlib import Path
+
+import yaml
+from pydantic import BaseModel, Field
+
+
+class AIProfile(BaseModel):
+ """
+ Object to hold the AI's personality.
+
+ Attributes:
+ ai_name (str): The name of the AI.
+ ai_role (str): The description of the AI's role.
+ ai_goals (list): The list of objectives the AI is supposed to complete.
+ api_budget (float): The maximum dollar value for API calls (0.0 means infinite)
+ """
+
+ ai_name: str = ""
+ ai_role: str = ""
+ ai_goals: list[str] = Field(default_factory=list[str])
+ api_budget: float = 0.0
+
+ @staticmethod
+ def load(ai_settings_file: str | Path) -> "AIProfile":
+ """
+ Returns class object with parameters (ai_name, ai_role, ai_goals, api_budget)
+ loaded from yaml file if it exists, else returns class with no parameters.
+
+ Parameters:
+ ai_settings_file (Path): The path to the config yaml file.
+
+ Returns:
+ cls (object): An instance of given cls object
+ """
+
+ try:
+ with open(ai_settings_file, encoding="utf-8") as file:
+ config_params = yaml.load(file, Loader=yaml.FullLoader) or {}
+ except FileNotFoundError:
+ config_params = {}
+
+ ai_name = config_params.get("ai_name", "")
+ ai_role = config_params.get("ai_role", "")
+ ai_goals = [
+ str(goal).strip("{}").replace("'", "").replace('"', "")
+ if isinstance(goal, dict)
+ else str(goal)
+ for goal in config_params.get("ai_goals", [])
+ ]
+ api_budget = config_params.get("api_budget", 0.0)
+
+ return AIProfile(
+ ai_name=ai_name, ai_role=ai_role, ai_goals=ai_goals, api_budget=api_budget
+ )
+
+ def save(self, ai_settings_file: str | Path) -> None:
+ """
+ Saves the class parameters to the specified file yaml file path as a yaml file.
+
+ Parameters:
+ ai_settings_file (Path): The path to the config yaml file.
+
+ Returns:
+ None
+ """
+
+ with open(ai_settings_file, "w", encoding="utf-8") as file:
+ yaml.dump(self.dict(), file, allow_unicode=True)