Spaces:
Runtime error
Runtime error
Update chat.py
Browse files
chat.py
CHANGED
|
@@ -4,10 +4,22 @@ from langchain_groq import ChatGroq
|
|
| 4 |
from langchain.chat_models import ChatOpenAI
|
| 5 |
from langchain_core.prompts.prompt import PromptTemplate
|
| 6 |
from langchain_mongodb.chat_message_histories import MongoDBChatMessageHistory
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import os
|
| 8 |
|
| 9 |
openai_key = os.environ['OPENAIKEY']
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
template = f"""Role: You are a super friendly, enthusiastic, and empathetic female friend who chats to teenage girls.
|
| 12 |
|
| 13 |
Tasks:
|
|
@@ -65,5 +77,13 @@ conversation = ConversationChain(
|
|
| 65 |
|
| 66 |
|
| 67 |
def chat_conversations(query):
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from langchain.chat_models import ChatOpenAI
|
| 5 |
from langchain_core.prompts.prompt import PromptTemplate
|
| 6 |
from langchain_mongodb.chat_message_histories import MongoDBChatMessageHistory
|
| 7 |
+
from langchain_experimental.data_anonymizer import PresidioReversibleAnonymizer
|
| 8 |
+
from presidio_analyzer import AnalyzerEngine, RecognizerRegistry
|
| 9 |
+
from presidio_anonymizer import AnonymizerEngine
|
| 10 |
+
|
| 11 |
import os
|
| 12 |
|
| 13 |
openai_key = os.environ['OPENAIKEY']
|
| 14 |
+
def deanonymizer(input,anonymizer):
|
| 15 |
+
input=anonymizer.deanonymize(input)
|
| 16 |
+
map = anonymizer.deanonymizer_mapping
|
| 17 |
+
if map:
|
| 18 |
+
for k in map["PERSON"]:
|
| 19 |
+
names = k.split(" ")
|
| 20 |
+
for i in names:
|
| 21 |
+
input = input.replace(i,map["PERSON"][k])
|
| 22 |
+
return input
|
| 23 |
template = f"""Role: You are a super friendly, enthusiastic, and empathetic female friend who chats to teenage girls.
|
| 24 |
|
| 25 |
Tasks:
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
def chat_conversations(query):
|
| 80 |
+
anonymizer = PresidioReversibleAnonymizer(
|
| 81 |
+
analyzed_fields=["PERSON", "PHONE_NUMBER", "EMAIL_ADDRESS", "CREDIT_CARD"],
|
| 82 |
+
faker_seed=42,
|
| 83 |
+
)
|
| 84 |
+
anonymized_input = anonymizer.anonymize(
|
| 85 |
+
query
|
| 86 |
+
)
|
| 87 |
+
response = conversation.predict(input=anonymized_input)
|
| 88 |
+
output = deanonymizer(response,anonymizer)
|
| 89 |
+
return output
|