Spaces:
Sleeping
Sleeping
Update kadiApy_ragchain.py
Browse files- kadiApy_ragchain.py +2 -36
kadiApy_ragchain.py
CHANGED
@@ -31,8 +31,8 @@ class KadiApyRagchain:
|
|
31 |
#doc_contexts = self.retrieve_contexts(query, k=3, filter={"dataset_category": "kadi_apy_docs"})
|
32 |
#code_contexts = self.retrieve_contexts(query, k=5, filter={"dataset_category": "kadi_apy_source_code"})
|
33 |
|
34 |
-
|
35 |
-
|
36 |
|
37 |
|
38 |
# Format contexts
|
@@ -130,39 +130,6 @@ class KadiApyRagchain:
|
|
130 |
context = self.vector_store.similarity_search(query = query, k=k, filter=filter)
|
131 |
return context
|
132 |
|
133 |
-
# def generate_response(self, query, doc_context, code_context):
|
134 |
-
# """
|
135 |
-
# Generate a response using the retrieved contexts and the LLM.
|
136 |
-
# """
|
137 |
-
|
138 |
-
|
139 |
-
# prompt = f"""You are a Python programming assistant specialized in the "Kadi-APY" library.
|
140 |
-
# The "Kadi-APY" library is a Python package designed to facilitate interaction with the REST-like API of a software platform called Kadi4Mat.
|
141 |
-
# Your task is to answer the user's query based on the guidelines and if needed the combine understanding provided by
|
142 |
-
# "Document snippets" with the implementation details provided by "Code Snippets."
|
143 |
-
|
144 |
-
# Guidelines if generating code:
|
145 |
-
# - Display the complete code first, followed by a concise explanation in no more than 5 sentences.
|
146 |
-
|
147 |
-
# General Guideline:
|
148 |
-
# - If the user's query can not be fullfilled based on the provided snippets, reply with "The API does not support the requested functionality"
|
149 |
-
# - If the user's query does not implicate any task, reply with a question asking the user to elaborate.
|
150 |
-
|
151 |
-
# "Document Snippets": These contain documentation excerpts and code examples that explain how to use the "Kadi-APY" library
|
152 |
-
# Document Snippets:
|
153 |
-
# {doc_context}
|
154 |
-
|
155 |
-
|
156 |
-
# "Code Snippets": These are raw source code fragments from the implementation of the "Kadi-APY" library.
|
157 |
-
# Code Snippets:
|
158 |
-
# {code_context}
|
159 |
-
|
160 |
-
# Query:
|
161 |
-
# {query}
|
162 |
-
# """
|
163 |
-
# return self.llm.invoke(prompt).content
|
164 |
-
|
165 |
-
|
166 |
def generate_response(self, query, chat_history, doc_context, code_context):
|
167 |
"""
|
168 |
Generate a response using the retrieved contexts and the LLM.
|
@@ -203,7 +170,6 @@ class KadiApyRagchain:
|
|
203 |
|
204 |
def format_documents(self, documents):
|
205 |
formatted_docs = []
|
206 |
-
print("################################# start of doc #######################################")
|
207 |
for i, doc in enumerate(documents, start=1):
|
208 |
formatted_docs.append(f"Snippet {i}: \n")
|
209 |
formatted_docs.append("\n")
|
|
|
31 |
#doc_contexts = self.retrieve_contexts(query, k=3, filter={"dataset_category": "kadi_apy_docs"})
|
32 |
#code_contexts = self.retrieve_contexts(query, k=5, filter={"dataset_category": "kadi_apy_source_code"})
|
33 |
|
34 |
+
# doc_contexts = self.retrieve_contexts(query, k=3, filter={"dataset_category": "kadi_apy_docs"})
|
35 |
+
# code_contexts = self.retrieve_contexts(rewritten_query, k=5, filter={"dataset_category": "kadi_apy_source_code"})
|
36 |
|
37 |
|
38 |
# Format contexts
|
|
|
130 |
context = self.vector_store.similarity_search(query = query, k=k, filter=filter)
|
131 |
return context
|
132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
def generate_response(self, query, chat_history, doc_context, code_context):
|
134 |
"""
|
135 |
Generate a response using the retrieved contexts and the LLM.
|
|
|
170 |
|
171 |
def format_documents(self, documents):
|
172 |
formatted_docs = []
|
|
|
173 |
for i, doc in enumerate(documents, start=1):
|
174 |
formatted_docs.append(f"Snippet {i}: \n")
|
175 |
formatted_docs.append("\n")
|