Hello, No matter what I do my api is not calling the function. Instead every time I am getting “finish_reason”: “stop”. I am sharing my code. Can anyone identify what I am doing wrong?
def extract_discount_details(max_discount, bank_name, min_swipe):
'''Get the discount details like discount amount, bank name and Minimum swipe/pucrhase from the offer which is resulting in maximum discount
Inputs:
max_discount (integer): The discount amount from the best offer
bank_name (str): The name of the bank which is offereing the best offer
min_swipe (int): The minimum swipe or purchase amount from the best offer
'''
discount_info = {
"Maximum Discount" : max_discount,
"Bank Name" : bank_name,
"Minimum Swipe" : min_swipe
}
return json.dumps(discount_info)
def run_idenification(messages_2):
# Step 1: send the conversation and available functions to GPT
messages = messages_2
functions = [
{
"name": "extract_discount_details",
"description": "Get the discount details like discount amount, bank name and Minimum swipe/pucrhase from the offer which is resulting in maximum discount",
"parameters": {
"type": "object",
"properties": {
"max_discount": {
"type": "integer",
"description": "The discount amount from the best offer. e.g. 2000, 500"
},
"bank_name": {
"type": "string",
"description": "The name of the bank which is offereing the best offer. e.g HDFC Bank Credit card, ICICI Bank"
},
"min_swipe": {
"type": "integer",
"description": "The minimum swipe or purchase amount from the best offer. e.g. 17899, 19999"
}
},
"required": ["max_discount"]
}
}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=messages,
functions=functions,
function_call="auto", # auto is default, but we'll be explicit
temperature=0.1
)
response_message = response["choices"][0]["message"]
messages_3 = [
{"role": "user", "content": "The Price of the SKU is 19999\n\nOffers:\n\n1. Flat INR 2100 Instant Discount on HDFC Bank Credit CardTxn. Minimum purchase value INR 17999\n\n2. Flat INR 2100 Instant Discount on ICICI Bank Credit Cards (excluding Amazon Pay ICICI Credit Card) Credit CardTxn. Minimum purchase value INR 17999\n\n3. Flat INR 2000 Instant Discount on HDFC Bank Debit Card EMI Txn. Minimum purchase value INR 19999\n\n4. 5% Instant Discount up to INR 250 on HSBC Cashback Card Credit Card Transactions. Minimum purchase value INR 1000\n\n5. Get 5% back with Amazon Pay ICICI Bank credit card for Prime members. 3% back for others. Not applicable on Amazon business transactions.\n\n6. ₹100 cashback & ₹500 welcome rewards on Amazon Pay Later.\n\nWhich is the best Offer?"}
]
print(run_idenification(messages_3))
Output:
{
"id": "chatcmpl-82aWHMj7SS5NZq25CnrzQCLjfQa7a",
"object": "chat.completion",
"created": 1695627729,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The best offer would be offer number 1: Flat INR 2100 Instant Discount on HDFC Bank Credit CardTxn. Minimum purchase value INR 17999. This offer provides the highest discount amount of INR 2100."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 251,
"completion_tokens": 50,
"total_tokens": 301
}
}