tferhan commited on
Commit
99d54fa
·
verified ·
1 Parent(s): 758412b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -20
app.py CHANGED
@@ -27,7 +27,7 @@ from gradio_client import Client
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})
@@ -49,11 +49,14 @@ qa_faq = StructuredTool.from_function(
49
  analyze_data = StructuredTool.from_function(
50
  func=get_data,
51
  description = """
52
- Analyze and summarize data from a given url asked by the user to summarize or analyze dont use it with the tool request_data .
53
  Parameters :
54
  - url (string) : the url given by the user.
55
  Returns :
56
  - string : A summary about the data extracted and some insights about it in french obligatory.
 
 
 
57
  """
58
  )
59
 
@@ -71,11 +74,20 @@ def request_data(query: str) -> str:
71
  fetch_data = StructuredTool.from_function(
72
  func=request_data,
73
  description="""
74
- Request and fetch data using a search keyword in french must be always converted in french for the website data.gov.ma and return the results without analyse them.
75
  Parameters :
76
- - query (string) : the same input as the user input no more no less and always it must be in french if it isn't already. For example : "give me data about health" the input is health in french which is santé, same for other languages and the words translatted must be nouns not adjectives or verbs also the user may request data about an organization where you need to take just the main subject for example "Je veux les données de l'agence de développement digitale" you take just "développement".
77
  Returns :
78
  - string : the output as returned from the function in french , includes the link to all the data about the keyword along with an example.
 
 
 
 
 
 
 
 
 
79
  """,
80
  )
81
  # def request_data(query: str) -> str:
@@ -120,27 +132,27 @@ fetch_data = StructuredTool.from_function(
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 and must be in french if not translate it in french
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,
@@ -149,7 +161,7 @@ tools_add = [
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,
 
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})
 
49
  analyze_data = StructuredTool.from_function(
50
  func=get_data,
51
  description = """
52
+ Analyze and summarize data from a given url asked by the user to summarize or analyze dont use it with the tool request_data and the user must write analyze before this function get executed .
53
  Parameters :
54
  - url (string) : the url given by the user.
55
  Returns :
56
  - string : A summary about the data extracted and some insights about it in french obligatory.
57
+ Example:
58
+ >>> analyse this data of this link : https://data.gov.ma/data/fr/dataset/evolution-des-affaires-au-cours-du-quinquennat-2018-2022
59
+ >>> input : https://data.gov.ma/data/fr/dataset/evolution-des-affaires-au-cours-du-quinquennat-2018-2022
60
  """
61
  )
62
 
 
74
  fetch_data = StructuredTool.from_function(
75
  func=request_data,
76
  description="""
77
+ Request and fetch data using a search keyword and return the results without analyse them.
78
  Parameters :
79
+ - query (string) : the same input as the user input no more no less and always it must be in french if it isn't already.Same for other languages and the words translatted must be nouns not adjectives or verbs also the user may request data about an organization where you need to take just the main subject for example "Je veux les données de l'agence de développement digitale" you take just "développement".
80
  Returns :
81
  - string : the output as returned from the function in french , includes the link to all the data about the keyword along with an example.
82
+ Examples:
83
+ >>> Give me data about water
84
+ >>> input : eau
85
+ >>> Give me data about ADD
86
+ >>> input : ADD
87
+ >>> Je veux les données culturelles
88
+ >>> input : culture
89
+ >>> Je veux les données de justice
90
+ >>> input : justice
91
  """,
92
  )
93
  # def request_data(query: str) -> str:
 
132
 
133
 
134
 
135
+ # template = '''Answer the following questions as best you can. You have access to the following tools:
136
 
137
+ # {tools}
138
 
139
+ # Use the following format:
140
 
141
+ # Question: the input question you must answer and must be in french if not translate it in french
142
+ # Thought: you should always think about what to do
143
+ # Action: the action to take, should be one of [{tool_names}]
144
+ # Action Input: the input to the action
145
+ # Observation: the result of the action, don't include /nObservation in the end of each observation just what you observed
146
+ # ... (this Thought/Action/Action Input/Observation can repeat N times)
147
+ # Thought: I now know the final answer
148
+ # Final Answer: the final answer to the original input question and must always be in french no matter what.
149
 
150
+ # Begin!
151
 
152
+ # Question: {input}
153
+ # Thought:{agent_scratchpad}'''
154
 
155
+ # prompt_2 = PromptTemplate.from_template(template)
156
 
157
  tools_add = [
158
  qa_faq,
 
161
  # translate_text,
162
  ]
163
 
164
+ agent = create_react_agent(llm=llm, tools=tools_add, prompt=prompt)
165
 
166
  agent_executor = AgentExecutor(
167
  agent=agent,