fyodorov-llm-agents 0.0.58__py3-none-any.whl → 0.0.60__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.
- fyodorov_llm_agents/agents/base_agent.py +92 -7
- fyodorov_llm_agents/agents/openai.py +2 -2
- fyodorov_llm_agents/prompts/__init__.py +0 -0
- fyodorov_llm_agents/prompts/prompt.py +0 -0
- fyodorov_llm_agents/tools/tool.py +1 -0
- {fyodorov_llm_agents-0.0.58.dist-info → fyodorov_llm_agents-0.0.60.dist-info}/METADATA +1 -1
- fyodorov_llm_agents-0.0.60.dist-info/RECORD +12 -0
- fyodorov_llm_agents-0.0.58.dist-info/RECORD +0 -10
- {fyodorov_llm_agents-0.0.58.dist-info → fyodorov_llm_agents-0.0.60.dist-info}/WHEEL +0 -0
- {fyodorov_llm_agents-0.0.58.dist-info → fyodorov_llm_agents-0.0.60.dist-info}/top_level.txt +0 -0
@@ -1,19 +1,35 @@
|
|
1
|
-
from abc import ABC, abstractmethod
|
2
1
|
from fyodorov_llm_agents.tools.tool import Tool
|
3
2
|
import re
|
4
3
|
import requests
|
5
4
|
|
6
|
-
class
|
7
|
-
def __init__(self, api_key, tools: [Tool] = [], rag: [] = []):
|
5
|
+
class BaseAgent():
|
6
|
+
def __init__(self, api_key, tools: [Tool] = [], rag: [] = [], model: str = "gpt-3.5-turbo"):
|
8
7
|
self.api_key = api_key
|
9
8
|
self.tools = tools
|
10
9
|
self.rag = rag
|
10
|
+
self.model = model
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def call(self, prompt: str = "", input: str = "", temperature: float = 0.0):
|
13
|
+
print(f"[OpenAI] Calling OpenAI with prompt: {prompt}, input: {input}, temperature: {temperature}")
|
14
|
+
if temperature > 2.0 or temperature < 0.0:
|
15
|
+
raise ValueError("Temperature must be between 0.0 and 2.0")
|
15
16
|
|
16
|
-
|
17
|
+
response = self.client.chat.completions.create(
|
18
|
+
messages=[
|
19
|
+
{"role": "system", "content": prompt},
|
20
|
+
{"role": "user", "content": input},
|
21
|
+
],
|
22
|
+
temperature=temperature,
|
23
|
+
model=self.model,
|
24
|
+
)
|
25
|
+
|
26
|
+
# Process the response as needed
|
27
|
+
print(f"Response: {response}")
|
28
|
+
answer = response.choices[0].message.content
|
29
|
+
print(f"Answer: {answer}")
|
30
|
+
return str(answer)
|
31
|
+
|
32
|
+
def invoke(self, prompt: str = "", input: str = "", temperature: float = 0.0, depth: int = 0) -> str:
|
17
33
|
res = self.call(prompt, input, temperature)
|
18
34
|
print("llm response:", res)
|
19
35
|
if len(self.tools) > 0:
|
@@ -34,6 +50,75 @@ class AbstractAgent(ABC):
|
|
34
50
|
return self.invoke(prompt, input)
|
35
51
|
return res
|
36
52
|
|
53
|
+
def streaming_call(result_queue):
|
54
|
+
try:
|
55
|
+
# Simulate defining multiple functions that the model can choose to call
|
56
|
+
functions = [
|
57
|
+
{
|
58
|
+
"name": "get_current_weather",
|
59
|
+
"description": "Get the current weather for a location",
|
60
|
+
"parameters": {
|
61
|
+
"type": "object",
|
62
|
+
"properties": {
|
63
|
+
"location": {"type": "string"},
|
64
|
+
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
|
65
|
+
},
|
66
|
+
"required": ["location"]
|
67
|
+
}
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"name": "get_n_day_weather_forecast",
|
71
|
+
"description": "Get a weather forecast for a number of days",
|
72
|
+
"parameters": {
|
73
|
+
"type": "object",
|
74
|
+
"properties": {
|
75
|
+
"location": {"type": "string"},
|
76
|
+
"num_days": {"type": "integer"},
|
77
|
+
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
|
78
|
+
},
|
79
|
+
"required": ["location", "num_days"]
|
80
|
+
}
|
81
|
+
}
|
82
|
+
]
|
83
|
+
|
84
|
+
# Example request that could potentially trigger multiple function calls
|
85
|
+
response = openai.ChatCompletion.create(
|
86
|
+
model=self.model,
|
87
|
+
messages=[
|
88
|
+
{"role": "user", "content": "What's the weather today and the forecast for the next 4 days in San Francisco?"}
|
89
|
+
],
|
90
|
+
functions=functions
|
91
|
+
)
|
92
|
+
|
93
|
+
# Process the response assuming it might include multiple tool calls
|
94
|
+
if 'choices' in response and response['choices']:
|
95
|
+
tool_calls = response['choices'][0]['message']['tool_calls']
|
96
|
+
if tool_calls:
|
97
|
+
result_queue.put(json.dumps(tool_calls))
|
98
|
+
else:
|
99
|
+
print("No function calls detected.")
|
100
|
+
answer = response.choices[0].message.content
|
101
|
+
result_queue.put(answer)
|
102
|
+
else:
|
103
|
+
result_queue.put("Invalid response format.")
|
104
|
+
|
105
|
+
result_queue.put(None) # Signal the end of streaming
|
106
|
+
except Exception as e:
|
107
|
+
result_queue.put(str(e))
|
108
|
+
result_queue.put(None)
|
109
|
+
|
110
|
+
async def invoke_async(self, prompt: str = "", input: str = "", temperature: float = 0.0, depth: int = 0):
|
111
|
+
result_queue = queue.Queue()
|
112
|
+
thread = threading.Thread(target=streaming_call, args=(result_queue,))
|
113
|
+
thread.start()
|
114
|
+
|
115
|
+
while True:
|
116
|
+
result = result_queue.get()
|
117
|
+
if result is None: # End of stream
|
118
|
+
break
|
119
|
+
else:
|
120
|
+
yield result.encode()
|
121
|
+
|
37
122
|
def add_tool(self, tool: Tool):
|
38
123
|
self.tools.append(tool)
|
39
124
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
from openai import OpenAI as oai
|
2
|
-
from .base_agent import
|
2
|
+
from .base_agent import BaseAgent
|
3
3
|
|
4
4
|
DEFAULT_MODEL: str = "gpt-3.5-turbo"
|
5
5
|
|
6
|
-
class OpenAI(
|
6
|
+
class OpenAI(BaseAgent):
|
7
7
|
tools: list = []
|
8
8
|
rag: list = []
|
9
9
|
model: str = DEFAULT_MODEL
|
File without changes
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: fyodorov_llm_agents
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.60
|
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
|
@@ -0,0 +1,12 @@
|
|
1
|
+
fyodorov_llm_agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
fyodorov_llm_agents/agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
fyodorov_llm_agents/agents/base_agent.py,sha256=-ws8d0FA1Q8iAVvOyCuG44n04nakBSPofWYvAli52xE,9091
|
4
|
+
fyodorov_llm_agents/agents/openai.py,sha256=yAGV3pcFcKfwHR1zuIiv1hmmWOUjDfrJloUGECciOlw,1167
|
5
|
+
fyodorov_llm_agents/prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
fyodorov_llm_agents/prompts/prompt.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
fyodorov_llm_agents/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
+
fyodorov_llm_agents/tools/tool.py,sha256=bGZJe9stwILc4jcYsbY7-moAwy4dG6tBXg96lGqn75o,6410
|
9
|
+
fyodorov_llm_agents-0.0.60.dist-info/METADATA,sha256=YMCsfypGiM47OG7w12ffw3kJizUt9FApsbpl2hpc2Mc,2001
|
10
|
+
fyodorov_llm_agents-0.0.60.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
11
|
+
fyodorov_llm_agents-0.0.60.dist-info/top_level.txt,sha256=4QOslsBp8Gh7ng25DceA7fHp4KguTIdAxwURz97gH-g,20
|
12
|
+
fyodorov_llm_agents-0.0.60.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
fyodorov_llm_agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
fyodorov_llm_agents/agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
fyodorov_llm_agents/agents/base_agent.py,sha256=qnrUWrjmYlo6lzv05FiBjRd_GqfeiletvfWPIvsY7xk,5406
|
4
|
-
fyodorov_llm_agents/agents/openai.py,sha256=QGnc-wC6oTpomgyHK67kAtXekjdp1jcavG1relvHdH8,1175
|
5
|
-
fyodorov_llm_agents/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
fyodorov_llm_agents/tools/tool.py,sha256=5H0yRe9S-32iT7wppxPgPRTceqhFQK0xCVYk4OtnoSk,6386
|
7
|
-
fyodorov_llm_agents-0.0.58.dist-info/METADATA,sha256=ULyOMBY7MGp9Hm120YsO6bk-5reokRfI2_Gx8aHEhNk,2001
|
8
|
-
fyodorov_llm_agents-0.0.58.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
9
|
-
fyodorov_llm_agents-0.0.58.dist-info/top_level.txt,sha256=4QOslsBp8Gh7ng25DceA7fHp4KguTIdAxwURz97gH-g,20
|
10
|
-
fyodorov_llm_agents-0.0.58.dist-info/RECORD,,
|
File without changes
|
File without changes
|