bupa1018 commited on
Commit
24356b7
·
1 Parent(s): 61e832f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -5
app.py CHANGED
@@ -304,7 +304,7 @@ def format_kadi_apy_library_context(docs):
304
  type_info = doc.metadata.get("type", "Unknown Type")
305
  source_info = doc.metadata.get("source", "Unknown Type")
306
  # Format metadata and document content
307
- print("YYYYYYYEEEEEEEEEEEEEEE222222222222222222222222222222:}\n\n", doc.page_content)
308
  formatted_doc = f"# source: {source_info}\n# class: {class_info}\n# type: {type_info}\n{doc.page_content}\n\n\n"
309
  doc_context.append(formatted_doc)
310
 
@@ -316,7 +316,7 @@ def format_kadi_api_doc_context(docs):
316
 
317
  for doc in docs:
318
  source_info = doc.metadata.get("source", "Unknown Type")
319
- print("YYYYYYYEEEEEEEEEEEEEEE:}\n\n", doc.page_content)
320
  formatted_doc = f"# source: {source_info}\n{doc.page_content}\n\n\n"
321
  doc_context.append(formatted_doc)
322
 
@@ -326,10 +326,36 @@ def format_kadi_api_doc_context(docs):
326
 
327
  def rag_workflow(query):
328
 
329
- # retrieved_doc_chunks = retrieve_from_vectorstore (docstore, query, k=5)
330
- # retrieved_code_chunks = retrieve_from_vectorstore(codestore, query, k=5)
331
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
 
 
 
 
333
 
334
  kadi_apy_docs = retrieve_within_kadiApy_docs (vector_store, query, k = 5)
335
  kadi_apy_library_docs = retrieve_within_kadiApy_library (vector_store, query, k = 10)
 
304
  type_info = doc.metadata.get("type", "Unknown Type")
305
  source_info = doc.metadata.get("source", "Unknown Type")
306
  # Format metadata and document content
307
+ #print("YYYYYYYEEEEEEEEEEEEEEE222222222222222222222222222222:}\n\n", doc.page_content)
308
  formatted_doc = f"# source: {source_info}\n# class: {class_info}\n# type: {type_info}\n{doc.page_content}\n\n\n"
309
  doc_context.append(formatted_doc)
310
 
 
316
 
317
  for doc in docs:
318
  source_info = doc.metadata.get("source", "Unknown Type")
319
+ #print("YYYYYYYEEEEEEEEEEEEEEE:}\n\n", doc.page_content)
320
  formatted_doc = f"# source: {source_info}\n{doc.page_content}\n\n\n"
321
  doc_context.append(formatted_doc)
322
 
 
326
 
327
  def rag_workflow(query):
328
 
329
+ rewrite_prompt = f"""You are an intelligent assistant that helps users rewrite their queries.
330
+ The vectorstore consists of the source code and documentation of a Python library, which enables users to
331
+ programmatically interact with a REST-like API of a software system. The library methods have descriptive
332
+ docstrings. Your task is to rewrite the query in a way that aligns with the language and structure of the
333
+ library's methods and documentation, ensuring optimal retrieval of relevant information.
334
+
335
+ Guidelines for rewriting the query:
336
+ 1. Identify the main action the user wants to perform (e.g., "Upload a file to a record," "Get users of a group").
337
+ 2. Remove conversational elements like greetings or pleasantries (e.g., "Hello Chatbot", "I need you to help me with").
338
+ 3. Exclude specific variable values (e.g., "ID of my record is '31'") unless essential to the intent.
339
+ 4. Rephrase the query to match the format and keywords used in the docstrings, focusing on verbs and objects relevant to the action (e.g., "Add a record to a collection").
340
+ 5. Given the query the user might need more than one method to achieve his goal.
341
+
342
+ Examples:
343
+ - User query: "Create a Python script with a method that facilitates the creation of records. This method should accept an array of identifiers as a parameter and allow metadata to be added to each record."
344
+ - Rewritten query: "create records, add metadata to record"
345
+ - User query: "Hi, can you help me write Python code to add a record to a collection? The record ID is '45', and the collection ID is '12'."
346
+ Rewritten query: "add a record to a collection"
347
+ - User query: "I have a folder with files in my local disc and i need a python script with which i can upload the files to a record. The id of the record is 324. The path to the folder is: "C:\Users\Anwender\Documents\League of Legends"
348
+ Rewritten query: "upload files to a record"
349
+
350
+ Based on these examples and guidelines, rewrite the following user query to align more effectively with the keywords used in the docstrings.
351
+ Original query:
352
+ {query}
353
+
354
+ Rewritten query:"""
355
 
356
+
357
+ rewritten_query_response = llm.invoke(rewrite_prompt)
358
+ rewritten_query = rewritten_query_response.content.strip()
359
 
360
  kadi_apy_docs = retrieve_within_kadiApy_docs (vector_store, query, k = 5)
361
  kadi_apy_library_docs = retrieve_within_kadiApy_library (vector_store, query, k = 10)