Commit ·
1f35fad
1
Parent(s): ad0d3ca
Updating formatting
Browse files
src/manager/manager.py
CHANGED
|
@@ -126,8 +126,9 @@ class GeminiManager:
|
|
| 126 |
"message": f"Tool `{function_call.name}` failed to run.",
|
| 127 |
"output": str(e),
|
| 128 |
}
|
| 129 |
-
|
| 130 |
-
|
|
|
|
| 131 |
yield {
|
| 132 |
"role": "assistant",
|
| 133 |
"content": thinking,
|
|
@@ -226,9 +227,10 @@ class GeminiManager:
|
|
| 226 |
return formatted_history
|
| 227 |
|
| 228 |
def get_k_memories(self, query, k=5, threshold=0.0):
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
|
|
|
| 232 |
if len(memories) == 0:
|
| 233 |
return []
|
| 234 |
top_k = min(k, len(memories))
|
|
@@ -250,7 +252,7 @@ class GeminiManager:
|
|
| 250 |
results = []
|
| 251 |
for score, idx in zip(scores, indices):
|
| 252 |
if score >= threshold:
|
| 253 |
-
results.append(
|
| 254 |
return results
|
| 255 |
|
| 256 |
def run(self, messages):
|
|
@@ -265,7 +267,7 @@ class GeminiManager:
|
|
| 265 |
})
|
| 266 |
messages.append({
|
| 267 |
"role": "assistant",
|
| 268 |
-
"content": f"Memories: {memories}",
|
| 269 |
"metadata": {"title": "Memories"}
|
| 270 |
})
|
| 271 |
yield messages
|
|
@@ -324,7 +326,6 @@ class GeminiManager:
|
|
| 324 |
|
| 325 |
# Check if any text was received
|
| 326 |
if len(full_text.strip()) == 0 and len(function_calls) == 0:
|
| 327 |
-
print(response_stream)
|
| 328 |
messages.append({
|
| 329 |
"role": "assistant",
|
| 330 |
"content": "No response from the model.",
|
|
|
|
| 126 |
"message": f"Tool `{function_call.name}` failed to run.",
|
| 127 |
"output": str(e),
|
| 128 |
}
|
| 129 |
+
pretty_json = json.dumps(toolResponse, indent=4)
|
| 130 |
+
logger.debug(f"Tool Response: {pretty_json}")
|
| 131 |
+
thinking += f"Tool responded with \n```\n{pretty_json}\n```\n"
|
| 132 |
yield {
|
| 133 |
"role": "assistant",
|
| 134 |
"content": thinking,
|
|
|
|
| 227 |
return formatted_history
|
| 228 |
|
| 229 |
def get_k_memories(self, query, k=5, threshold=0.0):
|
| 230 |
+
raw_memories = MemoryManager().get_memories()
|
| 231 |
+
memories = []
|
| 232 |
+
for i in range(len(raw_memories)):
|
| 233 |
+
memories.append(raw_memories[i]['memory'])
|
| 234 |
if len(memories) == 0:
|
| 235 |
return []
|
| 236 |
top_k = min(k, len(memories))
|
|
|
|
| 252 |
results = []
|
| 253 |
for score, idx in zip(scores, indices):
|
| 254 |
if score >= threshold:
|
| 255 |
+
results.append(raw_memories[idx.item()])
|
| 256 |
return results
|
| 257 |
|
| 258 |
def run(self, messages):
|
|
|
|
| 267 |
})
|
| 268 |
messages.append({
|
| 269 |
"role": "assistant",
|
| 270 |
+
"content": f"Memories: \n```\n{json.dumps(memories, indent=4)}\n```\n",
|
| 271 |
"metadata": {"title": "Memories"}
|
| 272 |
})
|
| 273 |
yield messages
|
|
|
|
| 326 |
|
| 327 |
# Check if any text was received
|
| 328 |
if len(full_text.strip()) == 0 and len(function_calls) == 0:
|
|
|
|
| 329 |
messages.append({
|
| 330 |
"role": "assistant",
|
| 331 |
"content": "No response from the model.",
|
src/tools/default_tools/tool_creator.py
CHANGED
|
@@ -41,14 +41,25 @@ class ToolCreator():
|
|
| 41 |
print(f"Tool Content: {content}")
|
| 42 |
# Create the tool file
|
| 43 |
tool_file_path = f"src/tools/user_tools/{name}.py"
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
"
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
}
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
print(f"Tool Content: {content}")
|
| 42 |
# Create the tool file
|
| 43 |
tool_file_path = f"src/tools/user_tools/{name}.py"
|
| 44 |
+
try:
|
| 45 |
+
with open(tool_file_path, "w") as tool_file:
|
| 46 |
+
tool_file.write(content)
|
| 47 |
+
print(f"Tool file created at {tool_file_path}")
|
| 48 |
+
return {
|
| 49 |
+
"status": "success",
|
| 50 |
+
"message": "Tool created successfully",
|
| 51 |
+
"output": {
|
| 52 |
+
"tool_file_path": tool_file_path,
|
| 53 |
+
"tool_name": name,
|
| 54 |
+
}
|
| 55 |
}
|
| 56 |
+
except Exception as e:
|
| 57 |
+
print(f"Error creating tool: {e}")
|
| 58 |
+
return {
|
| 59 |
+
"status": "error",
|
| 60 |
+
"message": f"Error creating tool: {str(e)}",
|
| 61 |
+
"output": {
|
| 62 |
+
"tool_file_path": tool_file_path,
|
| 63 |
+
"tool_name": name,
|
| 64 |
+
}
|
| 65 |
+
}
|