LAKERFrank commited on
Commit
e36871a
Β·
verified Β·
1 Parent(s): 5d53a0e

modify prompts

Browse files
Files changed (1) hide show
  1. 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 location from user input."""
15
 
16
  prompt = f"""
17
- You are a travel assistant. Your job is to extract the travel intent, location, and departure date from a user's query.
18
- The intent can be anything from planning a trip to finding a hotel to suggesting a restaurant.
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 location, the departure_date, duration, budget, or num_people is not found, return null for that field.
23
 
24
  ```json
25
  {{
26
  "intent": "the extracted intent",
27
- "location": "the extracted location",
 
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
- "location": "Paris",
 
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
- "location": "New York City",
 
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
- "location": null,
 
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
- location = data.get("location")
 
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
- "location": location,
 
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, location, departure_date, duration, budget, num_people):
110
- """Uses Gemini AI to provide travel recommendations based on intent and location."""
111
 
112
  prompt = f"""
113
- You are a travel assistant. Based on the given intent, location, duration, budget, and number of people, provide helpful travel recommendations in Markdown format.
114
- Attractions should provide at least 10 recommendations.
115
- Accommodations should provide at least 5 recommendations.
116
- Activities should provide at least 10 recommendations.
117
- Food should provide at least 10 recommendations.
118
- Keep in mind the budget and the number of people when suggesting accommodations and activities.
 
 
 
119
 
120
  Intent: {intent}
121
- Location: {location}
 
122
  Departure Date: {departure_date}
123
  Duration: {duration}
124
  Budget: {budget}
125
- Number of people: {num_people}
126
 
127
  Your response should look like this:
128
 
129
- # 🌍 Travel Guide: {location}
130
 
131
  ## 🌀️ Weather:
132
- - Weather 1
133
 
134
- ## ✈️ Flight:
135
- - Flight 1
136
- - Flight 2
137
-
138
- ## 🏨 Accommodations:
139
- - Hotel 1
140
- - Hotel 2
141
 
142
  ## πŸ’³ Mobile Payment:
143
- - Mobile Payment 1
144
- - Mobile Payment 2
145
 
146
  ## πŸš— Local Transportations:
147
- - Local Transportations 1
148
- - Local Transportations 2
 
 
 
 
149
 
150
  ## 🏰 Attractions:
151
- - Attraction 1
152
- - Attraction 2
153
 
154
  ## πŸš€ Activities:
155
- - Activity 1
156
- - Activity 2
157
 
158
- ## 🍽️ Foods:
159
- - Foods 1
160
- - Foods 2
161
 
162
  ## πŸ’‘ Tips for Planning:
163
- - Tips for Planning 1
164
- - Tips for Planning 2
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)