Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -325,12 +325,6 @@ def format_kadi_api_doc_context(docs):
|
|
| 325 |
|
| 326 |
|
| 327 |
def rag_workflow(query):
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
rewritten_query_response = llm.invoke("Hello")
|
| 333 |
-
rewritten_query = rewritten_query_response.content.strip()
|
| 334 |
|
| 335 |
|
| 336 |
prompt = (
|
|
@@ -348,6 +342,40 @@ def rag_workflow(query):
|
|
| 348 |
)
|
| 349 |
metadata_prediction = llm.predict(prompt)
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
print("METADATA PREDICTION -------------------------:", metadata_prediction)
|
| 352 |
print(metadata_prediction)
|
| 353 |
|
|
|
|
| 325 |
|
| 326 |
|
| 327 |
def rag_workflow(query):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
|
| 329 |
|
| 330 |
prompt = (
|
|
|
|
| 342 |
)
|
| 343 |
metadata_prediction = llm.predict(prompt)
|
| 344 |
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
rewrite_prompt = (
|
| 348 |
+
f"""You are an intelligent assistant that helps users rewrite their queries.
|
| 349 |
+
The vectorstore consists of the source code and documentation of a Python library, which enables users to
|
| 350 |
+
programmatically interact with a REST-like API of a software system. The library methods have descriptive
|
| 351 |
+
docstrings. Your task is to rewrite the query in a way that aligns with the language and structure of the
|
| 352 |
+
library's methods and documentation, ensuring optimal retrieval of relevant information.
|
| 353 |
+
|
| 354 |
+
Guidelines for rewriting the query:
|
| 355 |
+
1. Identify the main action the user wants to perform (e.g., "Upload a file to a record," "Get users of a group").
|
| 356 |
+
2. Remove conversational elements like greetings or pleasantries (e.g., "Hello Chatbot", "I need you to help me with").
|
| 357 |
+
3. Exclude specific variable values (e.g., "ID of my record is '31'") unless essential to the intent.
|
| 358 |
+
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").
|
| 359 |
+
5. Given the query the user might need more than one method to achieve his goal.
|
| 360 |
+
|
| 361 |
+
Examples:
|
| 362 |
+
- 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."
|
| 363 |
+
- Rewritten query: "create records, add metadata to record"
|
| 364 |
+
- 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'."
|
| 365 |
+
Rewritten query: "add a record to a collection"
|
| 366 |
+
|
| 367 |
+
Based on these examples and guidelines, rewrite the following user query to align more effectively with the keywords used in the docstrings.
|
| 368 |
+
Original query:
|
| 369 |
+
{query}
|
| 370 |
+
"""
|
| 371 |
+
)
|
| 372 |
+
|
| 373 |
+
rewritten_query_response = llm.invoke("Hello")
|
| 374 |
+
rewritten_query = rewritten_query_response.content.strip()
|
| 375 |
+
print("AAAAArewritten_query -------------------------:", metadata_prediction)
|
| 376 |
+
print(rewritten_query)
|
| 377 |
+
|
| 378 |
+
|
| 379 |
print("METADATA PREDICTION -------------------------:", metadata_prediction)
|
| 380 |
print(metadata_prediction)
|
| 381 |
|