tferhan commited on
Commit
2bdb6e7
·
verified ·
1 Parent(s): 6350f37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -9,6 +9,7 @@ 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
  import gradio as gr
13
  from langchain.agents import (
14
  create_react_agent,
@@ -28,13 +29,13 @@ def faq(query: str) -> str:
28
  qa_faq = StructuredTool.from_function(
29
  func = faq ,
30
  description="""
31
- Respond to general questions about the website like the documentation, contact, utility, support... Don't use it when the user request data about a subject (economie, justice, water, or any type of public dataset) only for contact or useful links data. Used also for translating other languages in french.
32
 
33
  Parameters :
34
  - query (string) : the same input as the user input no more no less and dont translate it even if it is in another language.
35
 
36
  Returns :
37
- - string : the output as returned from the function in the language of the input if it is in french respond in french, if it is in arabic respond in arabic... just for general questions but for the translation the output must be in french .
38
  """
39
  )
40
 
@@ -62,9 +63,26 @@ fetch_data = StructuredTool.from_function(
62
  """,
63
  )
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  tools_add = [
66
  qa_faq,
67
  fetch_data,
 
68
  ]
69
 
70
  agent = create_react_agent(llm=llm, tools=tools_add, prompt=prompt)
 
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 gradio as gr
14
  from langchain.agents import (
15
  create_react_agent,
 
29
  qa_faq = StructuredTool.from_function(
30
  func = faq ,
31
  description="""
32
+ Respond to general questions about the website like the documentation, contact, utility, support... Don't use it when the user request data about a subject (economie, justice, water, or any type of public dataset) only for contact or useful links data.
33
 
34
  Parameters :
35
  - query (string) : the same input as the user input no more no less and dont translate it even if it is in another language.
36
 
37
  Returns :
38
+ - string : the output as returned from the function in the language of the input if it is in french respond in french, if it is in arabic respond in arabic...
39
  """
40
  )
41
 
 
63
  """,
64
  )
65
 
66
+ def translate(query: str) -> str:
67
+ translated = trans.invoke({"input": query})['text']
68
+ return translated
69
+
70
+ translate_text = StructuredTool.from_function(
71
+ func=translate,
72
+ description= """
73
+ Translate from any language to french.
74
+
75
+ Parameters :
76
+ - query (string) : the same input as the user input no more no less.
77
+ Returns :
78
+ - string : isolate just the translated text in french with no other useless words.
79
+ """,
80
+ )
81
+
82
  tools_add = [
83
  qa_faq,
84
  fetch_data,
85
+ translate_text,
86
  ]
87
 
88
  agent = create_react_agent(llm=llm, tools=tools_add, prompt=prompt)