Sneha Dixit commited on
Commit
74a9b66
1 Parent(s): b8d9e07

config related change

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. auth.py +4 -0
  3. client.py +31 -27
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  __pycache__/
 
2
 
 
1
  __pycache__/
2
+ .env
3
 
auth.py CHANGED
@@ -1,11 +1,15 @@
1
  from fastapi.security.api_key import APIKeyHeader
2
  from fastapi import Security, HTTPException
3
  import os
 
4
 
5
 
6
  api_key_header = APIKeyHeader(name="x-api-key", auto_error=False)
7
 
8
  async def api_key_auth(api_key: str = Security(api_key_header)):
 
 
 
9
  API_Keys = [os.environ.get('API_KEY')]
10
  if api_key not in API_Keys:
11
  raise HTTPException(status_code=401, detail="Missing or invalid API key")
 
1
  from fastapi.security.api_key import APIKeyHeader
2
  from fastapi import Security, HTTPException
3
  import os
4
+ # from dotenv import load_dotenv
5
 
6
 
7
  api_key_header = APIKeyHeader(name="x-api-key", auto_error=False)
8
 
9
  async def api_key_auth(api_key: str = Security(api_key_header)):
10
+ # for local
11
+ # load_dotenv()
12
+
13
  API_Keys = [os.environ.get('API_KEY')]
14
  if api_key not in API_Keys:
15
  raise HTTPException(status_code=401, detail="Missing or invalid API key")
client.py CHANGED
@@ -1,53 +1,57 @@
1
- from openai import AzureOpenAI
2
  import os
3
  import model
 
4
 
5
  def create_client():
6
  print("In create client")
7
- client = AzureOpenAI(
8
- api_key=os.environ.get('OPENAI_API_KEY'),
9
- api_version=os.environ.get('MODEL_VERSION'),
10
- azure_endpoint = os.environ.get('END_POINT')
11
- )
 
 
 
 
 
12
  return client
13
 
14
  def get_completion(ticket:model.Ticket):
15
  print("In get completion")
 
16
  # hardcoding response for testing
17
- 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"
18
- # client = create_client()
19
- # prompt = create_prompt(ticket.subject, ticket.description)
20
- # response = client.completions.create(
21
- # model=os.environ.get('MODEL_NAME'),
22
- # prompt=prompt,
23
- # max_tokens=100,
24
- # n=1,
25
- # stop=None,
26
- # temperature=0.7
27
- # )
28
- # result = response.choices[0].text.strip()
29
- # print(result)
 
 
30
  return result
31
 
32
  def create_prompt(subject:str, desc:str):
33
  print("In create Prompt")
34
  # add booking data here
35
- data = ""
36
  prompt = '''
37
  You are an AI Customer Service Agent for booking.com. Please use the below instructions to answer.
38
  What is the intent of this request ```
39
- Subject: {{subject}} Description: {{desc}}``` in 1 single word? Use these options for intent :
40
 
41
  Complaint
42
- Information Request
43
  Service Request
44
- Cancellation
45
- Change
46
  Refund Request
47
 
48
- In the context of the previous request,
49
- If the intent is Information Request, use the ``` Booking Details: {{data}}``` to provide information as part of resolution response.
50
- otherwise Suggest a resolution response to address the customer query from the following actions list:
51
 
52
  Issue Refund
53
  Cancellation
 
1
+ from openai import AzureOpenAI, OpenAI
2
  import os
3
  import model
4
+ # from dotenv import load_dotenv
5
 
6
  def create_client():
7
  print("In create client")
8
+
9
+ # for local
10
+ # load_dotenv()
11
+
12
+ # if using openai
13
+ client = OpenAI()
14
+
15
+ # if using azureopenai
16
+ # client = AzureOpenAI()
17
+
18
  return client
19
 
20
  def get_completion(ticket:model.Ticket):
21
  print("In get completion")
22
+
23
  # hardcoding response for testing
24
+ # 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"
25
+ # return result
26
+
27
+ client = create_client()
28
+ prompt = create_prompt(ticket.subject, ticket.description)
29
+ response = client.completions.create(
30
+ model=os.environ.get('MODEL_NAME'),
31
+ prompt=prompt,
32
+ max_tokens=500,
33
+ n=1,
34
+ stop=None,
35
+ temperature=0.5
36
+ )
37
+ result = response.choices[0].text.strip()
38
+ print(result)
39
  return result
40
 
41
  def create_prompt(subject:str, desc:str):
42
  print("In create Prompt")
43
  # add booking data here
 
44
  prompt = '''
45
  You are an AI Customer Service Agent for booking.com. Please use the below instructions to answer.
46
  What is the intent of this request ```
47
+ Subject: {{subject}} Description: {{desc}}``` in 1 single word? Use these options for intent:
48
 
49
  Complaint
 
50
  Service Request
51
+ Cancellation Request
 
52
  Refund Request
53
 
54
+ In the context of the previous request, Suggest a resolution response to address the customer query from the following actions list:
 
 
55
 
56
  Issue Refund
57
  Cancellation