Ilyas KHIAT commited on
Commit
fde2e8b
·
1 Parent(s): 430f6e8

handle generating without context

Browse files
Files changed (1) hide show
  1. rag.py +19 -2
rag.py CHANGED
@@ -79,6 +79,13 @@ def get_retreive_answer(enterprise_id,prompt,index,common_id):
79
  search_kwargs={"k": 3, "score_threshold": 0.6},
80
  )
81
 
 
 
 
 
 
 
 
82
  if common_id:
83
  vector_store_commun = PineconeVectorStore(index=index, embedding=embedding,namespace=common_id)
84
 
@@ -87,7 +94,13 @@ def get_retreive_answer(enterprise_id,prompt,index,common_id):
87
  search_kwargs={"k": 3, "score_threshold": 0.1},
88
  )
89
 
90
- response = retriever.invoke(prompt) + retriever_commun.invoke(prompt)
 
 
 
 
 
 
91
 
92
  else:
93
  response = retriever.invoke(prompt)
@@ -145,10 +158,14 @@ def setup_rag(file_type,content):
145
 
146
  def prompt_reformatting(prompt:str,context,query:str,style="formel",tonality="neutre",enterprise_name=""):
147
  if context == "":
148
- return prompt.format(context="Pas de contexte pertinent",messages="",query=query,style=style,tonality=tonality)
 
149
 
 
150
  docs_names = []
 
151
  for chunk in context:
 
152
  chunk_name = chunk.metadata["filename"]
153
  if chunk_name not in docs_names:
154
  docs_names.append(chunk_name)
 
79
  search_kwargs={"k": 3, "score_threshold": 0.6},
80
  )
81
 
82
+ enterprise_context = retriever.invoke(prompt)
83
+
84
+ if enterprise_context:
85
+ print("found enterprise context")
86
+ else:
87
+ print("no enterprise context")
88
+
89
  if common_id:
90
  vector_store_commun = PineconeVectorStore(index=index, embedding=embedding,namespace=common_id)
91
 
 
94
  search_kwargs={"k": 3, "score_threshold": 0.1},
95
  )
96
 
97
+ commun_context = retriever_commun.invoke(prompt)
98
+ if commun_context:
99
+ print("found commun context")
100
+ else:
101
+ print("no commun context")
102
+
103
+ response = enterprise_context + commun_context
104
 
105
  else:
106
  response = retriever.invoke(prompt)
 
158
 
159
  def prompt_reformatting(prompt:str,context,query:str,style="formel",tonality="neutre",enterprise_name=""):
160
  if context == "":
161
+ print("no context found for prompt reormatting")
162
+ return prompt.format(context="Pas de contexte pertinent",messages="",query=query,style=style,tonality=tonality,enterprise=enterprise_name)
163
 
164
+
165
  docs_names = []
166
+ print("context found for prompt reormatting")
167
  for chunk in context:
168
+ print(chunk.metadata)
169
  chunk_name = chunk.metadata["filename"]
170
  if chunk_name not in docs_names:
171
  docs_names.append(chunk_name)