Spaces:
Sleeping
Sleeping
fix bug
Browse files- Agents/agent.py +4 -1
- Tools/tools.py +10 -0
- app.py +0 -1
Agents/agent.py
CHANGED
|
@@ -17,15 +17,17 @@ load_dotenv()
|
|
| 17 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 18 |
|
| 19 |
if not GROQ_API_KEY:
|
|
|
|
| 20 |
raise ValueError("GROQ_API_KEY environment variable not set")
|
| 21 |
|
| 22 |
langfuse_handler = CallbackHandler()
|
| 23 |
|
| 24 |
with open("Prompts/SystemPrompt.txt","r",encoding="utf-8") as f:
|
| 25 |
systemPrompt = f.read()
|
| 26 |
-
print(systemPrompt)
|
| 27 |
|
| 28 |
sysMsg = SystemMessage(content=systemPrompt)
|
|
|
|
| 29 |
|
| 30 |
'''
|
| 31 |
embeddings = HuggingFaceEmbeddings(
|
|
@@ -67,6 +69,7 @@ def build_graph(provider: str="groq"):
|
|
| 67 |
print(f"Running llm groq")
|
| 68 |
llm=ChatGroq(groq_api_key=GROQ_API_KEY,model="qwen/qwen3-32b",temperature=0)
|
| 69 |
elif provider == "huggingface":
|
|
|
|
| 70 |
llm = ChatHuggingFace(
|
| 71 |
llm=HuggingFaceEndpoint(
|
| 72 |
repo_id="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
|
|
|
|
| 17 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 18 |
|
| 19 |
if not GROQ_API_KEY:
|
| 20 |
+
print("groq api error")
|
| 21 |
raise ValueError("GROQ_API_KEY environment variable not set")
|
| 22 |
|
| 23 |
langfuse_handler = CallbackHandler()
|
| 24 |
|
| 25 |
with open("Prompts/SystemPrompt.txt","r",encoding="utf-8") as f:
|
| 26 |
systemPrompt = f.read()
|
| 27 |
+
print(f"systemPrompt {systemPrompt}")
|
| 28 |
|
| 29 |
sysMsg = SystemMessage(content=systemPrompt)
|
| 30 |
+
print(f"system message {sysMsg}")
|
| 31 |
|
| 32 |
'''
|
| 33 |
embeddings = HuggingFaceEmbeddings(
|
|
|
|
| 69 |
print(f"Running llm groq")
|
| 70 |
llm=ChatGroq(groq_api_key=GROQ_API_KEY,model="qwen/qwen3-32b",temperature=0)
|
| 71 |
elif provider == "huggingface":
|
| 72 |
+
print(f"huggingface")
|
| 73 |
llm = ChatHuggingFace(
|
| 74 |
llm=HuggingFaceEndpoint(
|
| 75 |
repo_id="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
|
Tools/tools.py
CHANGED
|
@@ -13,6 +13,7 @@ def add(a: int, b:int) -> int:
|
|
| 13 |
a: first integer
|
| 14 |
b: second integer
|
| 15 |
"""
|
|
|
|
| 16 |
return a + b
|
| 17 |
|
| 18 |
@tool
|
|
@@ -22,6 +23,7 @@ def substract(a: int, b:int) -> int:
|
|
| 22 |
a : first integer
|
| 23 |
b : second integer
|
| 24 |
"""
|
|
|
|
| 25 |
return a - b
|
| 26 |
|
| 27 |
@tool
|
|
@@ -31,6 +33,8 @@ def multiply(a: int, b: int) -> int:
|
|
| 31 |
a: first integer
|
| 32 |
b: second integer
|
| 33 |
"""
|
|
|
|
|
|
|
| 34 |
return a * b
|
| 35 |
|
| 36 |
@tool
|
|
@@ -40,6 +44,8 @@ def divide(a: int, b: int) -> int:
|
|
| 40 |
a: first integer
|
| 41 |
b: second integer
|
| 42 |
"""
|
|
|
|
|
|
|
| 43 |
return a / b
|
| 44 |
|
| 45 |
@tool
|
|
@@ -49,6 +55,7 @@ def remainder(a: int, b: int) -> int:
|
|
| 49 |
a: first integer
|
| 50 |
b: second integer
|
| 51 |
"""
|
|
|
|
| 52 |
return a % b
|
| 53 |
|
| 54 |
@tool
|
|
@@ -58,6 +65,7 @@ def wikiSearch(searchQuery:str) -> str:
|
|
| 58 |
args:
|
| 59 |
searchQuery: the search query
|
| 60 |
"""
|
|
|
|
| 61 |
search_results = WikipediaLoader(query=searchQuery, load_max_docs=3).load()
|
| 62 |
formatted_results = "\n\n--\n\n".join(
|
| 63 |
[
|
|
@@ -74,6 +82,7 @@ def arxivSearch(searchQuery:str) -> str:
|
|
| 74 |
args:
|
| 75 |
searchQuery: the search query
|
| 76 |
"""
|
|
|
|
| 77 |
search_results = ArxivLoader(query=searchQuery, load_max_docs=3).load()
|
| 78 |
formatted_results = "\n\n--\n\n".join(
|
| 79 |
[
|
|
@@ -90,6 +99,7 @@ def webSearch(searchQuery:str) -> str:
|
|
| 90 |
args:
|
| 91 |
searchQuery: search query
|
| 92 |
"""
|
|
|
|
| 93 |
search_results = TavilySearchResults(max_results=3).invoke(query=searchQuery)
|
| 94 |
formatted_results = "\n\n--\n\n".join(
|
| 95 |
[
|
|
|
|
| 13 |
a: first integer
|
| 14 |
b: second integer
|
| 15 |
"""
|
| 16 |
+
print("add")
|
| 17 |
return a + b
|
| 18 |
|
| 19 |
@tool
|
|
|
|
| 23 |
a : first integer
|
| 24 |
b : second integer
|
| 25 |
"""
|
| 26 |
+
print("substract")
|
| 27 |
return a - b
|
| 28 |
|
| 29 |
@tool
|
|
|
|
| 33 |
a: first integer
|
| 34 |
b: second integer
|
| 35 |
"""
|
| 36 |
+
print ("multiply")
|
| 37 |
+
|
| 38 |
return a * b
|
| 39 |
|
| 40 |
@tool
|
|
|
|
| 44 |
a: first integer
|
| 45 |
b: second integer
|
| 46 |
"""
|
| 47 |
+
print ("divide")
|
| 48 |
+
|
| 49 |
return a / b
|
| 50 |
|
| 51 |
@tool
|
|
|
|
| 55 |
a: first integer
|
| 56 |
b: second integer
|
| 57 |
"""
|
| 58 |
+
print ("remainder")
|
| 59 |
return a % b
|
| 60 |
|
| 61 |
@tool
|
|
|
|
| 65 |
args:
|
| 66 |
searchQuery: the search query
|
| 67 |
"""
|
| 68 |
+
print("wiki search")
|
| 69 |
search_results = WikipediaLoader(query=searchQuery, load_max_docs=3).load()
|
| 70 |
formatted_results = "\n\n--\n\n".join(
|
| 71 |
[
|
|
|
|
| 82 |
args:
|
| 83 |
searchQuery: the search query
|
| 84 |
"""
|
| 85 |
+
print("arxivsearch")
|
| 86 |
search_results = ArxivLoader(query=searchQuery, load_max_docs=3).load()
|
| 87 |
formatted_results = "\n\n--\n\n".join(
|
| 88 |
[
|
|
|
|
| 99 |
args:
|
| 100 |
searchQuery: search query
|
| 101 |
"""
|
| 102 |
+
print("web search")
|
| 103 |
search_results = TavilySearchResults(max_results=3).invoke(query=searchQuery)
|
| 104 |
formatted_results = "\n\n--\n\n".join(
|
| 105 |
[
|
app.py
CHANGED
|
@@ -28,7 +28,6 @@ class BasicAgent:
|
|
| 28 |
#messages = self.graph.invoke({"messages": messages},config={"callbacks": [langfuse_handler]})
|
| 29 |
self.graph.get_graph().draw_mermaid_png()
|
| 30 |
answer = messages['messages'][-1].content
|
| 31 |
-
print(f"second last message : {messages['messages'][-2].content}")
|
| 32 |
print(f"full answer : {answer}")
|
| 33 |
|
| 34 |
return answer[14:]
|
|
|
|
| 28 |
#messages = self.graph.invoke({"messages": messages},config={"callbacks": [langfuse_handler]})
|
| 29 |
self.graph.get_graph().draw_mermaid_png()
|
| 30 |
answer = messages['messages'][-1].content
|
|
|
|
| 31 |
print(f"full answer : {answer}")
|
| 32 |
|
| 33 |
return answer[14:]
|