Update main.py
Browse files
main.py
CHANGED
@@ -20,6 +20,10 @@ from chainlit.input_widget import TextInput, Select, Switch, Slider
|
|
20 |
from deep_translator import GoogleTranslator
|
21 |
from IPython.display import display
|
22 |
|
|
|
|
|
|
|
|
|
23 |
from surveycaa import surveyCaa
|
24 |
|
25 |
@cl.password_auth_callback
|
@@ -39,6 +43,7 @@ def auth_callback(username: str, password: str):
|
|
39 |
identifier=ident + " : 🧑🎓 User Datapcc", metadata={"role": "user", "provider": "credentials"}
|
40 |
)
|
41 |
|
|
|
42 |
def create_agent(filename: str):
|
43 |
"""
|
44 |
Create an agent that can access and use a large language model (LLM).
|
@@ -173,23 +178,24 @@ async def on_chat_start():
|
|
173 |
|
174 |
@cl.on_message
|
175 |
async def on_message(message: cl.Message):
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
193 |
# Query the agent.
|
194 |
#response = query_agent(agent=agent, query=message.content)
|
195 |
# Decode the response.
|
|
|
20 |
from deep_translator import GoogleTranslator
|
21 |
from IPython.display import display
|
22 |
|
23 |
+
from literalai import LiteralClient
|
24 |
+
literal_client = LiteralClient(api_key=os.getenv("LITERAL_API_KEY"))
|
25 |
+
literal_client.instrument_openai()
|
26 |
+
|
27 |
from surveycaa import surveyCaa
|
28 |
|
29 |
@cl.password_auth_callback
|
|
|
43 |
identifier=ident + " : 🧑🎓 User Datapcc", metadata={"role": "user", "provider": "credentials"}
|
44 |
)
|
45 |
|
46 |
+
@literal_client.step(type="tool")
|
47 |
def create_agent(filename: str):
|
48 |
"""
|
49 |
Create an agent that can access and use a large language model (LLM).
|
|
|
178 |
|
179 |
@cl.on_message
|
180 |
async def on_message(message: cl.Message):
|
181 |
+
async with cl.Step(root=True, name="Réponse de l'Agent CSV", type="llm") as parent_step:
|
182 |
+
await cl.Message(f"> SURVEYIA").send()
|
183 |
+
agent = create_agent("./public/surveyia.csv")
|
184 |
+
cb = cl.AsyncLangchainCallbackHandler()
|
185 |
+
try:
|
186 |
+
#res = await agent.acall("Réponds en langue française à la question suivante : " + message.content, callbacks=[cb])
|
187 |
+
res = await agent.ainvoke("Réponds de la manière la plus complète et la plus intelligible, en langue française, à la question suivante : " + message.content + ". Réponds au format markdown ou au format tableau si le résultat nécessite l'affichage d'un tableau.")
|
188 |
+
await cl.Message(author="COPILOT",content=GoogleTranslator(source='auto', target='fr').translate(res['output'])).send()
|
189 |
+
except ValueError as e:
|
190 |
+
res = str(e)
|
191 |
+
resArray = res.split(":")
|
192 |
+
ans = ''
|
193 |
+
if str(res).find('parsing') != -1:
|
194 |
+
for i in range(2,len(resArray)):
|
195 |
+
ans += resArray[i]
|
196 |
+
await cl.Message(author="COPILOT",content=ans.replace("`","")).send()
|
197 |
+
else:
|
198 |
+
await cl.Message(author="COPILOT",content="Reformulez votre requête, s'il vous plait 😃").send()
|
199 |
# Query the agent.
|
200 |
#response = query_agent(agent=agent, query=message.content)
|
201 |
# Decode the response.
|