from enum import Enum
from typing import Union
import openai
product_search_prompt = '''
You are a clothes recommendation agent, specialized in finding the perfect match for a user.
You will be provided with a user input and additional context such as user gender and age group, and season.
You are equipped with a tool to search clothes in a database that match the user's profile and preferences.
Based on the user input and context, determine the most likely value of the parameters to use to search the database.
Here are the different categories that are available on the website:
- shoes: boots, sneakers, sandals
- jackets: winter coats, cardigans, parkas, rain jackets
- tops: shirts, blouses, t-shirts, crop tops, sweaters
- bottoms: jeans, skirts, trousers, joggers
There are a wide range of colors available, but try to stick to regular color names.
'''
class Category(str, Enum):
shoes = "shoes"
jackets = "jackets"
tops = "tops"
bottoms = "bottoms"
class ProductSearchParameters(BaseModel):
category: Category
subcategory: str
color: str
def get_response(user_input, context):
response = client.chat.completions.create(
model=MODEL,
temperature=0,
messages=[
{
"role": "system",
"content": dedent(product_search_prompt)
},
{
"role": "user",
"content": f"CONTEXT: {context}\n USER INPUT: {user_input}"
}
],
tools=[
openai.pydantic_function_tool(ProductSearchParameters, name="product_search", description="Search for a match in the product database")
]
)
return response.choices[0].message.tool_calls