feat: debuging
Browse files- .DS_Store +0 -0
- app 00-30-34-608/app.py +78 -0
- app.py +0 -13
- utils/.DS_Store +0 -0
- utils/llm_caller.py +2 -1
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
app 00-30-34-608/app.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
|
| 3 |
+
from interface import PlanRequest, PlanResponse, TripPlan , YoutubeLinkRequest, YoutubeLinkResponse, ChatRequest
|
| 4 |
+
from data_importer import DataImporter
|
| 5 |
+
from utils.llm_caller import LLMCaller
|
| 6 |
+
import asyncio
|
| 7 |
+
import time
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
|
| 10 |
+
app = FastAPI()
|
| 11 |
+
data_importer = DataImporter()
|
| 12 |
+
agent = LLMCaller()
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@app.get("/v1")
|
| 16 |
+
def greet_json():
|
| 17 |
+
start_time = time.time()
|
| 18 |
+
health_status = {
|
| 19 |
+
"status": "healthy",
|
| 20 |
+
"timestamp": datetime.utcnow().isoformat(),
|
| 21 |
+
"service": "SealionAI Travel Planning Service",
|
| 22 |
+
"version": "1.0.0",
|
| 23 |
+
"checks": {}
|
| 24 |
+
}
|
| 25 |
+
return health_status
|
| 26 |
+
|
| 27 |
+
@app.post("/v1/generateTripPlan", response_model=PlanResponse)
|
| 28 |
+
def generate_trip_plan(request: PlanRequest):
|
| 29 |
+
try:
|
| 30 |
+
trip_plan = asyncio.run(agent.query_with_rag(request))
|
| 31 |
+
return PlanResponse(tripOverview=trip_plan.tripOverview,
|
| 32 |
+
query_params=request,
|
| 33 |
+
retrieved_data=trip_plan.retrieved_data,
|
| 34 |
+
trip_plan=trip_plan.trip_plan,
|
| 35 |
+
meta={"status": "success", "timestamp": datetime.utcnow().isoformat()})
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"Error in generate_trip_plan: {e}")
|
| 38 |
+
# Return error response
|
| 39 |
+
return PlanResponse(
|
| 40 |
+
tripOverview=f"Error: {str(e)}",
|
| 41 |
+
query_params=request,
|
| 42 |
+
retrieved_data=[],
|
| 43 |
+
trip_plan=TripPlan(overview="Error occurred", total_estimated_cost=0.0, steps=[]),
|
| 44 |
+
meta={"status": "error", "error": str(e)}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
@app.post("/v1/addYoutubeLink", response_model=YoutubeLinkResponse)
|
| 48 |
+
def add_youtube_link(request: YoutubeLinkRequest):
|
| 49 |
+
try:
|
| 50 |
+
data_importer.insert_from_youtube(request.video_id)
|
| 51 |
+
except Exception as e:
|
| 52 |
+
return YoutubeLinkResponse(
|
| 53 |
+
message="Failed to add YouTube link",
|
| 54 |
+
video_url= None
|
| 55 |
+
)
|
| 56 |
+
return YoutubeLinkResponse(
|
| 57 |
+
message="add successfully",
|
| 58 |
+
video_url=f"https://www.youtube.com/watch?v={request.video_id}"
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
@app.post("/v1/searchSimilar", response_model=list[dict])
|
| 62 |
+
def search_similar(request: YoutubeLinkRequest):
|
| 63 |
+
try:
|
| 64 |
+
results = data_importer.search_similar(query=request.video_id)
|
| 65 |
+
return results
|
| 66 |
+
except Exception as e:
|
| 67 |
+
print(f"Error during search: {e}")
|
| 68 |
+
return {"error": "Search failed"}
|
| 69 |
+
return []
|
| 70 |
+
|
| 71 |
+
@app.post("/v1/basicChat", response_model=str)
|
| 72 |
+
def basic_chat(request: ChatRequest):
|
| 73 |
+
user_message = request.message
|
| 74 |
+
llm_response = asyncio.run(agent.basic_query(
|
| 75 |
+
user_prompt=user_message
|
| 76 |
+
))
|
| 77 |
+
return llm_response
|
| 78 |
+
|
app.py
CHANGED
|
@@ -85,19 +85,6 @@ def generate_trip_plan(request: PlanRequest):
|
|
| 85 |
# Wait before retrying
|
| 86 |
logger.info(f"Retrying in {RETRY_DELAY} seconds...")
|
| 87 |
time.sleep(RETRY_DELAY)
|
| 88 |
-
|
| 89 |
-
# except Exception as e:
|
| 90 |
-
# # For non-timeout errors, don't retry
|
| 91 |
-
# logger.error(f"Non-timeout error in generate_trip_plan: {e}")
|
| 92 |
-
# raise HTTPException(
|
| 93 |
-
# status_code=500,
|
| 94 |
-
# detail={
|
| 95 |
-
# "error": "Internal server error",
|
| 96 |
-
# "message": "Failed to generate trip plan",
|
| 97 |
-
# "details": str(e),
|
| 98 |
-
# "attempt": attempt + 1
|
| 99 |
-
# }
|
| 100 |
-
# )
|
| 101 |
|
| 102 |
|
| 103 |
@app.post("/v1/addYoutubeLink", response_model=YoutubeLinkResponse)
|
|
|
|
| 85 |
# Wait before retrying
|
| 86 |
logger.info(f"Retrying in {RETRY_DELAY} seconds...")
|
| 87 |
time.sleep(RETRY_DELAY)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
@app.post("/v1/addYoutubeLink", response_model=YoutubeLinkResponse)
|
utils/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
utils/llm_caller.py
CHANGED
|
@@ -104,7 +104,7 @@ class LLMCaller:
|
|
| 104 |
retrieved_data = []
|
| 105 |
context_text = ""
|
| 106 |
|
| 107 |
-
print(f"Search results: {search_results['result']}")
|
| 108 |
for result in search_results['result']:
|
| 109 |
retrieved_item = RetrievedItem(
|
| 110 |
place_id=result.get('id', 'Unknown'),
|
|
@@ -114,6 +114,7 @@ class LLMCaller:
|
|
| 114 |
retrieved_data.append(retrieved_item)
|
| 115 |
context_text += f"\n{result['payload'].get('text', '')}"
|
| 116 |
|
|
|
|
| 117 |
# 5. Create detailed prompt for LLM - updated with new fields
|
| 118 |
llm_prompt = f"""Generate a travel plan in JSON format for:
|
| 119 |
From: {plan_request.start_place} → To: {destination}
|
|
|
|
| 104 |
retrieved_data = []
|
| 105 |
context_text = ""
|
| 106 |
|
| 107 |
+
# print(f"Search results: {search_results['result']}")
|
| 108 |
for result in search_results['result']:
|
| 109 |
retrieved_item = RetrievedItem(
|
| 110 |
place_id=result.get('id', 'Unknown'),
|
|
|
|
| 114 |
retrieved_data.append(retrieved_item)
|
| 115 |
context_text += f"\n{result['payload'].get('text', '')}"
|
| 116 |
|
| 117 |
+
print(context_text)
|
| 118 |
# 5. Create detailed prompt for LLM - updated with new fields
|
| 119 |
llm_prompt = f"""Generate a travel plan in JSON format for:
|
| 120 |
From: {plan_request.start_place} → To: {destination}
|