Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -255,45 +255,11 @@ def setup_llm(model_name, temperature, api_key):
|
|
255 |
llm = ChatGroq(model=model_name, temperature=temperature, api_key=api_key)
|
256 |
return llm
|
257 |
|
258 |
-
def retrieve_from_vectorstore(vectorstore, query, k):
|
259 |
-
retrieved_docs = vectorstore.similarity_search(query, k=k)
|
260 |
-
return retrieved_docs
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
def retrieve_within_kadiApy_docs(vectorstore, query, k):
|
265 |
-
filter_criteria = {"usage": "doc"}
|
266 |
-
retrieved_docs = vectorstore.similarity_search(query=query, k=k, filter=filter_criteria)
|
267 |
-
return retrieved_docs
|
268 |
-
|
269 |
-
def retrieve_within_kadiApy_library(vectorstore, query, k):
|
270 |
-
filter_criteria = {"usage": "library"}
|
271 |
-
retrieved_docs = vectorstore.similarity_search(query=query, k=k, filter=filter_criteria)
|
272 |
-
return retrieved_docs
|
273 |
-
|
274 |
-
def retrieve_within_kadiApy_cli_library(vectorstore, query, k):
|
275 |
-
filter_criteria = {"usage": "cli_library"}
|
276 |
-
retrieved_docs = vectorstore.similarity_search(query=query, k=k, filter=filter_criteria)
|
277 |
-
return retrieved_docs
|
278 |
-
|
279 |
-
def retrieve_within_kadiApy_cli_library_excluding_cli_commands(vectorstore, query, k):
|
280 |
-
filter_criteria = {"usage": "cli_library"}
|
281 |
-
filtered_docs = [doc for doc in documents if "command" not in doc.metadata]
|
282 |
-
return filtered_docs
|
283 |
-
|
284 |
-
|
285 |
-
def retrieve_kadiApy_cli_commands(vectorstore, query, k):
|
286 |
-
filter_criteria = {"type": "command"}
|
287 |
-
results = vectorstore.similarity_search(query=query, k=k, filter=filter_criteria)
|
288 |
-
return results
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
def retrieve_docs_from_vectorstore(vectorstore, query, k):
|
293 |
-
return vectorstore.similarity_search(query, k=k)
|
294 |
|
295 |
|
296 |
|
|
|
|
|
297 |
|
298 |
def format_kadi_apy_library_context(docs):
|
299 |
doc_context = []
|
@@ -378,23 +344,30 @@ def rag_workflow(query):
|
|
378 |
|
379 |
rewritten_query_response = llm.invoke(rewrite_prompt)
|
380 |
rewritten_query = rewritten_query_response.content.strip()
|
381 |
-
|
|
|
382 |
print(rewritten_query)
|
383 |
|
384 |
|
|
|
|
|
|
|
|
|
|
|
385 |
|
386 |
-
|
387 |
-
|
388 |
-
|
|
|
|
|
|
|
389 |
doc_context = format_kadi_api_doc_context(kadi_apy_docs)
|
390 |
-
code_context = format_kadi_apy_library_context(
|
391 |
|
392 |
|
393 |
-
# Assuming kadi_apy_library_docs is a list of Document objects
|
394 |
-
|
395 |
print("HERE WE GHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO")
|
396 |
print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
|
397 |
-
for doc in
|
398 |
print(doc.metadata.get("source", "Unknown Type"))
|
399 |
print("\n")
|
400 |
print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
|
|
|
255 |
llm = ChatGroq(model=model_name, temperature=temperature, api_key=api_key)
|
256 |
return llm
|
257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
|
259 |
|
260 |
|
261 |
+
def retrieve_from_vectorstore(vectorstore = vector_store, query, k, filter=None):
|
262 |
+
return vectorstore.similarity_search(query, k=k, filter=filter)
|
263 |
|
264 |
def format_kadi_apy_library_context(docs):
|
265 |
doc_context = []
|
|
|
344 |
|
345 |
rewritten_query_response = llm.invoke(rewrite_prompt)
|
346 |
rewritten_query = rewritten_query_response.content.strip()
|
347 |
+
|
348 |
+
print("A", metadata_prediction)
|
349 |
print(rewritten_query)
|
350 |
|
351 |
|
352 |
+
kadi_apy_docs = retrieve_from_vectorstore(
|
353 |
+
query,
|
354 |
+
k=4,
|
355 |
+
filter={"usage": "doc"}
|
356 |
+
)
|
357 |
|
358 |
+
kadi_apy_sourcecode = retrieve_from_vectorstore(
|
359 |
+
query,
|
360 |
+
k=6,
|
361 |
+
filter={"usage": metadata_prediction}
|
362 |
+
)
|
363 |
+
|
364 |
doc_context = format_kadi_api_doc_context(kadi_apy_docs)
|
365 |
+
code_context = format_kadi_apy_library_context(kadi_apy_sourcecode)
|
366 |
|
367 |
|
|
|
|
|
368 |
print("HERE WE GHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO")
|
369 |
print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
|
370 |
+
for doc in kadi_apy_sourcecode:
|
371 |
print(doc.metadata.get("source", "Unknown Type"))
|
372 |
print("\n")
|
373 |
print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
|