Spaces:
Sleeping
Sleeping
| from openai import AzureOpenAI, OpenAI | |
| import os | |
| import model | |
| # from dotenv import load_dotenv | |
| def create_client(): | |
| print("In create client") | |
| # for local | |
| # load_dotenv() | |
| # if using openai | |
| client = OpenAI() | |
| # if using azureopenai | |
| # client = AzureOpenAI() | |
| return client | |
| def get_completion(ticket:model.Ticket): | |
| print("In get completion") | |
| # hardcoding response for testing | |
| # result = "intent= Complaint\nsuggested_response= Issue Refund\nsummary= The customer is making a complaint. Suggested resolution is to issue a refund.\nmail=\nDear Customer,\n\nWe are sorry to hear that you have a complaint regarding your booking. We understand the inconvenience this has caused you and we would like to make things right. Our records show that you have requested a refund.\n\nWe have processed your refund request and you should receive the refund within 3-5 business days. We apologize" | |
| # return result | |
| client = create_client() | |
| prompt = create_prompt(ticket.subject, ticket.description) | |
| response = client.completions.create( | |
| model=os.environ.get('MODEL_NAME'), | |
| prompt=prompt, | |
| max_tokens=1000, | |
| n=1, | |
| stop=None, | |
| temperature=1 | |
| ) | |
| result = response.choices[0].text.strip() | |
| print(result) | |
| return result | |
| def create_prompt(subject:str, desc:str): | |
| print("In create Prompt") | |
| # add booking data here | |
| prompt = ''' | |
| You are an AI Customer Service Agent for booking.com. Use the below instructions to answer. | |
| Determine the intent of this request: ```Subject: {{subject}} Description: {{desc}}``` in 1 single word? Use one the following options for intent: | |
| Cancellation | |
| Reporting Unknown Charge | |
| Complaint | |
| Information Request | |
| In the context of the previous request, Suggest a resolution response to address the customer query from the following actions list: | |
| Cancellation : Cancel the booking and issue refund if applicable | |
| Issue Refund for the unknown charge | |
| For Complaints, issue good will gesture voucher | |
| Provide information | |
| Finally, Summarize the message: ``` | |
| Subject: {{subject}}Description:{{desc}}``` and generate a mail content for the customer about the whole conversation. | |
| Give the final result like this: | |
| intent= {your intent} | |
| suggested_response= {your response} | |
| summary= {your summary} | |
| mail={generated_mail} | |
| ''' | |
| return prompt |