chroma hf api key?? really?
Browse files
agent.py
CHANGED
|
@@ -24,7 +24,7 @@ from tools import (
|
|
| 24 |
)
|
| 25 |
|
| 26 |
# Import utility functions
|
| 27 |
-
from utils import extract_final_answer, replace_tool_mentions
|
| 28 |
|
| 29 |
|
| 30 |
class BoomBot:
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
# Import utility functions
|
| 27 |
+
from finalassignment.Final_Assignment_Template_CURR.utils import extract_final_answer, replace_tool_mentions
|
| 28 |
|
| 29 |
|
| 30 |
class BoomBot:
|
requirements.txt
CHANGED
|
@@ -20,4 +20,4 @@ python-dotenv
|
|
| 20 |
requests
|
| 21 |
sentence-transformers
|
| 22 |
smolagents
|
| 23 |
-
|
|
|
|
| 20 |
requests
|
| 21 |
sentence-transformers
|
| 22 |
smolagents
|
| 23 |
+
ollama
|
tools.py
CHANGED
|
@@ -8,6 +8,9 @@ import traceback
|
|
| 8 |
from pathlib import Path
|
| 9 |
from typing import Dict, List
|
| 10 |
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
import chromadb
|
| 13 |
import chromadb.utils.embedding_functions as embedding_functions
|
|
|
|
| 8 |
from pathlib import Path
|
| 9 |
from typing import Dict, List
|
| 10 |
from urllib.parse import urlparse
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from ollama import chat
|
| 13 |
+
from PIL import Image
|
| 14 |
|
| 15 |
import chromadb
|
| 16 |
import chromadb.utils.embedding_functions as embedding_functions
|
utils.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def extract_final_answer(output: str) -> str:
|
| 5 |
+
"""
|
| 6 |
+
Extracts the text after 'FINAL ANSWER:' in the model's output.
|
| 7 |
+
Strips whitespace and ensures clean formatting.
|
| 8 |
+
If the answer is a comma-separated list, ensures a space after each comma.
|
| 9 |
+
"""
|
| 10 |
+
output = str(output)
|
| 11 |
+
marker = "FINAL ANSWER:"
|
| 12 |
+
lower_output = output.lower()
|
| 13 |
+
|
| 14 |
+
if marker.lower() in lower_output:
|
| 15 |
+
# Find actual case version in original output (for safety)
|
| 16 |
+
idx = lower_output.rfind(marker.lower())
|
| 17 |
+
raw_answer = output[idx + len(marker) :].strip()
|
| 18 |
+
|
| 19 |
+
# Normalize comma-separated lists: ensure single space after commas
|
| 20 |
+
cleaned_answer = re.sub(r",\s*", ", ", raw_answer)
|
| 21 |
+
return cleaned_answer
|
| 22 |
+
|
| 23 |
+
return output
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def replace_tool_mentions(prompt: str) -> str:
|
| 27 |
+
# Replace tool mentions in backticks: `search` -> `web_search`, `wiki` -> `wikipedia_search`
|
| 28 |
+
prompt = re.sub(r"(?<!\w)`search`(?!\w)", "`web_search`", prompt)
|
| 29 |
+
prompt = re.sub(r"(?<!\w)`wiki`(?!\w)", "`wikipedia_search`", prompt)
|
| 30 |
+
|
| 31 |
+
# Replace function calls: search(...) -> web_search(...), wiki(...) -> wikipedia_search(...)
|
| 32 |
+
# This ensures we only catch function calls (not words like arxiv_search)
|
| 33 |
+
prompt = re.sub(r"(?<!\w)(?<!_)search\(", "web_search(", prompt)
|
| 34 |
+
prompt = re.sub(r"(?<!\w)(?<!_)wiki\(", "wikipedia_search(", prompt)
|
| 35 |
+
|
| 36 |
+
return prompt
|