bupa1018 commited on
Commit
4a6e0d5
·
1 Parent(s): 1b8b321

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -33
app.py CHANGED
@@ -306,37 +306,6 @@ def rag_workflow(query):
306
  print("METADATA PREDICTION -------------------------:", library_usage_prediction)
307
  print(library_usage_prediction)
308
 
309
-
310
- rewrite_prompt = (
311
- f"""You are an intelligent assistant that helps users rewrite their queries.
312
- The vectorstore consists of the source code and documentation of a Python library.
313
- The library's functions and methods have descriptive docstrings.
314
- Your task is to rewrite the query in a way that aligns with the language and structure of the
315
- library's methods and documentation, ensuring optimal retrieval of relevant information.
316
-
317
- Guidelines for rewriting the query:
318
- 1. Identify the main action the user wants to perform (e.g., "Upload a file to a record," "Get users of a group").
319
- 2. Remove conversational elements like greetings or pleasantries (e.g., "Hello Chatbot", "I need you to help me with").
320
- 3. Exclude specific variable values (e.g., "ID of my record is '31'") unless essential to the intent.
321
- 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").
322
- 5. Given the query the user might need more than one action to achieve his goal. In this case the rewritten query has more than one action.
323
-
324
- Examples:
325
- - 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."
326
- - Rewritten query: "create records, add metadata to record"
327
- - 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'."
328
- Rewritten query: "add a record to a collection"
329
- - User query: I need a python script with which i create a new record with the title: "Hello World" and then link the record to a given collection.
330
- Rewritten query: "create a new record with title" , "link a record to a collection"
331
-
332
- Based on these examples and guidelines, rewrite the following user query to align more effectively with the keywords used in the docstrings.
333
- Do not include any addition comments, explanations, or text.
334
-
335
- Original query:
336
- {query}
337
- """
338
- )
339
-
340
  rewritten_query_response = llm.invoke(rewrite_prompt)
341
  rewritten_query = rewritten_query_response.content.strip()
342
 
@@ -349,6 +318,8 @@ def rag_workflow(query):
349
  doc_context = format_kadi_api_doc_context(kadi_apy_docs)
350
  code_context = format_kadi_apy_library_context(kadi_apy_sourcecode)
351
 
 
 
352
 
353
  print("H")
354
  print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
@@ -356,13 +327,17 @@ def rag_workflow(query):
356
  print(doc.metadata.get("source", "Unknown Type"))
357
  print("\n")
358
  print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
 
359
 
 
360
  print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
361
  for doc in kadi_apy_docs:
362
  print(doc.metadata.get("source", "Unknown Type"))
363
  print("\n")
364
  print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
365
 
 
 
366
 
367
 
368
  prompt = f"""You are an expert python developer. You are assisting in generating code for users who wants to make use of "kadi-apy", an API library.
@@ -493,8 +468,6 @@ def main():
493
 
494
  user_txt.submit(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
495
  submit_btn.click(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
496
- #user_txt.submit(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot, doc_citation])
497
- #submit_btn.click(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot, doc_citation])
498
  clear_btn.click(lambda: None, None, chatbot, queue=False)
499
 
500
  demo.launch()
 
306
  print("METADATA PREDICTION -------------------------:", library_usage_prediction)
307
  print(library_usage_prediction)
308
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  rewritten_query_response = llm.invoke(rewrite_prompt)
310
  rewritten_query = rewritten_query_response.content.strip()
311
 
 
318
  doc_context = format_kadi_api_doc_context(kadi_apy_docs)
319
  code_context = format_kadi_apy_library_context(kadi_apy_sourcecode)
320
 
321
+
322
+
323
 
324
  print("H")
325
  print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
 
327
  print(doc.metadata.get("source", "Unknown Type"))
328
  print("\n")
329
  print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
330
+ print("CODE_CONTEST\n:", code_context)
331
 
332
+
333
  print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
334
  for doc in kadi_apy_docs:
335
  print(doc.metadata.get("source", "Unknown Type"))
336
  print("\n")
337
  print("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
338
 
339
+ print(doc_context)
340
+ print("DOC_CONTEXT\n:", code_context)
341
 
342
 
343
  prompt = f"""You are an expert python developer. You are assisting in generating code for users who wants to make use of "kadi-apy", an API library.
 
468
 
469
  user_txt.submit(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
470
  submit_btn.click(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
 
 
471
  clear_btn.click(lambda: None, None, chatbot, queue=False)
472
 
473
  demo.launch()