Skip to content
Open

UI #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions globetrotter-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ videos/*
!videos/*.js
!videos/*.ts
public/_next-video

globetrotter-app/globetrotter-key.json

>>>>>>> 80afc2d46c8cfbd2852e3c9b5d741412c1072a37
4 changes: 3 additions & 1 deletion globetrotter-app/hooks/recordVoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ export const useRecordVoice = () => {
}, []);

return { recording, startRecording, stopRecording, text };
};
};

// send to python form here
43 changes: 24 additions & 19 deletions globetrotter-backend/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from flask import Flask, request, jsonify
from flask_cors import CORS
import requests
import requests
import google.generativeai as genai
import json
import os

app = Flask(__name__)
CORS(app)

GOOGLE_API_KEY = "AIzaSyAtw3ossKpb0a9aiDnB385Xal2OJpZX0ac"
genai.configure(api_key=GOOGLE_API_KEY)
Expand All @@ -17,33 +20,35 @@
def generate_travel_guide():
data = request.json
user_input = data.get('user_input', '')
obj = {"responseText":"Your response here, fit with some travel destination recommendations or activities based on the user's input, also add some questions based on things that you don't have values of in the details area",
"details":[
{"parameter":"departure", "value":"<value>"},
{"parameter":"arrival", "value":"<value>"},
{"parameter":"start_date", "value":"<value>"},
{"parameter":"end_date", "value":"<value>"},
{"parameter":"numAdults", "value":"<value>"},
{"parameter":"numChildren", "value":"<value>"},
{"parameter":"numInfants", "value":"<value>"},
{"parameter":"baggage", "value":"<value>"},
{"parameter":"isOneWay", "value":"<true/false>"},
{"parameter":"classPreference", "value":"<value>"},
{"parameter":"directOnly", "value":"<true/false>"}
]}

prompt = f"""
You are a travel booking assistant. The user provided the following information: "{user_input}".
Please extract and format the details like this JSON example:

{{
"responseText": "<Your response here, fit with some travel destination recommendations or activities based on the user's input, also add some questions based on things that you don't have values of in the details area>",
"details": [
{{"parameter": "departure", "value": "<value>"}},
{{"parameter": "arrival", "value": "<value>"}},
{{"parameter": "start_date", "value": "<value>"}},
{{"parameter": "end_date", "value": "<value>"}},
{{"parameter": "numAdults", "value": "<value>"}},
{{"parameter": "numChildren", "value": "<value>"}},
{{"parameter": "numInfants", "value": "<value>"}},
{{"parameter": "baggage", "value": "<value>"}},
{{"parameter": "isOneWay", "value": <true/false>}},
{{"parameter": "classPreference", "value": "<value>"}},
{{"parameter": "directOnly", "value": <true/false>}}
],
}}
Use data from the sentence to output in the following JSON format. do not include formatting or code blocks:
{json.dumps(obj)}
"""
try:
response = model.generate_content(prompt)
response_text = response.text
print("PROMPT")
print(prompt)
print("RESPONSE")
print(json.loads(response_text))
clean_response_text = response_text.replace("```json\n", "").replace("\n```", "")
return jsonify({'response': clean_response_text})
return json.loads(response_text)
except Exception as e:
return jsonify({'error': str(e)}), 500

Expand Down