Spaces:
Sleeping
Sleeping
Upload 164 files
Browse files- src/apis/controllers/__pycache__/chat_controller.cpython-311.pyc +0 -0
- src/apis/controllers/__pycache__/destination_controller.cpython-311.pyc +0 -0
- src/apis/controllers/__pycache__/location_controller.cpython-311.pyc +0 -0
- src/apis/controllers/chat_controller.py +83 -0
- src/apis/controllers/location_controller.py +6 -0
- src/apis/interfaces/__pycache__/api_interface.cpython-311.pyc +0 -0
- src/apis/interfaces/api_interface.py +3 -3
- src/apis/routes/__pycache__/chat_route.cpython-311.pyc +0 -0
- src/apis/routes/__pycache__/comment_route.cpython-311.pyc +0 -0
- src/apis/routes/__pycache__/location_route.cpython-311.pyc +0 -0
- src/apis/routes/__pycache__/planner_route.cpython-311.pyc +0 -0
- src/apis/routes/chat_route.py +10 -0
- src/apis/routes/location_route.py +14 -1
- src/langgraph/config/__pycache__/agent.cpython-311.pyc +0 -0
- src/langgraph/langchain/__pycache__/prompt.cpython-311.pyc +0 -0
- src/langgraph/multi_agent/chat/__pycache__/chat_flow.cpython-311.pyc +0 -0
- src/langgraph/multi_agent/chat/__pycache__/scheduling_flow.cpython-311.pyc +0 -0
- src/langgraph/multi_agent/chat/chat_flow.py +3 -1
- src/langgraph/multi_agent/chat/scheduling_flow.py +6 -1
- src/langgraph/tools/__pycache__/destination_tools.cpython-311.pyc +0 -0
- src/langgraph/tools/__pycache__/hotel_tools.cpython-311.pyc +0 -0
- src/langgraph/tools/__pycache__/plan_itinerary.cpython-311.pyc +0 -0
- src/langgraph/tools/__pycache__/scheduling_tools.cpython-311.pyc +0 -0
- src/langgraph/tools/__pycache__/search_tools.cpython-311.pyc +0 -0
- src/langgraph/tools/destination_tools.py +13 -14
- src/langgraph/tools/hotel_tools.py +15 -5
- src/langgraph/tools/plan_itinerary.py +0 -2
- src/langgraph/tools/scheduling_tools.py +14 -1
- src/langgraph/tools/search_tools.py +1 -0
- src/utils/__pycache__/helper.cpython-311.pyc +0 -0
- src/utils/helper.py +5 -1
src/apis/controllers/__pycache__/chat_controller.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/controllers/__pycache__/chat_controller.cpython-311.pyc and b/src/apis/controllers/__pycache__/chat_controller.cpython-311.pyc differ
|
|
|
src/apis/controllers/__pycache__/destination_controller.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/controllers/__pycache__/destination_controller.cpython-311.pyc and b/src/apis/controllers/__pycache__/destination_controller.cpython-311.pyc differ
|
|
|
src/apis/controllers/__pycache__/location_controller.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/controllers/__pycache__/location_controller.cpython-311.pyc and b/src/apis/controllers/__pycache__/location_controller.cpython-311.pyc differ
|
|
|
src/apis/controllers/chat_controller.py
CHANGED
|
@@ -153,6 +153,89 @@ async def chat_streaming_function(user, data: Chat, background_tasks: Background
|
|
| 153 |
)
|
| 154 |
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
async def chat_function(user, data: Chat, background_tasks: BackgroundTasks):
|
| 157 |
message = data.message
|
| 158 |
history = data.history
|
|
|
|
| 153 |
)
|
| 154 |
|
| 155 |
|
| 156 |
+
async def chat_streaming_no_login_function(
|
| 157 |
+
data: Chat, background_tasks: BackgroundTasks
|
| 158 |
+
):
|
| 159 |
+
human_message = data.message
|
| 160 |
+
history = data.history
|
| 161 |
+
lat = data.lat
|
| 162 |
+
long = data.long
|
| 163 |
+
language = data.language
|
| 164 |
+
logger.info(f"Language: {language}")
|
| 165 |
+
process_history = post_process_history(history) if history is not None else None
|
| 166 |
+
config = {
|
| 167 |
+
"configurable": {
|
| 168 |
+
"user_id": None,
|
| 169 |
+
"user_email": None,
|
| 170 |
+
"contact_number": None,
|
| 171 |
+
"session_id": None,
|
| 172 |
+
"lat": lat,
|
| 173 |
+
"long": long,
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
initial_input = {
|
| 177 |
+
"messages": [("user", human_message)],
|
| 178 |
+
"messages_history": process_history,
|
| 179 |
+
"entry_message": None,
|
| 180 |
+
"manual_save": False,
|
| 181 |
+
"intent": data.intent,
|
| 182 |
+
"language": language,
|
| 183 |
+
"tool_name": None,
|
| 184 |
+
"ever_leave_skill": False,
|
| 185 |
+
}
|
| 186 |
+
last_output_state = None
|
| 187 |
+
temp = ""
|
| 188 |
+
async for event in workflow.astream(
|
| 189 |
+
input=initial_input,
|
| 190 |
+
config=config,
|
| 191 |
+
stream_mode=["messages", "values"],
|
| 192 |
+
):
|
| 193 |
+
event_type, event_message = event
|
| 194 |
+
if event_type == "messages":
|
| 195 |
+
message, metadata = event_message
|
| 196 |
+
if (
|
| 197 |
+
isinstance(message, AIMessageChunk)
|
| 198 |
+
and message.tool_calls
|
| 199 |
+
and message.tool_call_chunks[0]["name"] != "ClassifyUserIntent"
|
| 200 |
+
):
|
| 201 |
+
tool_name = message.tool_call_chunks[0]["name"]
|
| 202 |
+
message_yield = json.dumps(
|
| 203 |
+
{"type": "tool_call", "content": tool_name}, ensure_ascii=False
|
| 204 |
+
)
|
| 205 |
+
print(message_yield)
|
| 206 |
+
yield message_yield + "\n"
|
| 207 |
+
if metadata["langgraph_node"] in [
|
| 208 |
+
"primary_assistant",
|
| 209 |
+
"scheduling_agent",
|
| 210 |
+
"book_hotel_agent",
|
| 211 |
+
]:
|
| 212 |
+
|
| 213 |
+
if message.content:
|
| 214 |
+
temp += message.content
|
| 215 |
+
message_yield = json.dumps(
|
| 216 |
+
{"type": "message", "content": temp}, ensure_ascii=False
|
| 217 |
+
)
|
| 218 |
+
print(message_yield)
|
| 219 |
+
yield message_yield + "\n"
|
| 220 |
+
if event_type == "values":
|
| 221 |
+
last_output_state = event_message
|
| 222 |
+
|
| 223 |
+
final_ai_output = last_output_state["messages"][-1].content
|
| 224 |
+
final_intent = last_output_state["intent"]
|
| 225 |
+
tool_name_important = last_output_state["tool_name"]
|
| 226 |
+
|
| 227 |
+
final_response = json.dumps(
|
| 228 |
+
{
|
| 229 |
+
"type": "final",
|
| 230 |
+
"content": final_ai_output,
|
| 231 |
+
"intent": final_intent,
|
| 232 |
+
"tool_name": tool_name_important,
|
| 233 |
+
},
|
| 234 |
+
ensure_ascii=False,
|
| 235 |
+
)
|
| 236 |
+
yield final_response
|
| 237 |
+
|
| 238 |
+
|
| 239 |
async def chat_function(user, data: Chat, background_tasks: BackgroundTasks):
|
| 240 |
message = data.message
|
| 241 |
history = data.history
|
src/apis/controllers/location_controller.py
CHANGED
|
@@ -81,6 +81,12 @@ def get_weather(lat, long):
|
|
| 81 |
)
|
| 82 |
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
def get_lat_long_location(location_name):
|
| 85 |
"""
|
| 86 |
Retrieve the latitude and longitude for a given location name using Geoapify's Geocoding API.
|
|
|
|
| 81 |
)
|
| 82 |
|
| 83 |
|
| 84 |
+
def get_weather_api(destination: str):
|
| 85 |
+
lat, long = get_lat_long_location(destination)
|
| 86 |
+
print("lat", lat, "long", long)
|
| 87 |
+
return json.loads(get_weather(lat, long).body)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
def get_lat_long_location(location_name):
|
| 91 |
"""
|
| 92 |
Retrieve the latitude and longitude for a given location name using Geoapify's Geocoding API.
|
src/apis/interfaces/__pycache__/api_interface.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/interfaces/__pycache__/api_interface.cpython-311.pyc and b/src/apis/interfaces/__pycache__/api_interface.cpython-311.pyc differ
|
|
|
src/apis/interfaces/api_interface.py
CHANGED
|
@@ -6,10 +6,10 @@ from typing import List, Union
|
|
| 6 |
|
| 7 |
class Chat(BaseModel):
|
| 8 |
message: str = Field(..., title="Message from user")
|
| 9 |
-
session_id: Optional[str] = Field(
|
| 10 |
history: Optional[list] = Field(None, title="Chat history")
|
| 11 |
-
lat: Optional[float] = Field(
|
| 12 |
-
long: Optional[float] = Field(
|
| 13 |
intent: Optional[str] = Field(None, title="Intent")
|
| 14 |
language: Optional[str] = Field("en", title="Language")
|
| 15 |
|
|
|
|
| 6 |
|
| 7 |
class Chat(BaseModel):
|
| 8 |
message: str = Field(..., title="Message from user")
|
| 9 |
+
session_id: Optional[str] = Field(None, title="Session Id")
|
| 10 |
history: Optional[list] = Field(None, title="Chat history")
|
| 11 |
+
lat: Optional[float] = Field(None, title="Latitude")
|
| 12 |
+
long: Optional[float] = Field(None, title="Longitude")
|
| 13 |
intent: Optional[str] = Field(None, title="Intent")
|
| 14 |
language: Optional[str] = Field("en", title="Language")
|
| 15 |
|
src/apis/routes/__pycache__/chat_route.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/routes/__pycache__/chat_route.cpython-311.pyc and b/src/apis/routes/__pycache__/chat_route.cpython-311.pyc differ
|
|
|
src/apis/routes/__pycache__/comment_route.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/routes/__pycache__/comment_route.cpython-311.pyc and b/src/apis/routes/__pycache__/comment_route.cpython-311.pyc differ
|
|
|
src/apis/routes/__pycache__/location_route.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/routes/__pycache__/location_route.cpython-311.pyc and b/src/apis/routes/__pycache__/location_route.cpython-311.pyc differ
|
|
|
src/apis/routes/__pycache__/planner_route.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/routes/__pycache__/planner_route.cpython-311.pyc and b/src/apis/routes/__pycache__/planner_route.cpython-311.pyc differ
|
|
|
src/apis/routes/chat_route.py
CHANGED
|
@@ -10,6 +10,7 @@ from src.apis.controllers.chat_controller import (
|
|
| 10 |
get_history_function,
|
| 11 |
list_chat_history_function,
|
| 12 |
delete_chat_history_function,
|
|
|
|
| 13 |
)
|
| 14 |
from src.utils.logger import logger
|
| 15 |
from src.apis.models.user_models import User
|
|
@@ -41,6 +42,15 @@ async def chat_streaming_router(
|
|
| 41 |
media_type="text/plain",
|
| 42 |
)
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
@router.post("/get_chat_history", status_code=status.HTTP_200_OK)
|
| 46 |
async def get_chat_history(user: user_dependency, background_tasks: BackgroundTasks):
|
|
|
|
| 10 |
get_history_function,
|
| 11 |
list_chat_history_function,
|
| 12 |
delete_chat_history_function,
|
| 13 |
+
chat_streaming_no_login_function,
|
| 14 |
)
|
| 15 |
from src.utils.logger import logger
|
| 16 |
from src.apis.models.user_models import User
|
|
|
|
| 42 |
media_type="text/plain",
|
| 43 |
)
|
| 44 |
|
| 45 |
+
@router.post("/chat_streaming_guest", status_code=status.HTTP_200_OK)
|
| 46 |
+
async def chat_streaming_guest_router(
|
| 47 |
+
data: Chat, background_tasks: BackgroundTasks
|
| 48 |
+
):
|
| 49 |
+
return StreamingResponse(
|
| 50 |
+
chat_streaming_no_login_function(data, background_tasks),
|
| 51 |
+
media_type="text/plain",
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
|
| 55 |
@router.post("/get_chat_history", status_code=status.HTTP_200_OK)
|
| 56 |
async def get_chat_history(user: user_dependency, background_tasks: BackgroundTasks):
|
src/apis/routes/location_route.py
CHANGED
|
@@ -5,8 +5,10 @@ from src.apis.controllers.location_controller import (
|
|
| 5 |
get_location_details,
|
| 6 |
get_nearby_places,
|
| 7 |
get_places,
|
|
|
|
|
|
|
| 8 |
)
|
| 9 |
-
from fastapi import APIRouter, status, Depends
|
| 10 |
from typing import Annotated
|
| 11 |
from fastapi.responses import JSONResponse
|
| 12 |
|
|
@@ -33,3 +35,14 @@ def get_nearby(body: Location, user: user_dependency):
|
|
| 33 |
@router.post("/places", status_code=status.HTTP_200_OK)
|
| 34 |
def get_near_places(body: Location):
|
| 35 |
return get_places(body.lat, body.long, body.radius, body.categories)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
get_location_details,
|
| 6 |
get_nearby_places,
|
| 7 |
get_places,
|
| 8 |
+
get_weather,
|
| 9 |
+
get_weather_api,
|
| 10 |
)
|
| 11 |
+
from fastapi import APIRouter, status, Depends, Query
|
| 12 |
from typing import Annotated
|
| 13 |
from fastapi.responses import JSONResponse
|
| 14 |
|
|
|
|
| 35 |
@router.post("/places", status_code=status.HTTP_200_OK)
|
| 36 |
def get_near_places(body: Location):
|
| 37 |
return get_places(body.lat, body.long, body.radius, body.categories)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@router.post("/weather", status_code=status.HTTP_200_OK)
|
| 41 |
+
def get_weather_with_geo(body: Location):
|
| 42 |
+
return get_weather(body.lat, body.long)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@router.get("/weather_text", status_code=status.HTTP_200_OK)
|
| 46 |
+
def get_weather_text(destination: str = Query(..., min_length=3)):
|
| 47 |
+
print("destination", destination)
|
| 48 |
+
return get_weather_api(destination)
|
src/langgraph/config/__pycache__/agent.cpython-311.pyc
CHANGED
|
Binary files a/src/langgraph/config/__pycache__/agent.cpython-311.pyc and b/src/langgraph/config/__pycache__/agent.cpython-311.pyc differ
|
|
|
src/langgraph/langchain/__pycache__/prompt.cpython-311.pyc
CHANGED
|
Binary files a/src/langgraph/langchain/__pycache__/prompt.cpython-311.pyc and b/src/langgraph/langchain/__pycache__/prompt.cpython-311.pyc differ
|
|
|
src/langgraph/multi_agent/chat/__pycache__/chat_flow.cpython-311.pyc
CHANGED
|
Binary files a/src/langgraph/multi_agent/chat/__pycache__/chat_flow.cpython-311.pyc and b/src/langgraph/multi_agent/chat/__pycache__/chat_flow.cpython-311.pyc differ
|
|
|
src/langgraph/multi_agent/chat/__pycache__/scheduling_flow.cpython-311.pyc
CHANGED
|
Binary files a/src/langgraph/multi_agent/chat/__pycache__/scheduling_flow.cpython-311.pyc and b/src/langgraph/multi_agent/chat/__pycache__/scheduling_flow.cpython-311.pyc differ
|
|
|
src/langgraph/multi_agent/chat/chat_flow.py
CHANGED
|
@@ -16,12 +16,13 @@ from src.langgraph.utils_function.function_graph import (
|
|
| 16 |
get_history,
|
| 17 |
save_history,
|
| 18 |
)
|
| 19 |
-
from src.langgraph.tools.destination_tools import destination_suggestion
|
| 20 |
from src.utils.logger import logger
|
| 21 |
|
| 22 |
primary_assistant_tools = [
|
| 23 |
TavilySearchResults(max_results=2),
|
| 24 |
destination_suggestion,
|
|
|
|
| 25 |
]
|
| 26 |
|
| 27 |
assistant_runnable = primary_assistant_prompt | llm.bind_tools(
|
|
@@ -60,6 +61,7 @@ class ChatBot:
|
|
| 60 |
self.primary_assistant_tools = [
|
| 61 |
TavilySearchResults(max_results=2),
|
| 62 |
destination_suggestion,
|
|
|
|
| 63 |
]
|
| 64 |
self.assistant_runnable = assistant_runnable
|
| 65 |
|
|
|
|
| 16 |
get_history,
|
| 17 |
save_history,
|
| 18 |
)
|
| 19 |
+
from src.langgraph.tools.destination_tools import destination_suggestion, get_weather
|
| 20 |
from src.utils.logger import logger
|
| 21 |
|
| 22 |
primary_assistant_tools = [
|
| 23 |
TavilySearchResults(max_results=2),
|
| 24 |
destination_suggestion,
|
| 25 |
+
get_weather,
|
| 26 |
]
|
| 27 |
|
| 28 |
assistant_runnable = primary_assistant_prompt | llm.bind_tools(
|
|
|
|
| 61 |
self.primary_assistant_tools = [
|
| 62 |
TavilySearchResults(max_results=2),
|
| 63 |
destination_suggestion,
|
| 64 |
+
get_weather,
|
| 65 |
]
|
| 66 |
self.assistant_runnable = assistant_runnable
|
| 67 |
|
src/langgraph/multi_agent/chat/scheduling_flow.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
|
|
| 1 |
from langgraph.prebuilt import tools_condition
|
| 2 |
from langgraph.graph import END, StateGraph
|
|
|
|
| 3 |
from src.langgraph.tools.scheduling_tools import (
|
| 4 |
create_a_activity,
|
| 5 |
search_activities,
|
|
@@ -21,6 +23,7 @@ from src.langgraph.state import State
|
|
| 21 |
from src.utils.logger import logger
|
| 22 |
from src.langgraph.tools.plan_itinerary import plan_itinerary
|
| 23 |
|
|
|
|
| 24 |
class SchedulingAgent:
|
| 25 |
def __init__(self, builder: StateGraph):
|
| 26 |
self.builder = builder
|
|
@@ -45,7 +48,9 @@ class SchedulingAgent:
|
|
| 45 |
and "Do you want to run the following tool(s)?"
|
| 46 |
in state["messages_history"][-1].content
|
| 47 |
):
|
| 48 |
-
if state["messages"][-1].tool_calls
|
|
|
|
|
|
|
| 49 |
logger.info("Sensitive tools")
|
| 50 |
return "scheduling_sensitive_tools"
|
| 51 |
logger.info("Safe tools")
|
|
|
|
| 1 |
+
from langchain_core.runnables import RunnableConfig
|
| 2 |
from langgraph.prebuilt import tools_condition
|
| 3 |
from langgraph.graph import END, StateGraph
|
| 4 |
+
from langchain_core.messages import HumanMessage
|
| 5 |
from src.langgraph.tools.scheduling_tools import (
|
| 6 |
create_a_activity,
|
| 7 |
search_activities,
|
|
|
|
| 23 |
from src.utils.logger import logger
|
| 24 |
from src.langgraph.tools.plan_itinerary import plan_itinerary
|
| 25 |
|
| 26 |
+
|
| 27 |
class SchedulingAgent:
|
| 28 |
def __init__(self, builder: StateGraph):
|
| 29 |
self.builder = builder
|
|
|
|
| 48 |
and "Do you want to run the following tool(s)?"
|
| 49 |
in state["messages_history"][-1].content
|
| 50 |
):
|
| 51 |
+
if state["messages"][-1].tool_calls and state["messages"][-1].tool_calls[0][
|
| 52 |
+
"name"
|
| 53 |
+
] in [r.name for r in self.scheduling_sensitive_tools]:
|
| 54 |
logger.info("Sensitive tools")
|
| 55 |
return "scheduling_sensitive_tools"
|
| 56 |
logger.info("Safe tools")
|
src/langgraph/tools/__pycache__/destination_tools.cpython-311.pyc
CHANGED
|
Binary files a/src/langgraph/tools/__pycache__/destination_tools.cpython-311.pyc and b/src/langgraph/tools/__pycache__/destination_tools.cpython-311.pyc differ
|
|
|
src/langgraph/tools/__pycache__/hotel_tools.cpython-311.pyc
CHANGED
|
Binary files a/src/langgraph/tools/__pycache__/hotel_tools.cpython-311.pyc and b/src/langgraph/tools/__pycache__/hotel_tools.cpython-311.pyc differ
|
|
|
src/langgraph/tools/__pycache__/plan_itinerary.cpython-311.pyc
CHANGED
|
Binary files a/src/langgraph/tools/__pycache__/plan_itinerary.cpython-311.pyc and b/src/langgraph/tools/__pycache__/plan_itinerary.cpython-311.pyc differ
|
|
|
src/langgraph/tools/__pycache__/scheduling_tools.cpython-311.pyc
CHANGED
|
Binary files a/src/langgraph/tools/__pycache__/scheduling_tools.cpython-311.pyc and b/src/langgraph/tools/__pycache__/scheduling_tools.cpython-311.pyc differ
|
|
|
src/langgraph/tools/__pycache__/search_tools.cpython-311.pyc
CHANGED
|
Binary files a/src/langgraph/tools/__pycache__/search_tools.cpython-311.pyc and b/src/langgraph/tools/__pycache__/search_tools.cpython-311.pyc differ
|
|
|
src/langgraph/tools/destination_tools.py
CHANGED
|
@@ -4,20 +4,7 @@ from src.apis.controllers.destination_controller import (
|
|
| 4 |
)
|
| 5 |
from langchain_core.runnables.config import RunnableConfig
|
| 6 |
from src.utils.logger import logger
|
| 7 |
-
from src.apis.controllers.location_controller import
|
| 8 |
-
get_nearby_places,
|
| 9 |
-
get_lat_long_location,
|
| 10 |
-
get_geometry_nearby_places,
|
| 11 |
-
)
|
| 12 |
-
from src.langgraph.models.model_validator import NearlyDestinationRecommendation
|
| 13 |
-
from src.utils.helper import get_google_map_url
|
| 14 |
-
from src.langgraph.langchain.prompt import (
|
| 15 |
-
routing_recommender_chain,
|
| 16 |
-
characteristic_extractor_chain,
|
| 17 |
-
RoutingRecommender,
|
| 18 |
-
CharacteristicExtractor,
|
| 19 |
-
)
|
| 20 |
-
import json
|
| 21 |
|
| 22 |
|
| 23 |
@tool
|
|
@@ -31,3 +18,15 @@ async def destination_suggestion(query: str, config: RunnableConfig):
|
|
| 31 |
response = await destination_recommendation_func(query, tool_chat=True)
|
| 32 |
logger.info(f"Destination recommendation output: {response}")
|
| 33 |
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
)
|
| 5 |
from langchain_core.runnables.config import RunnableConfig
|
| 6 |
from src.utils.logger import logger
|
| 7 |
+
from src.apis.controllers.location_controller import get_weather_api
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
@tool
|
|
|
|
| 18 |
response = await destination_recommendation_func(query, tool_chat=True)
|
| 19 |
logger.info(f"Destination recommendation output: {response}")
|
| 20 |
return response
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@tool
|
| 24 |
+
def get_weather(destination: str):
|
| 25 |
+
"""
|
| 26 |
+
Get weather information for a specific destination.
|
| 27 |
+
Args:
|
| 28 |
+
destination (str): The destination to get weather information for.
|
| 29 |
+
Returns:
|
| 30 |
+
str: Weather information for the destination.
|
| 31 |
+
"""
|
| 32 |
+
return get_weather_api(destination)
|
src/langgraph/tools/hotel_tools.py
CHANGED
|
@@ -1,17 +1,15 @@
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
from langchain_core.runnables.config import RunnableConfig
|
| 3 |
from datetime import datetime
|
| 4 |
-
from src.apis.controllers.location_controller import get_places
|
| 5 |
-
from src.utils.helper import process_controller_output, format_accommodation_markdown
|
| 6 |
from typing import Optional
|
| 7 |
from src.apis.controllers.hotel_controller import (
|
| 8 |
book_hotel_controller,
|
| 9 |
send_booking_confirmation_email,
|
| 10 |
)
|
| 11 |
-
|
| 12 |
|
| 13 |
@tool
|
| 14 |
-
def search_hotels(option: str, config: RunnableConfig):
|
| 15 |
"""
|
| 16 |
Call this tool directly to search hotels for the user. No need to require asking for city location.
|
| 17 |
Args:
|
|
@@ -62,6 +60,9 @@ async def book_hotel(
|
|
| 62 |
|
| 63 |
configuration = config.get("configurable", {})
|
| 64 |
user_id = configuration.get("user_id", None)
|
|
|
|
|
|
|
|
|
|
| 65 |
user_email = configuration.get("user_email", None)
|
| 66 |
user_contact_number = configuration.get(
|
| 67 |
"contact_number", "Does not have contact number"
|
|
@@ -102,9 +103,13 @@ async def cancel_hotel(
|
|
| 102 |
Returns:
|
| 103 |
str: Confirmation message of the cancellation request.
|
| 104 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
if receiver_email is None:
|
| 106 |
return "The hotel booking email is required"
|
| 107 |
-
|
| 108 |
return f"Email sent to {receiver_email} to cancel booking for room {room_number} with reason: {reason}"
|
| 109 |
|
| 110 |
|
|
@@ -122,6 +127,11 @@ async def update_hotel(
|
|
| 122 |
room_number (Optional[str]): Room number
|
| 123 |
content (Optional[str]): Updated content
|
| 124 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
if receiver_email is None:
|
| 126 |
return "The hotel booking email is required"
|
| 127 |
return f"Email sent to {receiver_email} to update booking for room {room_number} with content: {content}"
|
|
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
from langchain_core.runnables.config import RunnableConfig
|
| 3 |
from datetime import datetime
|
|
|
|
|
|
|
| 4 |
from typing import Optional
|
| 5 |
from src.apis.controllers.hotel_controller import (
|
| 6 |
book_hotel_controller,
|
| 7 |
send_booking_confirmation_email,
|
| 8 |
)
|
| 9 |
+
from src.utils.logger import logger
|
| 10 |
|
| 11 |
@tool
|
| 12 |
+
async def search_hotels(option: str, config: RunnableConfig):
|
| 13 |
"""
|
| 14 |
Call this tool directly to search hotels for the user. No need to require asking for city location.
|
| 15 |
Args:
|
|
|
|
| 60 |
|
| 61 |
configuration = config.get("configurable", {})
|
| 62 |
user_id = configuration.get("user_id", None)
|
| 63 |
+
if not user_id:
|
| 64 |
+
logger.warning(f"User not login")
|
| 65 |
+
return "User not login. Please login"
|
| 66 |
user_email = configuration.get("user_email", None)
|
| 67 |
user_contact_number = configuration.get(
|
| 68 |
"contact_number", "Does not have contact number"
|
|
|
|
| 103 |
Returns:
|
| 104 |
str: Confirmation message of the cancellation request.
|
| 105 |
"""
|
| 106 |
+
configuration = config.get("configurable", {})
|
| 107 |
+
user_id = configuration.get("user_id", None)
|
| 108 |
+
if not user_id:
|
| 109 |
+
logger.warning(f"User not login")
|
| 110 |
+
return "User not login. Please login"
|
| 111 |
if receiver_email is None:
|
| 112 |
return "The hotel booking email is required"
|
|
|
|
| 113 |
return f"Email sent to {receiver_email} to cancel booking for room {room_number} with reason: {reason}"
|
| 114 |
|
| 115 |
|
|
|
|
| 127 |
room_number (Optional[str]): Room number
|
| 128 |
content (Optional[str]): Updated content
|
| 129 |
"""
|
| 130 |
+
configuration = config.get("configurable", {})
|
| 131 |
+
user_id = configuration.get("user_id", None)
|
| 132 |
+
if not user_id:
|
| 133 |
+
logger.warning(f"User not login")
|
| 134 |
+
return "User not login. Please login"
|
| 135 |
if receiver_email is None:
|
| 136 |
return "The hotel booking email is required"
|
| 137 |
return f"Email sent to {receiver_email} to update booking for room {room_number} with content: {content}"
|
src/langgraph/tools/plan_itinerary.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
|
| 3 |
from langchain_core.runnables.config import RunnableConfig
|
| 4 |
-
from src.utils.logger import logger
|
| 5 |
-
from typing import Optional
|
| 6 |
from src.langgraph.multi_agent.planner.planner_flow import planner_app
|
| 7 |
|
| 8 |
@tool
|
|
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
|
| 3 |
from langchain_core.runnables.config import RunnableConfig
|
|
|
|
|
|
|
| 4 |
from src.langgraph.multi_agent.planner.planner_flow import planner_app
|
| 5 |
|
| 6 |
@tool
|
src/langgraph/tools/scheduling_tools.py
CHANGED
|
@@ -9,7 +9,6 @@ from src.apis.controllers.scheduling_controller import (
|
|
| 9 |
search_activities_controller,
|
| 10 |
)
|
| 11 |
|
| 12 |
-
|
| 13 |
@tool
|
| 14 |
async def create_a_activity(
|
| 15 |
description: str,
|
|
@@ -30,6 +29,9 @@ async def create_a_activity(
|
|
| 30 |
# Convert start_time and end_time to the required format
|
| 31 |
configuration = config.get("configurable", {})
|
| 32 |
user_id = configuration.get("user_id", None)
|
|
|
|
|
|
|
|
|
|
| 33 |
response = await create_a_activity_controller(
|
| 34 |
None,
|
| 35 |
activity_category,
|
|
@@ -60,6 +62,9 @@ async def search_activities(
|
|
| 60 |
try:
|
| 61 |
configuration = config.get("configurable", {})
|
| 62 |
user_id = configuration.get("user_id", None)
|
|
|
|
|
|
|
|
|
|
| 63 |
response = await search_activities_controller(start_time, end_time, user_id)
|
| 64 |
return response["message"]
|
| 65 |
except Exception as e:
|
|
@@ -85,6 +90,9 @@ async def update_a_activiy(
|
|
| 85 |
try:
|
| 86 |
configuration = config.get("configurable", {})
|
| 87 |
user_id = configuration.get("user_id", None)
|
|
|
|
|
|
|
|
|
|
| 88 |
response = await update_a_activity_controller(
|
| 89 |
None,
|
| 90 |
activity_category,
|
|
@@ -113,6 +121,9 @@ async def delete_a_activity(
|
|
| 113 |
try:
|
| 114 |
configuration = config.get("configurable", {})
|
| 115 |
user_id = configuration.get("user_id", None)
|
|
|
|
|
|
|
|
|
|
| 116 |
response = await delete_activities_controller(
|
| 117 |
None, start_time, end_time, user_id
|
| 118 |
)
|
|
@@ -120,3 +131,5 @@ async def delete_a_activity(
|
|
| 120 |
except Exception as e:
|
| 121 |
logger.error(f"Error deleting activity: {e}")
|
| 122 |
return f"Error deleting activity {e}"
|
|
|
|
|
|
|
|
|
| 9 |
search_activities_controller,
|
| 10 |
)
|
| 11 |
|
|
|
|
| 12 |
@tool
|
| 13 |
async def create_a_activity(
|
| 14 |
description: str,
|
|
|
|
| 29 |
# Convert start_time and end_time to the required format
|
| 30 |
configuration = config.get("configurable", {})
|
| 31 |
user_id = configuration.get("user_id", None)
|
| 32 |
+
if not user_id:
|
| 33 |
+
logger.warning(f"User not login")
|
| 34 |
+
return "You are not logged in. Please log in to use this feature"
|
| 35 |
response = await create_a_activity_controller(
|
| 36 |
None,
|
| 37 |
activity_category,
|
|
|
|
| 62 |
try:
|
| 63 |
configuration = config.get("configurable", {})
|
| 64 |
user_id = configuration.get("user_id", None)
|
| 65 |
+
if not user_id:
|
| 66 |
+
logger.warning(f"User not login")
|
| 67 |
+
return "You are not logged in. Please log in to use this feature"
|
| 68 |
response = await search_activities_controller(start_time, end_time, user_id)
|
| 69 |
return response["message"]
|
| 70 |
except Exception as e:
|
|
|
|
| 90 |
try:
|
| 91 |
configuration = config.get("configurable", {})
|
| 92 |
user_id = configuration.get("user_id", None)
|
| 93 |
+
if not user_id:
|
| 94 |
+
logger.warning(f"User not login")
|
| 95 |
+
return "You are not logged in. Please log in to use this feature"
|
| 96 |
response = await update_a_activity_controller(
|
| 97 |
None,
|
| 98 |
activity_category,
|
|
|
|
| 121 |
try:
|
| 122 |
configuration = config.get("configurable", {})
|
| 123 |
user_id = configuration.get("user_id", None)
|
| 124 |
+
if not user_id:
|
| 125 |
+
logger.warning(f"User not login")
|
| 126 |
+
return "You are not logged in. Please log in to use this feature"
|
| 127 |
response = await delete_activities_controller(
|
| 128 |
None, start_time, end_time, user_id
|
| 129 |
)
|
|
|
|
| 131 |
except Exception as e:
|
| 132 |
logger.error(f"Error deleting activity: {e}")
|
| 133 |
return f"Error deleting activity {e}"
|
| 134 |
+
logger.error(f"Error deleting activity: {e}")
|
| 135 |
+
return f"Error deleting activity {e}"
|
src/langgraph/tools/search_tools.py
CHANGED
|
@@ -3,6 +3,7 @@ from langchain_community.document_loaders.recursive_url_loader import RecursiveU
|
|
| 3 |
from langchain_core.prompts import PromptTemplate
|
| 4 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 5 |
from langchain_core.tools import tool
|
|
|
|
| 6 |
from src.langgraph.langchain.llm import llm_flash
|
| 7 |
from src.utils.logger import logger
|
| 8 |
from langchain_community.tools import DuckDuckGoSearchResults
|
|
|
|
| 3 |
from langchain_core.prompts import PromptTemplate
|
| 4 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 5 |
from langchain_core.tools import tool
|
| 6 |
+
from src.apis.controllers.location_controller import get_weather_api
|
| 7 |
from src.langgraph.langchain.llm import llm_flash
|
| 8 |
from src.utils.logger import logger
|
| 9 |
from langchain_community.tools import DuckDuckGoSearchResults
|
src/utils/__pycache__/helper.cpython-311.pyc
CHANGED
|
Binary files a/src/utils/__pycache__/helper.cpython-311.pyc and b/src/utils/__pycache__/helper.cpython-311.pyc differ
|
|
|
src/utils/helper.py
CHANGED
|
@@ -56,9 +56,13 @@ def format_weather_data(weather_data):
|
|
| 56 |
lat = weather_data["lat"]
|
| 57 |
lon = weather_data["lon"]
|
| 58 |
location = f"Latitude: {lat}, Longitude: {lon}"
|
|
|
|
| 59 |
formatted_weather = f"In {location}, the current weather is as follows:\n"
|
| 60 |
formatted_weather += (
|
| 61 |
-
f"
|
|
|
|
|
|
|
|
|
|
| 62 |
)
|
| 63 |
formatted_weather += f"Wind speed: {current_weather['wind_speed']} m/s, direction: {current_weather['wind_deg']}°\n"
|
| 64 |
formatted_weather += f"Humidity: {current_weather['humidity']}%\n"
|
|
|
|
| 56 |
lat = weather_data["lat"]
|
| 57 |
lon = weather_data["lon"]
|
| 58 |
location = f"Latitude: {lat}, Longitude: {lon}"
|
| 59 |
+
icon_url = f"http://openweathermap.org/img/wn/{current_weather['weather'][0]['icon']}@2x.png"
|
| 60 |
formatted_weather = f"In {location}, the current weather is as follows:\n"
|
| 61 |
formatted_weather += (
|
| 62 |
+
f" <img src='{icon_url}' width='100' height='100'/>\n"
|
| 63 |
+
)
|
| 64 |
+
formatted_weather += (
|
| 65 |
+
f" Detailed status: {current_weather['weather'][0]['description']}\n"
|
| 66 |
)
|
| 67 |
formatted_weather += f"Wind speed: {current_weather['wind_speed']} m/s, direction: {current_weather['wind_deg']}°\n"
|
| 68 |
formatted_weather += f"Humidity: {current_weather['humidity']}%\n"
|