Spaces:
Runtime error
Runtime error
File size: 2,124 Bytes
8b79aed 5039b99 8b79aed 5039b99 8b79aed 26f32ee 8b79aed 26f32ee 5039b99 26f32ee 5039b99 8b79aed 26f32ee 8b79aed 5039b99 8b79aed 5039b99 8b79aed 5039b99 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
from langchain.memory import ConversationBufferWindowMemory
from langchain_community.chat_models import ChatOpenAI
from langchain_mongodb.chat_message_histories import MongoDBChatMessageHistory
# from langchain_experimental.data_anonymizer import PresidioReversibleAnonymizer
from langchain.agents import AgentExecutor
from langchain.agents.format_scratchpad import format_to_openai_functions
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain.schema.runnable import RunnablePassthrough
from langchain_core.utils.function_calling import convert_to_openai_function
from database_functions import set_chat_bot_name,isFirstSession
from utils import deanonymizer, create_agent,chat_balancer
import time
def chat_conversations(query,user_id):
is_first = False
if query == "START":
if isFirstSession(user_id):
query = """ return this message without changing it.:-
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'!"""
else:
is_first = True
query = ""
# anonymizer = PresidioReversibleAnonymizer(
# analyzed_fields=["PHONE_NUMBER",
# "EMAIL_ADDRESS", "CREDIT_CARD"],
# faker_seed=42,
# )
# anonymized_input = anonymizer.anonymize(
# query
# )
start = time.time()
agent = create_agent(user_id,is_first)
print("time to create agent: ",time.time()-start)
response = agent({"input": query})['output']
print(response)
print("time to generate response by agent",time.time()-start)
# response = chat_balancer(query,response)
if "Okay, from now my name will be " in response:
set_chat_bot_name(response.split("Okay, from now my name will be ")[-1], user_id)
return response
# output = deanonymizer(response, anonymizer)
return response
|