adrien.aribaut-gaudin commited on
Commit
7352d7a
·
1 Parent(s): 2f14157

fix: language answer from bot

Browse files
database/4a5944a6-5c35-44f8-88be-78ce2e35028c/data_level0.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d3c9fd302f000d7790aa403c2d0d8fec363fe46f30b07d53020b6e33b22435a9
3
  size 1676000
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:438a50d5e22300bf69cf65a069fdab5d99af120fa635fa9444d3ae52ffcf23d1
3
  size 1676000
database/4a5944a6-5c35-44f8-88be-78ce2e35028c/length.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5b8e0bc4024bd2c60f910c5ea628a6b78cab039442c2c1e1576985ca11d8ab69
3
  size 4000
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40616716b33e9e16756c831d8097b709a29c0c3b0c182e61ed8516183883b5c3
3
  size 4000
src/control/control.py CHANGED
@@ -12,8 +12,8 @@ class Chatbot:
12
 
13
  def get_response(self, query, histo):
14
  histo_conversation, histo_queries = self._get_histo(histo)
15
- langage_of_query = self.llm.detect_language(query)
16
- queries = self.llm.translate(text=histo_queries) if langage_of_query.lower() == 'fr' else histo_queries
17
  block_sources = self.retriever.similarity_search(query=queries)
18
  block_sources = self._select_best_sources(block_sources)
19
  sources_contents = [s.content for s in block_sources]
 
12
 
13
  def get_response(self, query, histo):
14
  histo_conversation, histo_queries = self._get_histo(histo)
15
+ langage_of_query = self.llm.detect_language(query).lower()
16
+ queries = self.llm.translate(text=histo_queries)
17
  block_sources = self.retriever.similarity_search(query=queries)
18
  block_sources = self._select_best_sources(block_sources)
19
  sources_contents = [s.content for s in block_sources]
src/tools/llm.py CHANGED
@@ -10,16 +10,16 @@ class LlmAgent:
10
  f"\\n ``` {query} ```\\n"
11
  f"Your answer is based on the context delimited by triple backticks: "
12
  f"\\n ``` {context} ```\\n"
13
- f"You are consistent and avoid redundancies with the rest of the initial conversation"
14
  f"delimited by triple backticks: "
15
  f"\\n ``` {histo} ```\\n"
16
  f"Your response shall be in {language} and shall be concise")
17
 
18
  p = self.llm(template)
19
- print("****************")
20
- print(template)
21
- print("----")
22
- print(p)
23
  return p
24
 
25
  def translate(self, text: str, language="en") -> str:
@@ -27,20 +27,20 @@ class LlmAgent:
27
 
28
  languages = "`French to English" if language == "en" else "English to French"
29
 
30
- template = (f" Your task consists in translating {languages}\\n"
31
  f" the following text delimited by by triple backticks: ```{text}```\n"
32
  )
33
 
34
  p = self.llm(template)
35
  return p
36
 
37
- def generate_answer(self, query: str, answer: str, histo: str, context: str, language: str) -> str:
38
- """provides the final answer based on the initial query and the answer"""
39
 
40
  def _cut_unfinished_sentence(s: str):
41
  return '.'.join(s.split('.')[:-1])
42
 
43
- template = (f"Your task consists in answering to the query from users in {language} "
44
  f"delimited by triple backticks: ```{query}``` \\n"
45
  f"You are given the answer in {language} delimited by triple backticks: ```{answer}```"
46
  f"\\n You don't add new content to the answer but: "
@@ -48,7 +48,6 @@ class LlmAgent:
48
  f"```{context}```"
49
  f"\\n 2 You are consistent and avoid redundancies with the rest of the initial"
50
  f" conversation delimited by triple backticks: ```{histo}```"
51
- f" If the langage of the answer is the same as the langage of the query, you shall be concise but keep the meaning of the answer"
52
  )
53
 
54
  p = self.llm(template)
@@ -59,7 +58,7 @@ class LlmAgent:
59
  """detects the language"""
60
  template = (f"Your task consists in detecting the language of the following text delimited by triple backticks: "
61
  f"```{text}```"
62
- f"Your answer shall be the two letters code of the language"
63
  )
64
  p = self.llm(template)
65
  return p
 
10
  f"\\n ``` {query} ```\\n"
11
  f"Your answer is based on the context delimited by triple backticks: "
12
  f"\\n ``` {context} ```\\n"
13
+ f" You are consistent and avoid redundancies with the rest of the initial conversation "
14
  f"delimited by triple backticks: "
15
  f"\\n ``` {histo} ```\\n"
16
  f"Your response shall be in {language} and shall be concise")
17
 
18
  p = self.llm(template)
19
+ # print("****************")
20
+ # print(template)
21
+ # print("----")
22
+ # print(p)
23
  return p
24
 
25
  def translate(self, text: str, language="en") -> str:
 
27
 
28
  languages = "`French to English" if language == "en" else "English to French"
29
 
30
+ template = (f" Your task consists in translating in English\\n"
31
  f" the following text delimited by by triple backticks: ```{text}```\n"
32
  )
33
 
34
  p = self.llm(template)
35
  return p
36
 
37
+ def generate_answer(self, query: str, answer: str, histo: str, context: str,language : str) -> str:
38
+ """provides the final answer in French based on the initial query and the answer in english"""
39
 
40
  def _cut_unfinished_sentence(s: str):
41
  return '.'.join(s.split('.')[:-1])
42
 
43
+ template = (f"Your task consists in translating the answer in {language}, if its not already the case, to the query "
44
  f"delimited by triple backticks: ```{query}``` \\n"
45
  f"You are given the answer in {language} delimited by triple backticks: ```{answer}```"
46
  f"\\n You don't add new content to the answer but: "
 
48
  f"```{context}```"
49
  f"\\n 2 You are consistent and avoid redundancies with the rest of the initial"
50
  f" conversation delimited by triple backticks: ```{histo}```"
 
51
  )
52
 
53
  p = self.llm(template)
 
58
  """detects the language"""
59
  template = (f"Your task consists in detecting the language of the following text delimited by triple backticks: "
60
  f"```{text}```"
61
+ f" Your answer shall be the two letters code of the language"
62
  )
63
  p = self.llm(template)
64
  return p