Arafath10 commited on
Commit
9ef5d60
·
verified ·
1 Parent(s): e57c2bb

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +85 -2
main.py CHANGED
@@ -4,12 +4,95 @@ from fastapi.responses import StreamingResponse
4
  import requests
5
  import json,os,openai
6
 
 
7
  api_key = os.environ["OPENAI_API_KEY"]
8
 
9
  app = FastAPI()
10
 
 
11
  # Declare the continuous function as an async function.
12
- async def get_response():
13
- return "hu"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
 
 
4
  import requests
5
  import json,os,openai
6
 
7
+
8
  api_key = os.environ["OPENAI_API_KEY"]
9
 
10
  app = FastAPI()
11
 
12
+
13
  # Declare the continuous function as an async function.
14
+ async def streaming(userText,idf):
15
+
16
+ if str(idf)=="1":
17
+ openaikey = "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"
18
+ openai.api_key = openaikey
19
+ print(idf)
20
+
21
+
22
+ if str(idf) == "2" and str(userText.split("Prospect:")[-1]).lower() == " no":
23
+ remaind_msg = "That's alright. We provide AI engineering as a service. We work with some top startups and Fortune 500 companies to develop custom AI models for their business. Does that ring a bell now?"
24
+ return remaind_msg
25
+
26
+ if str(idf) == "2" and (
27
+ "remind" in str(userText.split("Prospect:")[-1]).lower() or
28
+ "remember" in str(userText.split("Prospect:")[-1]).lower() or
29
+ "forgot" in str(userText.split("Prospect:")[-1]).lower()
30
+ ):
31
+ remaind_msg = "That's alright. We provide AI engineering as a service. We work with some top startups and Fortune 500 companies to develop custom AI models for their business. Does that ring a bell now?"
32
+
33
+ return remaind_msg
34
+
35
+ dec = ""
36
+ yest = "This is [SDR’s name] with Neural Leap. I saw you schedule a call with us for [Insert day and time] to learn more about our A.I. engineering services. Does that ring a bell?"
37
+
38
+ if str(idf) == "1":
39
+ #openai.api_key = openaikey
40
+ response = openai.ChatCompletion.create(
41
+ model="gpt-3.5-turbo",
42
+ messages=[
43
+ {
44
+ "role": "user",
45
+ "content": "this is my part of conversation >" + userText +
46
+ "\n\ntell me this Prospect like to continue the conversation or unlike to continue the conversation? give only like or unlike as a result"
47
+ }
48
+ ],
49
+ )
50
+
51
+ dec = str(response.choices[0].message.content)
52
+ if 'unlike' not in dec.lower():
53
+ return yest
54
+
55
+
56
+
57
+ response = openai.ChatCompletion.create(
58
+ model="gpt-3.5-turbo",
59
+ stream=True,
60
+ messages=[{"role":"system","content":"""
61
+ \nif prospect like to finish or leave the conversation or call then lets finish don't ask any questions.give suitable respones
62
+
63
+ \n\n if prospect confirm the schedule the call then don't ask any questions only give this response one time only don't ask same questions again and again
64
+ "That's great! I just wanted to confirm that (time) still works for you and you are able to be on. Is that still the case ? ".
65
+
66
+ \n\n if prospect want to cancel the time not reschedule or change time then only give this response
67
+ "I appreciate you letting me know. If this is about finding a suitable time, let's figure out a slot that works for both of us. I'm available for both morning and afternoon sessions this week, what do you you prefer?"
68
+
69
+ \n\nif prospect like to reschedule or change the meeting without specific time(am or pm) then always suggest 3 diffrents random time between 10 am to 5pm (example 10am , 12pm ,3pm like this) and don't include 'appologise' word in response.
70
+
71
+ \n\nif prospect like to reschedule or change the meeting with specific day and time(am or pm) then give like this response 'Understood. I can make (prospect provided time). I will update our schedule accordingly. Thank you for letting us know.'
72
+
73
+ \n\nIf the prospect confirms that the time still works for him, then ask the following question:
74
+ sample question format 'Before we begin our conversation, it would be helpful to know more about your financial landscape. Are there specific budgetary constraints or financial aspects that we should take into account to ensure our discussion is tailored to your needs?'
75
+
76
+ \n\nAfter the prospect provides budget details then only, inquire about and assess their specific needs and pain points.'
77
+
78
+ \n\nnote : don't ask same questions again and again always give single response, don't iclude the prospect, sdr conversation responses\n\n """},
79
+
80
+ {"role":"user","content":userText}],
81
+ )
82
+
83
+ for chunk in response:
84
+ try:
85
+ yield chunk.choices[0].delta.content
86
+ except:
87
+ yield "error"
88
+
89
+
90
+
91
+
92
+
93
+ @app.post("/get_sdr_response/")
94
+ async def get_sdr_response(userText,idf):
95
+ return StreamingResponse(streaming(userText,idf), media_type="text/plain")
96
+
97
 
98