fyodorov-llm-agents 0.0.92__py3-none-any.whl → 0.0.93__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,13 +6,71 @@ import threading
6
6
  import json
7
7
  from openai import OpenAI as oai
8
8
 
9
+ MAX_NAME_LENGTH = 80
10
+ MAX_DESCRIPTION_LENGTH = 280
11
+ VALID_CHARACTERS_REGEX = r'^[a-zA-Z0-9\s.,!?:;\'"-]+$'
12
+
9
13
  class BaseAgent():
10
- def __init__(self, api_key, tools: [Tool] = [], rag: [] = [], model: str = "gpt-3.5-turbo"):
14
+ provider_id: str
15
+ name_for_human: str
16
+ description_for_human: str
17
+ prompt: str
18
+
19
+ def __init__(
20
+ self,
21
+ api_key,
22
+ tools: [Tool] = [],
23
+ rag: [] = [],
24
+ model: str = "gpt-3.5-turbo",
25
+ name_for_human: str = "My Agent",
26
+ description_for_human: str = "My Agent",
27
+ prompt: str = "My Prompt",
28
+ prompt_size: int = 10000,
29
+ temperature: float = 0.8,
30
+ ):
11
31
  self.api_key = api_key
12
32
  self.client = oai(api_key=api_key)
13
33
  self.tools = tools
14
34
  self.rag = rag
15
35
  self.model = model
36
+ self.name_for_human = name_for_human
37
+ self.description_for_human = description_for_human
38
+ self.prompt = prompt
39
+ self.validate()
40
+
41
+ def validate(self):
42
+ BaseAgent.validate_name_for_human(self.name_for_human)
43
+ BaseAgent.validate_description_for_human(self.description_for_human)
44
+ BaseAgent.validate_prompt(self.prompt, self.prompt_size)
45
+
46
+ @staticmethod
47
+ def validate_name_for_human(name_for_human: str) -> str:
48
+ if not name_for_human:
49
+ raise ValueError('Name for human is required')
50
+ if len(name_for_human) > MAX_NAME_LENGTH:
51
+ raise ValueError('Name for human exceeds maximum length')
52
+ if not re.match(VALID_CHARACTERS_REGEX, name_for_human):
53
+ raise ValueError('Name for human contains invalid characters')
54
+ return name_for_human
55
+
56
+ @staticmethod
57
+ def validate_description_for_human(description_for_human: str) -> str:
58
+ if not description_for_human:
59
+ raise ValueError('Description for human is required')
60
+ if len(description_for_human) > MAX_DESCRIPTION_LENGTH:
61
+ raise ValueError('Description for human exceeds maximum length')
62
+ if not re.match(VALID_CHARACTERS_REGEX, description_for_human):
63
+ raise ValueError('Description for human contains invalid characters')
64
+ return description_for_human
65
+
66
+ @staticmethod
67
+ def validate_prompt(prompt: str, prompt_size: int) -> str:
68
+ if not prompt:
69
+ raise ValueError('Prompt is required')
70
+ if len(prompt) > prompt_size:
71
+ raise ValueError('Prompt exceeds maximum length')
72
+ return prompt
73
+
16
74
 
17
75
  def call(self, prompt: str = "", input: str = "", temperature: float = 0.0):
18
76
  print(f"[OpenAI] Calling OpenAI with prompt: {prompt}, input: {input}, temperature: {temperature}")
@@ -154,6 +212,25 @@ class BaseAgent():
154
212
  print(f"type of result: {type(result)}")
155
213
  yield result.encode()
156
214
 
215
+ @staticmethod
216
+ def from_yaml(yaml_str: str):
217
+ """Instantiate BaseAgent from YAML."""
218
+ if not yaml_str:
219
+ raise ValueError('YAML string is required')
220
+ agent_dict = yaml.safe_load(yaml_str)
221
+ agent = cls(
222
+ api_key=agent_dict["api_key"],
223
+ model=agent_dict["model"],
224
+ tools=agent_dict["tools"],
225
+ rag=agent_dict["rag"],
226
+ name_for_human=agent_dict["name_for_human"],
227
+ description_for_human=agent_dict["description_for_human"],
228
+ prompt=agent_dict["prompt"],
229
+ temperature=agent_dict["temperature"],
230
+ prompt_size=agent_dict["prompt_size"],
231
+ )
232
+ return agent
233
+
157
234
  def add_tool(self, tool: Tool):
158
235
  self.tools.append(tool)
159
236
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fyodorov_llm_agents
3
- Version: 0.0.92
3
+ Version: 0.0.93
4
4
  Summary: Library for creating LLM-based agents with tools and RAG
5
5
  Author-email: Daniel Ransom <02masseur.alibis@icloud.com>
6
6
  Project-URL: Homepage, https://github.com/FyodorovAI/fyodorov-llm-agents
@@ -1,12 +1,12 @@
1
1
  fyodorov_llm_agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  fyodorov_llm_agents/agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- fyodorov_llm_agents/agents/base_agent.py,sha256=uEgjX95kQcImDCs_epTUuprmB0sjWMEODX2DOFtzUgc,11142
3
+ fyodorov_llm_agents/agents/base_agent.py,sha256=YTUV3bokCxm_Cf2FxYdLHOjP4Gj-8xNN8pAl30NXz9Q,13949
4
4
  fyodorov_llm_agents/agents/openai.py,sha256=yAGV3pcFcKfwHR1zuIiv1hmmWOUjDfrJloUGECciOlw,1167
5
5
  fyodorov_llm_agents/prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  fyodorov_llm_agents/prompts/prompt.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  fyodorov_llm_agents/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  fyodorov_llm_agents/tools/tool.py,sha256=7N_v1I0lRkDrT1qTYlEgcxzbrLopH-uegkyybSV8BEk,6976
9
- fyodorov_llm_agents-0.0.92.dist-info/METADATA,sha256=8Jy4_JPzjFVohir_gNFLKdYPl6cDr_WBqZ73HmNfSxk,2001
10
- fyodorov_llm_agents-0.0.92.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
11
- fyodorov_llm_agents-0.0.92.dist-info/top_level.txt,sha256=4QOslsBp8Gh7ng25DceA7fHp4KguTIdAxwURz97gH-g,20
12
- fyodorov_llm_agents-0.0.92.dist-info/RECORD,,
9
+ fyodorov_llm_agents-0.0.93.dist-info/METADATA,sha256=uIM52gkBYD59OE7hUVOER6xr-rnButDgHetvHMA0wHM,2001
10
+ fyodorov_llm_agents-0.0.93.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
11
+ fyodorov_llm_agents-0.0.93.dist-info/top_level.txt,sha256=4QOslsBp8Gh7ng25DceA7fHp4KguTIdAxwURz97gH-g,20
12
+ fyodorov_llm_agents-0.0.93.dist-info/RECORD,,