Hello 78233321,
I'm not sure if this approach meets your requirements.
The following code will employ function calling to achieve the 'understand' the intent you mentioned. When GPT discerns that a user is inquiring about a product, it will retrieve product information through an API request and respond to related questions.
For a complete example code, please refer to the Microsoft Learn documentation.
from openai import AzureOpenAI
import requests
client = AzureOpenAI(
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version="2024-03-01-preview"
)
def get_product_info(product_id):
return requests.get(f"https://<some-product-system>/api/products/product/{product_id}").json()
messages = [{"role": "user", "content": "..."}]
tools = [
{
"type": "function",
"function": {
"name": "get_product_info",
"description": "Obtain information about the product.",
"parameters": {
"type": "object",
"properties": {
"product_id": {
"type": "string",
"description": "The ID of the product",
}
},
"required": ["product_id"],
},
},
}
]
response = client.chat.completions.create(
model="<REPLACE_WITH_YOUR_MODEL_DEPLOYMENT_NAME>",
messages=messages,
tools=tools,
tool_choice="auto"
)
est regards,
Charlie
If you find my response helpful, please consider accepting this answer
and voting yes
to support the community. Thank you!