Spaces:
Sleeping
Sleeping
chore: update app examples
Browse files
app.py
CHANGED
@@ -8,8 +8,13 @@ from langchain.schema import AIMessage
|
|
8 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
9 |
from gradio import ChatMessage
|
10 |
import textwrap
|
11 |
-
from tools import GetDriverPerformance, GetEventPerformance,
|
|
|
|
|
12 |
from db.connection import db
|
|
|
|
|
|
|
13 |
load_dotenv()
|
14 |
os.environ['LANGCHAIN_PROJECT'] = 'gradio-test'
|
15 |
|
@@ -43,7 +48,8 @@ agent_prompt = open("agent_prompt.txt", "r")
|
|
43 |
system_prompt = textwrap.dedent(agent_prompt.read())
|
44 |
agent_prompt.close()
|
45 |
state_modifier = SystemMessage(content=system_prompt)
|
46 |
-
agent = create_react_agent(
|
|
|
47 |
|
48 |
# * Interact with agent
|
49 |
|
@@ -57,6 +63,8 @@ async def interact_with_agent(message, history):
|
|
57 |
messages = chunk["tools"]["messages"]
|
58 |
for msg in messages:
|
59 |
if isinstance(msg, ToolMessage):
|
|
|
|
|
60 |
history.append(ChatMessage(
|
61 |
role="assistant", content=msg.content, metadata={"title": f"🛠️ Used tool {msg.name}"}))
|
62 |
yield history
|
@@ -66,6 +74,8 @@ async def interact_with_agent(message, history):
|
|
66 |
for msg in messages:
|
67 |
if isinstance(msg, AIMessage):
|
68 |
if msg.content:
|
|
|
|
|
69 |
history.append(ChatMessage(
|
70 |
role="assistant", content=msg.content, metadata={"title": "💬 Assistant"}))
|
71 |
yield history
|
@@ -90,8 +100,10 @@ with gr.Blocks(theme=theme, fill_height=True) as demo:
|
|
90 |
input.submit(interact_with_agent, [
|
91 |
input, chatbot], [chatbot])
|
92 |
examples = gr.Examples(examples=[
|
93 |
-
"
|
94 |
-
"
|
|
|
|
|
95 |
], inputs=input)
|
96 |
btn = gr.Button("Submit", variant="primary")
|
97 |
btn.click(fn=interact_with_agent, inputs=[input, chatbot], outputs=chatbot)
|
|
|
8 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
9 |
from gradio import ChatMessage
|
10 |
import textwrap
|
11 |
+
from tools import (GetDriverPerformance, GetEventPerformance,
|
12 |
+
GetTelemetry, GetTyrePerformance, GetWeatherImpact)
|
13 |
+
from rich.console import Console
|
14 |
from db.connection import db
|
15 |
+
|
16 |
+
console = Console(style="chartreuse1 on grey7")
|
17 |
+
|
18 |
load_dotenv()
|
19 |
os.environ['LANGCHAIN_PROJECT'] = 'gradio-test'
|
20 |
|
|
|
48 |
system_prompt = textwrap.dedent(agent_prompt.read())
|
49 |
agent_prompt.close()
|
50 |
state_modifier = SystemMessage(content=system_prompt)
|
51 |
+
agent = create_react_agent(
|
52 |
+
llm, tools, state_modifier=state_modifier)
|
53 |
|
54 |
# * Interact with agent
|
55 |
|
|
|
63 |
messages = chunk["tools"]["messages"]
|
64 |
for msg in messages:
|
65 |
if isinstance(msg, ToolMessage):
|
66 |
+
console.print(f"\n\n Used tool {msg.name}")
|
67 |
+
console.print(msg.content)
|
68 |
history.append(ChatMessage(
|
69 |
role="assistant", content=msg.content, metadata={"title": f"🛠️ Used tool {msg.name}"}))
|
70 |
yield history
|
|
|
74 |
for msg in messages:
|
75 |
if isinstance(msg, AIMessage):
|
76 |
if msg.content:
|
77 |
+
console.print(f"\n\n💬 Assistant: {msg.content}")
|
78 |
+
console.print("-"*100)
|
79 |
history.append(ChatMessage(
|
80 |
role="assistant", content=msg.content, metadata={"title": "💬 Assistant"}))
|
81 |
yield history
|
|
|
100 |
input.submit(interact_with_agent, [
|
101 |
input, chatbot], [chatbot])
|
102 |
examples = gr.Examples(examples=[
|
103 |
+
"Highlight the telemetry data for Verstappen in the first lap",
|
104 |
+
"Compare sector times between Hamilton and Russell",
|
105 |
+
"Which driver had the best second sector?",
|
106 |
+
"How did track temperature affect lap times throughout qualifying?"
|
107 |
], inputs=input)
|
108 |
btn = gr.Button("Submit", variant="primary")
|
109 |
btn.click(fn=interact_with_agent, inputs=[input, chatbot], outputs=chatbot)
|