Update main.py
Browse files
main.py
CHANGED
@@ -21,6 +21,7 @@ from deep_translator import GoogleTranslator
|
|
21 |
from IPython.display import display
|
22 |
|
23 |
from surveycaa import surveyCaa
|
|
|
24 |
|
25 |
@cl.password_auth_callback
|
26 |
def auth_callback(username: str, password: str):
|
@@ -39,27 +40,6 @@ 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).
|
45 |
-
|
46 |
-
Args:
|
47 |
-
filename: The path to the CSV file that contains the data.
|
48 |
-
|
49 |
-
Returns:
|
50 |
-
An agent that can access and use the LLM.
|
51 |
-
"""
|
52 |
-
|
53 |
-
# Create an OpenAI object.
|
54 |
-
os.environ['OPENAI_API_KEY'] = os.environ['OPENAI_API_KEY']
|
55 |
-
llm = ChatOpenAI(temperature=0, model="gpt-4o-2024-05-13")
|
56 |
-
|
57 |
-
# Read the CSV file into a Pandas DataFrame.
|
58 |
-
df = pd.read_csv(filename)
|
59 |
-
|
60 |
-
# Create a Pandas DataFrame agent.
|
61 |
-
return create_csv_agent(llm, filename, verbose=False, allow_dangerous_code=True, handle_parsing_errors=True, agent_type=AgentType.OPENAI_FUNCTIONS)
|
62 |
-
|
63 |
def query_agent(agent, query):
|
64 |
"""
|
65 |
Query an agent and return the response as a string.
|
@@ -173,26 +153,4 @@ async def on_chat_start():
|
|
173 |
@cl.on_message
|
174 |
async def on_message(message: cl.Message):
|
175 |
await cl.Message(f"> SURVEYIA").send()
|
176 |
-
|
177 |
-
cb = cl.AsyncLangchainCallbackHandler()
|
178 |
-
try:
|
179 |
-
res = await agent.acall("Réponds en langue française à la question suivante : " + message.content, callbacks=[cb])
|
180 |
-
await cl.Message(author="COPILOT",content=GoogleTranslator(source='auto', target='fr').translate(res['output'])).send()
|
181 |
-
except ValueError as e:
|
182 |
-
res = str(e)
|
183 |
-
resArray = res.split(":")
|
184 |
-
ans = ''
|
185 |
-
if str(res).find('parsing') != -1:
|
186 |
-
for i in range(2,len(resArray)):
|
187 |
-
ans += resArray[i]
|
188 |
-
await cl.Message(author="COPILOT",content=ans.replace("`","")).send()
|
189 |
-
else:
|
190 |
-
await cl.Message(author="COPILOT",content="Reformulez votre requête, s'il vous plait 😃").send()
|
191 |
-
# Query the agent.
|
192 |
-
#response = query_agent(agent=agent, query=message.content)
|
193 |
-
# Decode the response.
|
194 |
-
#decoded_response = decode_response(response)
|
195 |
-
|
196 |
-
# Write the response to the Streamlit app.
|
197 |
-
#result = write_response(decoded_response)
|
198 |
-
#await cl.Message(author="COPILOT",content=GoogleTranslator(source='auto', target='fr').translate(result)).send()
|
|
|
21 |
from IPython.display import display
|
22 |
|
23 |
from surveycaa import surveyCaa
|
24 |
+
from csvanswer import LLMAnswer
|
25 |
|
26 |
@cl.password_auth_callback
|
27 |
def auth_callback(username: str, password: str):
|
|
|
40 |
identifier=ident + " : 🧑🎓 User Datapcc", metadata={"role": "user", "provider": "credentials"}
|
41 |
)
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
def query_agent(agent, query):
|
44 |
"""
|
45 |
Query an agent and return the response as a string.
|
|
|
153 |
@cl.on_message
|
154 |
async def on_message(message: cl.Message):
|
155 |
await cl.Message(f"> SURVEYIA").send()
|
156 |
+
await LLMAnswer()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|