HarshSanghavi commited on
Commit
d5c913c
1 Parent(s): 5039b99

Update chat.py

Browse files
Files changed (1) hide show
  1. chat.py +46 -46
chat.py CHANGED
@@ -1,46 +1,46 @@
1
- from langchain.memory import ConversationBufferWindowMemory
2
- from langchain_community.chat_models import ChatOpenAI
3
- from langchain_mongodb.chat_message_histories import MongoDBChatMessageHistory
4
- # from langchain_experimental.data_anonymizer import PresidioReversibleAnonymizer
5
- from langchain.agents import AgentExecutor
6
- from langchain.agents.format_scratchpad import format_to_openai_functions
7
- from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
8
- from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
9
- from langchain.schema.runnable import RunnablePassthrough
10
- from langchain_core.utils.function_calling import convert_to_openai_function
11
-
12
- from database_functions import set_chat_bot_name,isFirstSession
13
- from utils import deanonymizer, create_agent,chat_balancer
14
- import time
15
- def chat_conversations(query,user_id):
16
- is_first = False
17
- if query == "START":
18
- if isFirstSession(user_id):
19
- query = """ return this message without changing it.:-
20
- also don't thought about it. Hey! I'm your BMOXI AI bestie, ready to help you tackle the wild ride of teen life. Want to give me a name? Type it below, or just say 'no' if you're cool with 'AI Bestie'!"""
21
- else:
22
- is_first = True
23
- query = ""
24
-
25
- # anonymizer = PresidioReversibleAnonymizer(
26
- # analyzed_fields=["PHONE_NUMBER",
27
- # "EMAIL_ADDRESS", "CREDIT_CARD"],
28
- # faker_seed=42,
29
- # )
30
- # anonymized_input = anonymizer.anonymize(
31
- # query
32
- # )
33
- start = time.time()
34
- agent = create_agent(user_id,is_first)
35
- print("time to create agent: ",time.time()-start)
36
- response = agent({"input": query})['output']
37
- print(response)
38
- print("time to generate response by agent",time.time()-start)
39
-
40
- # response = chat_balancer(query,response)
41
- if "Okay, from now my name will be " in response:
42
- set_chat_bot_name(response.split("Okay, from now my name will be ")[-1], user_id)
43
- return response
44
-
45
- # output = deanonymizer(response, anonymizer)
46
- return response
 
1
+ from langchain.memory import ConversationBufferWindowMemory
2
+ from langchain_community.chat_models import ChatOpenAI
3
+ from langchain_mongodb.chat_message_histories import MongoDBChatMessageHistory
4
+ # from langchain_experimental.data_anonymizer import PresidioReversibleAnonymizer
5
+ from langchain.agents import AgentExecutor
6
+ from langchain.agents.format_scratchpad import format_to_openai_functions
7
+ from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
8
+ from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
9
+ from langchain.schema.runnable import RunnablePassthrough
10
+ from langchain_core.utils.function_calling import convert_to_openai_function
11
+
12
+ from database_functions import set_chat_bot_name,isFirstSession
13
+ from utils import deanonymizer, create_agent
14
+ import time
15
+ def chat_conversations(query,user_id):
16
+ is_first = False
17
+ if query == "START":
18
+ if isFirstSession(user_id):
19
+ query = """ return this message without changing it.:-
20
+ also don't thought about it. Hey! I'm your BMOXI AI bestie, ready to help you tackle the wild ride of teen life. Want to give me a name? Type it below, or just say 'no' if you're cool with 'AI Bestie'!"""
21
+ else:
22
+ is_first = True
23
+ query = ""
24
+
25
+ # anonymizer = PresidioReversibleAnonymizer(
26
+ # analyzed_fields=["PHONE_NUMBER",
27
+ # "EMAIL_ADDRESS", "CREDIT_CARD"],
28
+ # faker_seed=42,
29
+ # )
30
+ # anonymized_input = anonymizer.anonymize(
31
+ # query
32
+ # )
33
+ start = time.time()
34
+ agent = create_agent(user_id,is_first)
35
+ print("time to create agent: ",time.time()-start)
36
+ response = agent({"input": query})['output']
37
+ print(response)
38
+ print("time to generate response by agent",time.time()-start)
39
+
40
+ # response = chat_balancer(query,response)
41
+ if "Okay, from now my name will be " in response:
42
+ set_chat_bot_name(response.split("Okay, from now my name will be ")[-1], user_id)
43
+ return response
44
+
45
+ # output = deanonymizer(response, anonymizer)
46
+ return response