Emmel Cyrus Navarro Greetings & Welcome to Microsoft Q&A forum!
Similar issue has been addressed here by Naveen. I'm adding the answer here for reference.
To implement a ‘Regenerate’ button in your chatbot, you would need to make another API call to the Azure Open AI model endpoint with the same prompt when the ‘Regenerate’ button is clicked.
Here’s a simplified example of how you could implement this in Python using Flask and the OpenAI API:
from flask import Flask, request
import os
from openai import AzureOpenAI
app = Flask(__name__)
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version="2023-12-01-preview",
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
)
deployment_name='REPLACE_WITH_YOUR_DEPLOYMENT_NAME' #This will correspond to the custom name you chose for your deployment when you deployed a model. Use a gpt-35-turbo-instruct deployment.
@app.route('/chat', methods=['POST'])
def chat():
message = request.json['message']
response = client.completions.create(model=deployment_name, prompt=message, max_tokens=10)
return response.choices[0].text
if __name__ == '__main__':
app.run()
In this code, when a POST request is made to the ‘/chat’ endpoint with a message, the chatbot generates a response using the Azure OpenAI model. If the user is not satisfied with the response and clicks the ‘Regenerate’ button, your frontend should make another POST request to the ‘/chat’ endpoint with the same message, and the chatbot will generate a new response.
Please replace 'REPLACE_WITH_YOUR_DEPLOYMENT_NAME' with your actual deployment name. Also, remember to handle exceptions and edge cases according to your application’s needs. This is a simplified example and might need modifications based on your application’s architecture and requirements.
You can find more information about the Python Azure Open AI code here.
Do let me know if that helps or have any other queries.
If the response helped, please do click Accept Answer
and Yes
for was this answer helpful.
Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.