Spaces:
Sleeping
Sleeping
modify prompts
Browse files- gemini_api.py +53 -45
gemini_api.py
CHANGED
@@ -11,20 +11,19 @@ genai.configure(api_key=GEMINI_API_KEY)
|
|
11 |
model = genai.GenerativeModel('gemini-2.0-flash')
|
12 |
|
13 |
def get_travel_info(user_input):
|
14 |
-
"""Uses Gemini AI to extract travel intent and
|
15 |
|
16 |
prompt = f"""
|
17 |
-
You are a travel assistant. Your job is to extract the travel intent,
|
18 |
-
|
19 |
-
The location is the destination of the travel.
|
20 |
-
If the location is not specified, return None.
|
21 |
If the intent is not related to travel, return the intent and location in JSON format ONLY, like this:
|
22 |
-
If either the intent, the
|
23 |
|
24 |
```json
|
25 |
{{
|
26 |
"intent": "the extracted intent",
|
27 |
-
"
|
|
|
28 |
"departure_date": "the extracted departure date",
|
29 |
"duration": "the extracted duration",
|
30 |
"budget": "the extracted budget",
|
@@ -32,11 +31,12 @@ def get_travel_info(user_input):
|
|
32 |
}}
|
33 |
```
|
34 |
|
35 |
-
User Query: I want to plan a trip to Paris for 5 days with a budget of $2000 for 2 people, leaving on March 15th.
|
36 |
```json
|
37 |
{{
|
38 |
"intent": "plan a trip",
|
39 |
-
"
|
|
|
40 |
"departure_date": "March 15th",
|
41 |
"duration": "5 days",
|
42 |
"budget": "$2000",
|
@@ -48,7 +48,8 @@ def get_travel_info(user_input):
|
|
48 |
```json
|
49 |
{{
|
50 |
"intent": "Find a hotel",
|
51 |
-
"
|
|
|
52 |
"departure_date": "April 10th",
|
53 |
"duration": "3 nights",
|
54 |
"budget": "$1500",
|
@@ -60,7 +61,8 @@ def get_travel_info(user_input):
|
|
60 |
```json
|
61 |
{{
|
62 |
"intent": null,
|
63 |
-
"
|
|
|
64 |
"departure_date": null,
|
65 |
"duration": null,
|
66 |
"budget": null,
|
@@ -82,14 +84,16 @@ def get_travel_info(user_input):
|
|
82 |
json_string = match.group(0).strip()
|
83 |
data = json.loads(json_string)
|
84 |
intent = data.get("intent")
|
85 |
-
|
|
|
86 |
departure_date = data.get("departure_date")
|
87 |
duration = data.get("duration")
|
88 |
budget = data.get("budget")
|
89 |
num_people = data.get("num_people")
|
90 |
return {
|
91 |
"intent": intent,
|
92 |
-
"
|
|
|
93 |
"departure_date": departure_date,
|
94 |
"duration": duration,
|
95 |
"budget": budget,
|
@@ -106,62 +110,66 @@ def get_travel_info(user_input):
|
|
106 |
print(f"An unexpected error occurred: {e}")
|
107 |
return None
|
108 |
|
109 |
-
def get_travel_recommendations(intent,
|
110 |
-
"""Uses Gemini AI to provide travel recommendations based on intent and
|
111 |
|
112 |
prompt = f"""
|
113 |
-
You are a travel assistant. Based on the given intent,
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
119 |
|
120 |
Intent: {intent}
|
121 |
-
|
|
|
122 |
Departure Date: {departure_date}
|
123 |
Duration: {duration}
|
124 |
Budget: {budget}
|
125 |
-
Number of
|
126 |
|
127 |
Your response should look like this:
|
128 |
|
129 |
-
# π Travel Guide: {
|
130 |
|
131 |
## π€οΈ Weather:
|
132 |
-
- Weather
|
133 |
|
134 |
-
## βοΈ
|
135 |
-
-
|
136 |
-
-
|
137 |
-
|
138 |
-
## π¨ Accommodations:
|
139 |
-
- Hotel 1
|
140 |
-
- Hotel 2
|
141 |
|
142 |
## π³ Mobile Payment:
|
143 |
-
-
|
144 |
-
-
|
145 |
|
146 |
## π Local Transportations:
|
147 |
-
-
|
148 |
-
-
|
|
|
|
|
|
|
|
|
149 |
|
150 |
## π° Attractions:
|
151 |
-
-
|
152 |
-
-
|
153 |
|
154 |
## π Activities:
|
155 |
-
-
|
156 |
-
-
|
157 |
|
158 |
-
## π½οΈ Foods:
|
159 |
-
-
|
160 |
-
-
|
161 |
|
162 |
## π‘ Tips for Planning:
|
163 |
-
-
|
164 |
-
-
|
165 |
"""
|
166 |
|
167 |
response = model.generate_content(prompt)
|
|
|
11 |
model = genai.GenerativeModel('gemini-2.0-flash')
|
12 |
|
13 |
def get_travel_info(user_input):
|
14 |
+
"""Uses Gemini AI to extract travel intent, origin, destination, and other travel details from user input."""
|
15 |
|
16 |
prompt = f"""
|
17 |
+
You are a travel assistant. Your job is to extract the travel intent, origin (from where), destination (to where), and departure date from a user's query.
|
18 |
+
If the origin is not mentioned, return null.
|
|
|
|
|
19 |
If the intent is not related to travel, return the intent and location in JSON format ONLY, like this:
|
20 |
+
If either the intent, the origin, the destination, the departure_date, duration, budget, or num_people is not found, return null for that field.
|
21 |
|
22 |
```json
|
23 |
{{
|
24 |
"intent": "the extracted intent",
|
25 |
+
"from": "the extracted origin",
|
26 |
+
"to": "the extracted destination",
|
27 |
"departure_date": "the extracted departure date",
|
28 |
"duration": "the extracted duration",
|
29 |
"budget": "the extracted budget",
|
|
|
31 |
}}
|
32 |
```
|
33 |
|
34 |
+
User Query: I want to plan a trip from Los Angeles to Paris for 5 days with a budget of $2000 for 2 people, leaving on March 15th.
|
35 |
```json
|
36 |
{{
|
37 |
"intent": "plan a trip",
|
38 |
+
"from": "Los Angeles",
|
39 |
+
"to": "Paris",
|
40 |
"departure_date": "March 15th",
|
41 |
"duration": "5 days",
|
42 |
"budget": "$2000",
|
|
|
48 |
```json
|
49 |
{{
|
50 |
"intent": "Find a hotel",
|
51 |
+
"from": null,
|
52 |
+
"to": "New York City",
|
53 |
"departure_date": "April 10th",
|
54 |
"duration": "3 nights",
|
55 |
"budget": "$1500",
|
|
|
61 |
```json
|
62 |
{{
|
63 |
"intent": null,
|
64 |
+
"from": null,
|
65 |
+
"to": null,
|
66 |
"departure_date": null,
|
67 |
"duration": null,
|
68 |
"budget": null,
|
|
|
84 |
json_string = match.group(0).strip()
|
85 |
data = json.loads(json_string)
|
86 |
intent = data.get("intent")
|
87 |
+
from_location = data.get("from")
|
88 |
+
to_location = data.get("to")
|
89 |
departure_date = data.get("departure_date")
|
90 |
duration = data.get("duration")
|
91 |
budget = data.get("budget")
|
92 |
num_people = data.get("num_people")
|
93 |
return {
|
94 |
"intent": intent,
|
95 |
+
"from": from_location,
|
96 |
+
"to": to_location,
|
97 |
"departure_date": departure_date,
|
98 |
"duration": duration,
|
99 |
"budget": budget,
|
|
|
110 |
print(f"An unexpected error occurred: {e}")
|
111 |
return None
|
112 |
|
113 |
+
def get_travel_recommendations(intent, from_location, to_location, departure_date, duration, budget, num_people):
|
114 |
+
"""Uses Gemini AI to provide travel recommendations based on intent, origin, and destination."""
|
115 |
|
116 |
prompt = f"""
|
117 |
+
You are a travel assistant. Based on the given intent, origin (from where), destination (to where), duration, budget, and number of people, provide helpful travel recommendations in Markdown format.
|
118 |
+
- Provide some common websites for booking flights as well as the like to the web.
|
119 |
+
- List at least 2 of the cheapest flight options.
|
120 |
+
- Provide at least 10 recommended attractions.
|
121 |
+
- Provide at least 5 accommodations.
|
122 |
+
- Provide at least 10 activities.
|
123 |
+
- Provide at least 10 food recommendations.
|
124 |
+
- Keep in mind the budget and number of people when suggesting accommodations and activities.
|
125 |
+
- Use NTD as the currency
|
126 |
|
127 |
Intent: {intent}
|
128 |
+
From: {from_location}
|
129 |
+
To: {to_location}
|
130 |
Departure Date: {departure_date}
|
131 |
Duration: {duration}
|
132 |
Budget: {budget}
|
133 |
+
Number of People: {num_people}
|
134 |
|
135 |
Your response should look like this:
|
136 |
|
137 |
+
# π Travel Guide: {to_location}
|
138 |
|
139 |
## π€οΈ Weather:
|
140 |
+
- Weather details for {to_location}
|
141 |
|
142 |
+
## βοΈ Flights from {from_location} to {to_location}:
|
143 |
+
-
|
144 |
+
-
|
|
|
|
|
|
|
|
|
145 |
|
146 |
## π³ Mobile Payment:
|
147 |
+
-
|
148 |
+
-
|
149 |
|
150 |
## π Local Transportations:
|
151 |
+
-
|
152 |
+
-
|
153 |
+
|
154 |
+
## π¨ Accommodations:
|
155 |
+
-
|
156 |
+
-
|
157 |
|
158 |
## π° Attractions:
|
159 |
+
-
|
160 |
+
-
|
161 |
|
162 |
## π Activities:
|
163 |
+
-
|
164 |
+
-
|
165 |
|
166 |
+
## π½οΈ Foods to Try:
|
167 |
+
-
|
168 |
+
-
|
169 |
|
170 |
## π‘ Tips for Planning:
|
171 |
+
-
|
172 |
+
-
|
173 |
"""
|
174 |
|
175 |
response = model.generate_content(prompt)
|