RCaz commited on
Commit
581b36a
·
1 Parent(s): 7db25b1

increased context to 20, updateed prompt in app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -151,11 +151,11 @@ def predict(message, history, request: gr.Request):
151
 
152
 
153
  # Retrieve relevant documents for the current message
154
- relevant_docs = vectorstore.similarity_search(message,k=6) # retriever
155
 
156
  # Build context from retrieved documents
157
  context = "\nExtracted documents:\n" + "\n".join([
158
- f"Content document {i}: {doc.page_content}\n\n---"
159
  for i, doc in enumerate(relevant_docs)
160
  ])
161
 
@@ -163,7 +163,7 @@ def predict(message, history, request: gr.Request):
163
 
164
  # RAG tool
165
  RAG_PROMPT_TEMPLATE="""You will be asked information related to Rémi Cazelles's specific projects, work and education.
166
- Using the information contained in the context, provide a comprehensive answer to the question.
167
  Respond to the question asked with enought details, response should be precise and relevant to the question.
168
  """
169
 
@@ -179,7 +179,7 @@ def predict(message, history, request: gr.Request):
179
  gpt_response = llm.invoke(
180
  messages,
181
  config={
182
- "tags": ["Testing", 'RAG-Bot', 'V1','Host_on_HF'],
183
  "metadata": {
184
  "rag_llm": "gpt-5-nano",
185
  "num_retrieved_docs": len(relevant_docs),
@@ -190,17 +190,9 @@ def predict(message, history, request: gr.Request):
190
  messages.append(AIMessage(content=gpt_response.content))
191
 
192
  try :
193
- raw_source_lines = [
194
- f"{i+1} : {format_source(doc)})\n---"
195
- for i, doc in enumerate(relevant_docs)]
196
-
197
- seen = set()
198
- unique_source_lines = []
199
- for line in raw_source_lines:
200
- if line not in seen:
201
- seen.add(line)
202
- unique_source_lines.append(line)
203
- source_context = "\nSources:" + "\n".join(unique_source_lines)
204
 
205
  except :
206
  source_context = "Issue extracting source"
 
151
 
152
 
153
  # Retrieve relevant documents for the current message
154
+ relevant_docs = vectorstore.similarity_search(message,k=20) # retriever
155
 
156
  # Build context from retrieved documents
157
  context = "\nExtracted documents:\n" + "\n".join([
158
+ f"Content document {i+1}: {doc.page_content}\n\n---"
159
  for i, doc in enumerate(relevant_docs)
160
  ])
161
 
 
163
 
164
  # RAG tool
165
  RAG_PROMPT_TEMPLATE="""You will be asked information related to Rémi Cazelles's specific projects, work and education.
166
+ Using the information contained in the context, provide a structured answer to the question.
167
  Respond to the question asked with enought details, response should be precise and relevant to the question.
168
  """
169
 
 
179
  gpt_response = llm.invoke(
180
  messages,
181
  config={
182
+ "tags": ["Testing", 'RAG-Bot', 'V2','Host_on_HF'],
183
  "metadata": {
184
  "rag_llm": "gpt-5-nano",
185
  "num_retrieved_docs": len(relevant_docs),
 
190
  messages.append(AIMessage(content=gpt_response.content))
191
 
192
  try :
193
+ source_context = "\n\nSources:\n" + "\n".join([
194
+ f"{i+1} - {format_source(doc)}"
195
+ for i, doc in enumerate(relevant_docs)])
 
 
 
 
 
 
 
 
196
 
197
  except :
198
  source_context = "Issue extracting source"