Skip to content

Commit

Permalink
chore: update app examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Draichi committed Oct 31, 2024
1 parent 2fe429b commit 51473cd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
from langchain_google_genai import ChatGoogleGenerativeAI
from gradio import ChatMessage
import textwrap
from tools import GetDriverPerformance, GetEventPerformance, GetTelemetry, GetTyrePerformance, GetWeatherImpact
from tools import (GetDriverPerformance, GetEventPerformance,
GetTelemetry, GetTyrePerformance, GetWeatherImpact)
from rich.console import Console
from db.connection import db

console = Console(style="chartreuse1 on grey7")

load_dotenv()
os.environ['LANGCHAIN_PROJECT'] = 'gradio-test'

Expand Down Expand Up @@ -43,7 +48,8 @@
system_prompt = textwrap.dedent(agent_prompt.read())
agent_prompt.close()
state_modifier = SystemMessage(content=system_prompt)
agent = create_react_agent(llm, tools, state_modifier=state_modifier)
agent = create_react_agent(
llm, tools, state_modifier=state_modifier)

# * Interact with agent

Expand All @@ -57,6 +63,8 @@ async def interact_with_agent(message, history):
messages = chunk["tools"]["messages"]
for msg in messages:
if isinstance(msg, ToolMessage):
console.print(f"\n\n Used tool {msg.name}")
console.print(msg.content)
history.append(ChatMessage(
role="assistant", content=msg.content, metadata={"title": f"🛠️ Used tool {msg.name}"}))
yield history
Expand All @@ -66,6 +74,8 @@ async def interact_with_agent(message, history):
for msg in messages:
if isinstance(msg, AIMessage):
if msg.content:
console.print(f"\n\n💬 Assistant: {msg.content}")
console.print("-"*100)
history.append(ChatMessage(
role="assistant", content=msg.content, metadata={"title": "💬 Assistant"}))
yield history
Expand All @@ -90,8 +100,10 @@ async def interact_with_agent(message, history):
input.submit(interact_with_agent, [
input, chatbot], [chatbot])
examples = gr.Examples(examples=[
"How many fastest laps did Verstappen achieve?",
"How many pit stops did Hamilton make?"
"Highlight the telemetry data for Verstappen in the first lap",
"Compare sector times between Hamilton and Russell",
"Which driver had the best second sector?",
"How did track temperature affect lap times throughout qualifying?"
], inputs=input)
btn = gr.Button("Submit", variant="primary")
btn.click(fn=interact_with_agent, inputs=[input, chatbot], outputs=chatbot)
Expand Down

0 comments on commit 51473cd

Please sign in to comment.