Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,16 @@ from langchain.tools.base import StructuredTool
|
|
10 |
from langchain.agents import initialize_agent
|
11 |
from qa_txt import llm
|
12 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def faq(query: str) -> str:
|
15 |
reponse = conversation_chain({"question": query, "chat_history": []})
|
@@ -29,7 +39,7 @@ qa_faq = StructuredTool.from_function(
|
|
29 |
)
|
30 |
|
31 |
def request_data(query: str) -> str:
|
32 |
-
request = chain.
|
33 |
mot_cle = nettoyer_string(request)
|
34 |
mots = mot_cle.split()
|
35 |
ui = mots[0]
|
@@ -58,17 +68,18 @@ tools_add = [
|
|
58 |
fetch_data,
|
59 |
]
|
60 |
|
61 |
-
agent =
|
62 |
-
|
63 |
-
|
64 |
-
agent
|
65 |
-
|
|
|
66 |
)
|
67 |
|
68 |
def data_gov_ma(message, history):
|
69 |
try:
|
70 |
-
response =
|
71 |
-
return response
|
72 |
except ValueError as e:
|
73 |
return "Je suis désolé, je n'ai pas compris votre question. Pourriez-vous la reformuler s'il vous plaît ?"
|
74 |
|
|
|
10 |
from langchain.agents import initialize_agent
|
11 |
from qa_txt import llm
|
12 |
import gradio as gr
|
13 |
+
from langchain.agents import (
|
14 |
+
create_react_agent,
|
15 |
+
AgentExecutor,
|
16 |
+
tool,
|
17 |
+
)
|
18 |
+
from langchain import hub
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
prompt = hub.pull("hwchase17/react")
|
23 |
|
24 |
def faq(query: str) -> str:
|
25 |
reponse = conversation_chain({"question": query, "chat_history": []})
|
|
|
39 |
)
|
40 |
|
41 |
def request_data(query: str) -> str:
|
42 |
+
request = chain.invoke({"input": query})['text']
|
43 |
mot_cle = nettoyer_string(request)
|
44 |
mots = mot_cle.split()
|
45 |
ui = mots[0]
|
|
|
68 |
fetch_data,
|
69 |
]
|
70 |
|
71 |
+
agent = create_react_agent(llm=llm, tools=tools_add, prompt=prompt)
|
72 |
+
|
73 |
+
agent_executor = AgentExecutor(
|
74 |
+
agent=agent,
|
75 |
+
tools=tools_add,
|
76 |
+
verbose=True,
|
77 |
)
|
78 |
|
79 |
def data_gov_ma(message, history):
|
80 |
try:
|
81 |
+
response = agent_executor.invoke({"input": message})
|
82 |
+
return response['output']
|
83 |
except ValueError as e:
|
84 |
return "Je suis désolé, je n'ai pas compris votre question. Pourriez-vous la reformuler s'il vous plaît ?"
|
85 |
|