def provide_user_specific_recommendations(user_input, user_id):
customer_profile = fetch_customer_profile(user_id)
if customer_profile is None:
return "I couldn't find your profile. Could you please verify your user ID?"
customer_profile_str = json.dumps(customer_profile)
food_preference = customer_profile.get('preferences', {}).get('food', [])[0] if customer_profile.get('preferences', {}).get('food') else None
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": f"You are a sophisticated AI assistant, a specialist in user intent detection and interpretation. Your task is to perceive and respond to the user's needs, even when they're expressed in an indirect or direct manner. You excel in recognizing subtle cues: for example, if a user states they are 'hungry', you should assume they are seeking nearby dining options such as a restaurant or a cafe. If they indicate feeling 'tired', 'weary', or mention a long journey, interpret this as a request for accommodation options like hotels or guest houses. However, remember to navigate the fine line of interpretation and assumption: if a user's intent is unclear or can be interpreted in multiple ways, do not hesitate to politely ask for additional clarification. Make sure to tailor your responses to the user based on their preferences and past experiences which can be found here {customer_profile_str}"
},
{"role": "user", "content": user_input}
],
temperature=0,
tools=[
{
"type": "function",
"function" : {
"name": "call_google_places_api",
"description": "This function calls the Google Places API to find the top places of a specified type near a specific location. It can be used when a user expresses a need (e.g., feeling hungry or tired) or wants to find a certain type of place (e.g., restaurant or hotel).",
"parameters": {
"type": "object",
"properties": {
"place_type": {
"type": "string",
"description": "The type of place to search for."
}
}
},
"result": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
],
)
print(response.choices[0].message.tool_calls)
if response.choices[0].finish_reason=='tool_calls':
function_call = response.choices[0].message.tool_calls[0].function
if function_call.name == "call_google_places_api":
place_type = json.loads(function_call.arguments)["place_type"]
places = call_google_places_api(user_id, place_type, food_preference)
if places: # If the list of places is not empty
return f"Here are some places you might be interested in: {' '.join(places)}"
else:
return "I couldn't find any places of interest nearby."
return "I am sorry, but I could not understand your request."