tferhan commited on
Commit
1e7022c
·
verified ·
1 Parent(s): 139cc35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -24
app.py CHANGED
@@ -2,14 +2,14 @@ from langchain.prompts import StringPromptTemplate
2
  import re
3
  import langchain
4
  from qa_txt import conversation_chain
5
- from key_extract import chain
6
  from bs4 import BeautifulSoup
7
  import requests
8
  from data_process import *
9
  from langchain.tools.base import StructuredTool
10
  from langchain.agents import initialize_agent
11
  from qa_txt import llm
12
- from trans import trans
13
  import pathlib
14
  import gradio as gr
15
  from langchain.agents import (
@@ -40,10 +40,8 @@ qa_faq = StructuredTool.from_function(
40
  - string : the output as returned from the function in french.
41
  """
42
  )
43
-
44
  def request_data(query: str) -> str:
45
- request = chain.invoke({"input": query})
46
- mot_cle = nettoyer_string(request)
47
  mots = mot_cle.split()
48
  ui = mots[0]
49
  rg = chercher_data(ui)
@@ -51,40 +49,62 @@ def request_data(query: str) -> str:
51
  reponse_final = format_reponse(rg)
52
  return reponse_final
53
  else:
54
- return "Désolé, il semble que nous n'ayons pas de données correspondant à votre demande pour le moment. Avez-vous une autre question ou avez-vous besoin d'aide sur quelque chose d'autre?"
55
 
56
  fetch_data = StructuredTool.from_function(
57
  func=request_data,
58
  description="""
59
  Request and fetch data using a search keyword.
60
-
61
  Parameters :
62
  - 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".
63
  Returns :
64
  - string : the output as returned from the function in french , includes the link to all the data about the keyword along with an example.
65
  """,
66
  )
67
-
68
- def translate(query: str) -> str:
69
- translated = trans.invoke({"input": query})['text']
70
- return translated
71
-
72
- translate_text = StructuredTool.from_function(
73
- func=translate,
74
- description= """
75
- Translate from any language to french. Don't use it if the text is already in french
76
-
77
- Parameters :
78
- - query (string) : the same input as the user input no more no less.
79
- Returns :
80
- - string : isolate just the translated text in french with no other useless words.
81
- """,
82
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  tools_add = [
85
  qa_faq,
86
  fetch_data,
87
- translate_text,
88
  ]
89
 
90
  agent = create_react_agent(llm=llm, tools=tools_add, prompt=prompt)
 
2
  import re
3
  import langchain
4
  from qa_txt import conversation_chain
5
+ # from key_extract import chain
6
  from bs4 import BeautifulSoup
7
  import requests
8
  from data_process import *
9
  from langchain.tools.base import StructuredTool
10
  from langchain.agents import initialize_agent
11
  from qa_txt import llm
12
+ # from trans import trans
13
  import pathlib
14
  import gradio as gr
15
  from langchain.agents import (
 
40
  - string : the output as returned from the function in french.
41
  """
42
  )
 
43
  def request_data(query: str) -> str:
44
+ mot_cle = nettoyer_string(query)
 
45
  mots = mot_cle.split()
46
  ui = mots[0]
47
  rg = chercher_data(ui)
 
49
  reponse_final = format_reponse(rg)
50
  return reponse_final
51
  else:
52
+ return query + "salam"
53
 
54
  fetch_data = StructuredTool.from_function(
55
  func=request_data,
56
  description="""
57
  Request and fetch data using a search keyword.
 
58
  Parameters :
59
  - 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".
60
  Returns :
61
  - string : the output as returned from the function in french , includes the link to all the data about the keyword along with an example.
62
  """,
63
  )
64
+ # def request_data(query: str) -> str:
65
+ # request = chain.invoke({"input": query})
66
+ # mot_cle = nettoyer_string(request)
67
+ # mots = mot_cle.split()
68
+ # ui = mots[0]
69
+ # rg = chercher_data(ui)
70
+ # if len(rg[0]):
71
+ # reponse_final = format_reponse(rg)
72
+ # return reponse_final
73
+ # else:
74
+ # return "Désolé, il semble que nous n'ayons pas de données correspondant à votre demande pour le moment. Avez-vous une autre question ou avez-vous besoin d'aide sur quelque chose d'autre?"
75
+
76
+ # fetch_data = StructuredTool.from_function(
77
+ # func=request_data,
78
+ # description="""
79
+ # Request and fetch data using a search keyword.
80
+
81
+ # Parameters :
82
+ # - 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".
83
+ # Returns :
84
+ # - string : the output as returned from the function in french , includes the link to all the data about the keyword along with an example.
85
+ # """,
86
+ # )
87
+
88
+ # def translate(query: str) -> str:
89
+ # translated = trans.invoke({"input": query})['text']
90
+ # return translated
91
+
92
+ # translate_text = StructuredTool.from_function(
93
+ # func=translate,
94
+ # description= """
95
+ # Translate from any language to french. Don't use it if the text is already in french
96
+
97
+ # Parameters :
98
+ # - query (string) : the same input as the user input no more no less.
99
+ # Returns :
100
+ # - string : isolate just the translated text in french with no other useless words.
101
+ # """,
102
+ # )
103
 
104
  tools_add = [
105
  qa_faq,
106
  fetch_data,
107
+ # translate_text,
108
  ]
109
 
110
  agent = create_react_agent(llm=llm, tools=tools_add, prompt=prompt)