Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from document_scrapped import get_data
|
|
| 4 |
import langchain
|
| 5 |
from qa_txt import conversation_chain
|
| 6 |
# from key_extract import chain
|
|
|
|
| 7 |
from bs4 import BeautifulSoup
|
| 8 |
import requests
|
| 9 |
from data_process import *
|
|
@@ -26,7 +27,7 @@ from gradio_client import Client
|
|
| 26 |
|
| 27 |
file_text = pathlib.Path('intents_v2.txt').read_text()
|
| 28 |
|
| 29 |
-
prompt = hub.pull("hwchase17/react")
|
| 30 |
|
| 31 |
def faq(query: str) -> str:
|
| 32 |
reponse = conversation_chain.invoke({"input": query, 'document': file_text})
|
|
@@ -56,7 +57,6 @@ analyze_data = StructuredTool.from_function(
|
|
| 56 |
"""
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
def request_data(query: str) -> str:
|
| 61 |
mot_cle = nettoyer_string(query)
|
| 62 |
mots = mot_cle.split()
|
|
@@ -118,6 +118,30 @@ fetch_data = StructuredTool.from_function(
|
|
| 118 |
# """,
|
| 119 |
# )
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
tools_add = [
|
| 122 |
qa_faq,
|
| 123 |
fetch_data,
|
|
@@ -125,13 +149,14 @@ tools_add = [
|
|
| 125 |
# translate_text,
|
| 126 |
]
|
| 127 |
|
| 128 |
-
agent = create_react_agent(llm=llm, tools=tools_add, prompt=
|
| 129 |
|
| 130 |
agent_executor = AgentExecutor(
|
| 131 |
agent=agent,
|
| 132 |
tools=tools_add,
|
| 133 |
verbose=True,
|
| 134 |
max_iterations = 10,
|
|
|
|
| 135 |
#max_execution_time = 45, optionel mais useful dans le deployement
|
| 136 |
|
| 137 |
)
|
|
|
|
| 4 |
import langchain
|
| 5 |
from qa_txt import conversation_chain
|
| 6 |
# from key_extract import chain
|
| 7 |
+
from langchain_core.prompts import PromptTemplate
|
| 8 |
from bs4 import BeautifulSoup
|
| 9 |
import requests
|
| 10 |
from data_process import *
|
|
|
|
| 27 |
|
| 28 |
file_text = pathlib.Path('intents_v2.txt').read_text()
|
| 29 |
|
| 30 |
+
#prompt = hub.pull("hwchase17/react")
|
| 31 |
|
| 32 |
def faq(query: str) -> str:
|
| 33 |
reponse = conversation_chain.invoke({"input": query, 'document': file_text})
|
|
|
|
| 57 |
"""
|
| 58 |
)
|
| 59 |
|
|
|
|
| 60 |
def request_data(query: str) -> str:
|
| 61 |
mot_cle = nettoyer_string(query)
|
| 62 |
mots = mot_cle.split()
|
|
|
|
| 118 |
# """,
|
| 119 |
# )
|
| 120 |
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
template = '''Answer the following questions as best you can. You have access to the following tools:
|
| 124 |
+
|
| 125 |
+
{tools}
|
| 126 |
+
|
| 127 |
+
Use the following format:
|
| 128 |
+
|
| 129 |
+
Question: the input question you must answer
|
| 130 |
+
Thought: you should always think about what to do
|
| 131 |
+
Action: the action to take, should be one of [{tool_names}]
|
| 132 |
+
Action Input: the input to the action
|
| 133 |
+
Observation: the result of the action, don't include /nObservation in the end of each observation just what you observed
|
| 134 |
+
... (this Thought/Action/Action Input/Observation can repeat N times)
|
| 135 |
+
Thought: I now know the final answer
|
| 136 |
+
Final Answer: the final answer to the original input question and must always be in french no matter what.
|
| 137 |
+
|
| 138 |
+
Begin!
|
| 139 |
+
|
| 140 |
+
Question: {input}
|
| 141 |
+
Thought:{agent_scratchpad}'''
|
| 142 |
+
|
| 143 |
+
prompt_2 = PromptTemplate.from_template(template)
|
| 144 |
+
|
| 145 |
tools_add = [
|
| 146 |
qa_faq,
|
| 147 |
fetch_data,
|
|
|
|
| 149 |
# translate_text,
|
| 150 |
]
|
| 151 |
|
| 152 |
+
agent = create_react_agent(llm=llm, tools=tools_add, prompt=prompt_2)
|
| 153 |
|
| 154 |
agent_executor = AgentExecutor(
|
| 155 |
agent=agent,
|
| 156 |
tools=tools_add,
|
| 157 |
verbose=True,
|
| 158 |
max_iterations = 10,
|
| 159 |
+
handle_parsing_errors=True,
|
| 160 |
#max_execution_time = 45, optionel mais useful dans le deployement
|
| 161 |
|
| 162 |
)
|