Skip to content

Commit

Permalink
Refactor: Update chatbot chain.py to improve event data retrieval and…
Browse files Browse the repository at this point in the history
… response formatting
  • Loading branch information
luthfiarifin committed Oct 6, 2024
1 parent 0bfa983 commit a313316
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/chatbot/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@


from app.chatbot.model.response_model import AgentState, ToolResponse
from app.chatbot.tools.get_my_tickets import get_my_tickets_tool
from app.chatbot.tools.get_my_tickets import get_my_tickets_tool, get_tickets_by_ids
from app.chatbot.tools.get_tikeetron import get_tikeetron_tool
from app.chatbot.tools.get_current_events import get_current_event_tool
from app.chatbot.tools.get_current_events import (
get_current_event_tool,
get_events_by_ids,
)
from app.events.crud import get_event_datas

load_dotenv()
Expand Down Expand Up @@ -49,7 +52,7 @@ def respond(state: AgentState):
[HumanMessage(content=state["messages"][-2].content)]
)

if response.events and response.events[0].id:
if response.events and response.events[0].eventId:
return {
"events": response.events,
"tickets": [],
Expand Down Expand Up @@ -122,7 +125,7 @@ def ask_agent(messages, user_address):
(
"system",
"""You are Tikeetron Bot. Follow these rules:
1. For event-related questions (e.g., "What events are happening?"), call `get_events`, retrieve the event ID, name, and category, and return the event name along with a brief description.
1. For event-related questions (e.g., "What events are happening?"), call `get_events`, retrieve the eventId, name, and category, and return the event name along with a brief description.
2. For ticket/transaction inquiries, call `get_my_tickets`.
3. For general queries (NFTs or Tikeetron info), call `get_to_know_tikeetron`.
Expand All @@ -139,7 +142,7 @@ def ask_agent(messages, user_address):
),
],
},
debug=True,
# debug=True,
)

print(response)
Expand All @@ -148,8 +151,13 @@ def ask_agent(messages, user_address):
if message != None:
return {
"message": message.content,
"events": get_events(response["events"]),
"tickets": response["tickets"],
"events": get_events_by_ids(
[event.eventId for event in response["events"]]
),
"tickets": [
get_tickets_by_ids([ticket.ticketId], user_address)
for ticket in response["tickets"]
],
}
else:
return {
Expand Down

0 comments on commit a313316

Please sign in to comment.