Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
from langgraph.graph import StateGraph, START, MessagesState
|
| 3 |
from langgraph.prebuilt import tools_condition, ToolNode
|
|
@@ -5,6 +9,9 @@ from langchain_groq import ChatGroq
|
|
| 5 |
from langchain_core.messages import HumanMessage, SystemMessage
|
| 6 |
import math
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
# -------------------------
|
| 9 |
# Tools
|
| 10 |
# -------------------------
|
|
@@ -82,7 +89,7 @@ sys_msg = SystemMessage(content=system_prompt)
|
|
| 82 |
# Build LangGraph Agent
|
| 83 |
# -------------------------
|
| 84 |
def build_deepseek_graph():
|
| 85 |
-
llm = ChatGroq(model="deepseek-
|
| 86 |
|
| 87 |
all_tools = [
|
| 88 |
add, subtract, multiply, divide, modulus,
|
|
@@ -105,14 +112,3 @@ def build_deepseek_graph():
|
|
| 105 |
|
| 106 |
ninu = builder.compile()
|
| 107 |
return ninu
|
| 108 |
-
|
| 109 |
-
# -------------------------
|
| 110 |
-
# Example Run
|
| 111 |
-
# -------------------------
|
| 112 |
-
if __name__ == "__main__":
|
| 113 |
-
ninu = build_deepseek_graph()
|
| 114 |
-
user_question = "ترجم لي الجملة: Artificial intelligence is transforming education."
|
| 115 |
-
messages = [sys_msg, HumanMessage(content=user_question)]
|
| 116 |
-
result = ninu.invoke({"messages": messages})
|
| 117 |
-
for msg in result["messages"]:
|
| 118 |
-
print("\n", msg.content)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
load_dotenv()
|
| 4 |
+
|
| 5 |
from langchain_core.tools import tool
|
| 6 |
from langgraph.graph import StateGraph, START, MessagesState
|
| 7 |
from langgraph.prebuilt import tools_condition, ToolNode
|
|
|
|
| 9 |
from langchain_core.messages import HumanMessage, SystemMessage
|
| 10 |
import math
|
| 11 |
|
| 12 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 13 |
+
serpapi_api_key = os.getenv("SERPAPI_API_KEY")
|
| 14 |
+
|
| 15 |
# -------------------------
|
| 16 |
# Tools
|
| 17 |
# -------------------------
|
|
|
|
| 89 |
# Build LangGraph Agent
|
| 90 |
# -------------------------
|
| 91 |
def build_deepseek_graph():
|
| 92 |
+
llm = ChatGroq(model="deepseek-r1-distill-llama-70b", groq_api_key=groq_api_key)
|
| 93 |
|
| 94 |
all_tools = [
|
| 95 |
add, subtract, multiply, divide, modulus,
|
|
|
|
| 112 |
|
| 113 |
ninu = builder.compile()
|
| 114 |
return ninu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|