Update main.py
Browse files
main.py
CHANGED
@@ -186,25 +186,29 @@ def Generation_completion(client, data, question):
|
|
186 |
@traceable(run_type="chain", name="Mistral Assistant des datas Gustaviz",)
|
187 |
async def Affichage_reponse(response, question, data):
|
188 |
memory = cl.user_session.get("memory")
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
192 |
# time.sleep(0.125)
|
193 |
-
# await
|
|
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
msg = GoogleTranslator(source='auto', target='fr').translate(msg[0:4999])
|
198 |
-
msgList = msg.split(' ')
|
199 |
-
for chunk in msgList:
|
200 |
-
time.sleep(0.125)
|
201 |
-
await result.stream_token(chunk + ' ')
|
202 |
-
|
203 |
-
await result.send()
|
204 |
memory.chat_memory.add_user_message(question)
|
205 |
-
memory.chat_memory.add_ai_message(
|
206 |
|
207 |
-
return
|
208 |
|
209 |
@cl.step(type="tool", show_input=True)
|
210 |
async def Affichage_question_contexte(answer, question, contexte):
|
|
|
186 |
@traceable(run_type="chain", name="Mistral Assistant des datas Gustaviz",)
|
187 |
async def Affichage_reponse(response, question, data):
|
188 |
memory = cl.user_session.get("memory")
|
189 |
+
msg = cl.Message(author="COPILOT",content="")
|
190 |
+
async for chunk in response.astream({"question": question, "data": data},config=RunnableConfig(callbacks=[cl.AsyncLangchainCallbackHandler(stream_final_answer=True)])):
|
191 |
+
time.sleep(0.125)
|
192 |
+
await msg.stream_token(chunk.replace('Ã','é').replace('©','').replace('Ã','è').replace('¨','').replace('â','\'').replace('€','').replace('™','').replace('Å','oe').replace('“','').replace('®','î').replace('´','ô').replace('<','').replace('>','').replace('/',''))
|
193 |
+
|
194 |
+
answer = msg.content
|
195 |
|
196 |
+
#### Avec Traduction #####
|
197 |
+
#msg = response.invoke({"question": question, "data": data})
|
198 |
+
#msg = msg.replace('Ã','é').replace('©','').replace('Ã','è').replace('¨','').replace('â','\'').replace('€','').replace('™','').replace('Å','oe').replace('“','').replace('®','î').replace('´','ô').replace('<','').replace('>','').replace('/','')
|
199 |
+
#msg = GoogleTranslator(source='auto', target='fr').translate(msg[0:4999])
|
200 |
+
#msgList = msg.split(' ')
|
201 |
+
#for chunk in msgList:
|
202 |
# time.sleep(0.125)
|
203 |
+
# await result.stream_token(chunk + ' ')
|
204 |
+
#### Avec Traduction #####
|
205 |
|
206 |
+
|
207 |
+
await msg.send()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
memory.chat_memory.add_user_message(question)
|
209 |
+
memory.chat_memory.add_ai_message(answer)
|
210 |
|
211 |
+
return answer
|
212 |
|
213 |
@cl.step(type="tool", show_input=True)
|
214 |
async def Affichage_question_contexte(answer, question, contexte):
|