Spaces:
Sleeping
Sleeping
| import asyncio | |
| from fastapi import FastAPI | |
| from fastapi.responses import StreamingResponse | |
| import requests | |
| import json,os,openai | |
| api_key = os.environ["OPENAI_API_KEY"] | |
| # Declare the continuous function as an async function. | |
| def streaming(userText,idf): | |
| import openai | |
| openaikey = api_key | |
| openai.api_key = openaikey | |
| if str(idf)=="1": | |
| print(idf) | |
| if str(idf) == "2" and str(userText.split("Prospect:")[-1]).lower() == " no": | |
| 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?" | |
| yield remaind_msg | |
| return "" | |
| if str(idf) == "2" and ( | |
| "remind" in str(userText.split("Prospect:")[-1]).lower() or | |
| "remember" in str(userText.split("Prospect:")[-1]).lower() or | |
| "forgot" in str(userText.split("Prospect:")[-1]).lower() | |
| ): | |
| 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?" | |
| yield remaind_msg | |
| return "" | |
| dec = "" | |
| 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 AI engineering services. Does that ring a bell?" | |
| if str(idf) == "1": | |
| #openai.api_key = openaikey | |
| response = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", | |
| messages=[ | |
| { | |
| "role": "user", | |
| "content": "this is my part of conversation >" + userText + | |
| "\n\ntell me this Prospect like to continue the conversation or unlike to continue the conversation? give only like or unlike as a result" | |
| } | |
| ], | |
| ) | |
| dec = str(response.choices[0].message.content) | |
| if 'unlike' not in dec.lower(): | |
| yield yest | |
| return "" | |
| response = openai.ChatCompletion.create( | |
| model="gpt-4", | |
| stream=True, | |
| messages=[{"role":"system","content":""" | |
| company Details: | |
| This is [SDR’s name] from Neural Leap 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. | |
| 1. When the prospect wishes to end or leave the conversation/call: | |
| - Response: "I understand. Thank you for your time today. If you have any questions or need further assistance in the future, please don't hesitate to reach out. Have a great day!" | |
| 2. If the prospect confirms the schedule for the call: | |
| - Response: "That's great! I just wanted to confirm that (time) still works for you and that you are able to be on. Is that still the case?" | |
| 3. If the prospect wants to cancel the meeting without rescheduling: | |
| - Response: "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 prefer?" | |
| 4. If the prospect wishes to reschedule the meeting without specifying a time (AM or PM): | |
| - Response: "Certainly, let's find a new time that works for both of us. How about we consider 10 AM, 12 PM, or 3 PM? Please let me know which time suits you best." | |
| 5. If the prospect wishes to reschedule the meeting with a specific day and time: | |
| - Response: "Understood. I can make (prospect provided time). I will update our schedule accordingly. Thank you for letting us know." | |
| 6. If the prospect After confirming the meeting time always ask this : | |
| - Question: "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?" | |
| 7. After the prospect provides budget details: | |
| - Inquiry: "Thank you for sharing that information. Could you tell me more about your specific needs and pain points? Understanding these will help us address your concerns more effectively." | |
| \n\nnote : don't ask same questions again and again always give single response, please don't iclude the prospect :, SDR : conversation responses\n\n """}, | |
| {"role":"user","content":userText}], | |
| ) | |
| for chunk in response: | |
| try: | |
| #print(chunk.choices[0].delta.content) | |
| out = (chunk.choices[0].delta.content).replace("SD","") | |
| out = out.replace("R","") | |
| print(out) | |
| yield out.replace(":","") | |
| except: | |
| return "" | |
| app = FastAPI() | |
| async def get_sdr_response(userText,idf): | |
| return StreamingResponse(streaming(userText,idf), media_type="text/plain") | |