Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,71 +5,11 @@ from langchain_core.runnables import RunnableConfig
|
|
5 |
from langchain_teddynote.messages import random_uuid
|
6 |
from langchain_core.messages import BaseMessage, HumanMessage
|
7 |
from pprint import pprint
|
|
|
8 |
|
9 |
def format_namespace(namespace):
|
10 |
return namespace[-1].split(":")[0] if len(namespace) > 0 else "root graph"
|
11 |
|
12 |
-
from langchain_openai import ChatOpenAI
|
13 |
-
from langgraph.checkpoint.memory import MemorySaver
|
14 |
-
from langgraph_supervisor import create_supervisor
|
15 |
-
from langgraph.prebuilt import create_react_agent
|
16 |
-
from langgraph.checkpoint.memory import MemorySaver, InMemorySaver
|
17 |
-
from langgraph.store.memory import InMemoryStore
|
18 |
-
|
19 |
-
checkpointer = InMemorySaver()
|
20 |
-
store = InMemoryStore()
|
21 |
-
|
22 |
-
model = ChatOpenAI(model="gpt-4o")
|
23 |
-
|
24 |
-
# Create specialized agents
|
25 |
-
|
26 |
-
def add(a: float, b: float) -> float:
|
27 |
-
"""Add two numbers."""
|
28 |
-
return a + b
|
29 |
-
|
30 |
-
def multiply(a: float, b: float) -> float:
|
31 |
-
"""Multiply two numbers."""
|
32 |
-
return a * b
|
33 |
-
|
34 |
-
def web_search(query: str) -> str:
|
35 |
-
"""Search the web for information."""
|
36 |
-
return (
|
37 |
-
"Here are the headcounts for each of the FAANG companies in 2024:\n"
|
38 |
-
"1. **Facebook (Meta)**: 67,317 employees.\n"
|
39 |
-
"2. **Apple**: 164,000 employees.\n"
|
40 |
-
"3. **Amazon**: 1,551,000 employees.\n"
|
41 |
-
"4. **Netflix**: 14,000 employees.\n"
|
42 |
-
"5. **Google (Alphabet)**: 181,269 employees."
|
43 |
-
)
|
44 |
-
|
45 |
-
math_agent = create_react_agent(
|
46 |
-
model=model,
|
47 |
-
tools=[add, multiply],
|
48 |
-
name="math_expert",
|
49 |
-
prompt="You are a math expert. Always use one tool at a time."
|
50 |
-
)
|
51 |
-
|
52 |
-
research_agent = create_react_agent(
|
53 |
-
model=model,
|
54 |
-
tools=[web_search],
|
55 |
-
name="research_expert",
|
56 |
-
prompt="You are a world class researcher with access to web search. Do not do any math."
|
57 |
-
)
|
58 |
-
|
59 |
-
# Create supervisor workflow
|
60 |
-
workflow = create_supervisor(
|
61 |
-
[research_agent, math_agent],
|
62 |
-
model=model,
|
63 |
-
prompt=(
|
64 |
-
"You are a team supervisor managing a research expert and a math expert. "
|
65 |
-
"For current events, use research_agent. "
|
66 |
-
"For math problems, use math_agent."
|
67 |
-
)
|
68 |
-
)
|
69 |
-
|
70 |
-
# Compile and run
|
71 |
-
app = workflow.compile()
|
72 |
-
|
73 |
def generate_response(message, history):
|
74 |
inputs = {
|
75 |
"messages": [HumanMessage(content=message)],
|
|
|
5 |
from langchain_teddynote.messages import random_uuid
|
6 |
from langchain_core.messages import BaseMessage, HumanMessage
|
7 |
from pprint import pprint
|
8 |
+
from graph import app
|
9 |
|
10 |
def format_namespace(namespace):
|
11 |
return namespace[-1].split(":")[0] if len(namespace) > 0 else "root graph"
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def generate_response(message, history):
|
14 |
inputs = {
|
15 |
"messages": [HumanMessage(content=message)],
|