bupa1018 commited on
Commit
9237abc
·
verified ·
1 Parent(s): b8bd331

Update kadiApy_ragchain.py

Browse files
Files changed (1) hide show
  1. kadiApy_ragchain.py +46 -11
kadiApy_ragchain.py CHANGED
@@ -25,9 +25,9 @@ class KadiApyRagchain:
25
 
26
  # Retrieve contexts
27
  print("Start retrieving:")
28
- doc_contexts = self.retrieve_contexts(query, k=2, filter={"dataset_category": "kadi_apy_docs"})
29
- code_contexts = self.retrieve_contexts(rewritten_query, k=3, filter={"usage": code_library_usage_prediction})
30
-
31
 
32
  # Vanilla
33
  #doc_contexts = self.retrieve_contexts(query, k=3, filter={"dataset_category": "kadi_apy_docs"})
@@ -134,7 +134,44 @@ class KadiApyRagchain:
134
  context = self.vector_store.similarity_search(query = query, k=k, filter=filter)
135
  return context
136
 
137
- def generate_response(self, query, chat_history, doc_context, code_context):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  """
139
  Generate a response using the retrieved contexts and the LLM.
140
  """
@@ -144,8 +181,8 @@ class KadiApyRagchain:
144
  prompt = f"""
145
  You are a Python programming assistant specialized in the "Kadi-APY" library.
146
  The "Kadi-APY" library is a Python package designed to facilitate interaction with the REST-like API of a software platform called Kadi4Mat.
147
- Your task is to answer the user's query based on the guidelines, and if needed, combine understanding provided by
148
- "Document Snippets" with the implementation details provided by "Code Snippets."
149
 
150
  Guidelines if generating code:
151
  - Display the complete code first, followed by a concise explanation in no more than 5 sentences.
@@ -159,17 +196,15 @@ class KadiApyRagchain:
159
  Chat History:
160
  {formatted_history}
161
 
162
- Document Snippets:
163
- {doc_context}
164
-
165
- Code Snippets:
166
- {code_context}
167
 
168
  Query:
169
  {query}
170
  """
171
  return self.llm.invoke(prompt).content
172
 
 
173
 
174
  def format_documents(self, documents):
175
  formatted_docs = []
 
25
 
26
  # Retrieve contexts
27
  print("Start retrieving:")
28
+ #doc_contexts = self.retrieve_contexts(query, k=2, filter={"dataset_category": "kadi_apy_docs"})
29
+ #code_contexts = self.retrieve_contexts(rewritten_query, k=3, filter={"usage": code_library_usage_prediction})
30
+ context = self.retrieve_contexts(query, k=5)
31
 
32
  # Vanilla
33
  #doc_contexts = self.retrieve_contexts(query, k=3, filter={"dataset_category": "kadi_apy_docs"})
 
134
  context = self.vector_store.similarity_search(query = query, k=k, filter=filter)
135
  return context
136
 
137
+ # def generate_response(self, query, chat_history, doc_context, code_context):
138
+ # """
139
+ # Generate a response using the retrieved contexts and the LLM.
140
+ # """
141
+ # formatted_history = self.format_history(chat_history)
142
+
143
+ # # Update the prompt with history included
144
+ # prompt = f"""
145
+ # You are a Python programming assistant specialized in the "Kadi-APY" library.
146
+ # The "Kadi-APY" library is a Python package designed to facilitate interaction with the REST-like API of a software platform called Kadi4Mat.
147
+ # Your task is to answer the user's query based on the guidelines, and if needed, combine understanding provided by
148
+ # "Document Snippets" with the implementation details provided by "Code Snippets."
149
+
150
+ # Guidelines if generating code:
151
+ # - Display the complete code first, followed by a concise explanation in no more than 5 sentences.
152
+
153
+ # General Guidelines:
154
+ # - Refer to the "Chat History" if it provides context that could enhance your understanding of the user's query.
155
+ # - Always include the "Chat History" if relevant to the user's query for continuity and clarity in responses.
156
+ # - If the user's query cannot be fulfilled based on the provided snippets, reply with "The API does not support the requested functionality."
157
+ # - If the user's query does not implicate any task, reply with a question asking the user to elaborate.
158
+
159
+ # Chat History:
160
+ # {formatted_history}
161
+
162
+ # Document Snippets:
163
+ # {doc_context}
164
+
165
+ # Code Snippets:
166
+ # {code_context}
167
+
168
+ # Query:
169
+ # {query}
170
+ # """
171
+ # return self.llm.invoke(prompt).content
172
+
173
+
174
+ def generate_response(self, query, chat_history, context):
175
  """
176
  Generate a response using the retrieved contexts and the LLM.
177
  """
 
181
  prompt = f"""
182
  You are a Python programming assistant specialized in the "Kadi-APY" library.
183
  The "Kadi-APY" library is a Python package designed to facilitate interaction with the REST-like API of a software platform called Kadi4Mat.
184
+ Your task is to answer the user's query based on the guidelines, and if needed, combine understanding provided by "Context"
185
+ "Context" contains snippets from the source code and/or code examples
186
 
187
  Guidelines if generating code:
188
  - Display the complete code first, followed by a concise explanation in no more than 5 sentences.
 
196
  Chat History:
197
  {formatted_history}
198
 
199
+ Context:
200
+ {context}
 
 
 
201
 
202
  Query:
203
  {query}
204
  """
205
  return self.llm.invoke(prompt).content
206
 
207
+
208
 
209
  def format_documents(self, documents):
210
  formatted_docs = []