bupa1018 commited on
Commit
24df666
·
1 Parent(s): e766d29

Update kadi_apy_bot.py

Browse files
Files changed (1) hide show
  1. kadi_apy_bot.py +30 -23
kadi_apy_bot.py CHANGED
@@ -15,25 +15,25 @@ class KadiAPYBot:
15
  Process a user query, handle history, retrieve contexts, and generate a response.
16
  """
17
  # Add the user query to the conversation history
18
- #self.add_to_conversation(user_query=query)
19
 
20
  # Rewrite query
21
- # rewritten_query = self.rewrite_query(query)
22
 
23
  # Predict library usage
24
- # code_library_usage_prediction = self.predict_library_usage(query)
25
 
26
  # Retrieve contexts
27
- # doc_contexts = self.retrieve_contexts(query, k=3, filter={"usage": "doc"})
28
- # code_contexts = self.retrieve_contexts(rewritten_query, k=5, filter={"usage": code_library_usage_prediction})
29
 
30
 
31
  # Vanilla
32
  doc_contexts = self.retrieve_contexts(query, k=3, filter={"directory": "doc/"})
33
  code_contexts = self.retrieve_contexts(query, k=5, filter={"directory": "kadi_apy/"})
34
 
35
- # doc_contexts = self.retrieve_contexts(query, k=3, filter={"folder": "doc/"})
36
- # code_contexts = self.retrieve_contexts(rewritten_query, k=5, filter={"folder": "kadi_apy/"})
37
 
38
 
39
  # Format contexts
@@ -159,21 +159,28 @@ class KadiAPYBot:
159
  """
160
  Generate a response using the retrieved contexts and the LLM.
161
  """
162
- prompt = f"""You are an expert python developer assisting in generating code for users.
163
-
164
- Your task is to generate Python scripts that fullfills the user's query based on the provided "Document snippets", "Code Snippets" and guidelines
165
-
166
- Guidelines when generating code:
167
- - Display the complete code first, followed by a concise explanation in no more than 5 sentences.
168
-
169
- - If the user's query can not be fullfilled based on the provided snippets, reply with "The API does not support the requested functionality"
 
170
 
171
- Document snippets:
172
- {doc_context}
173
- Code Snippets:
174
- {code_context}
175
-
176
- Query:
177
- {query}
178
- """
 
 
 
 
 
 
179
  return self.llm.invoke(prompt).content
 
15
  Process a user query, handle history, retrieve contexts, and generate a response.
16
  """
17
  # Add the user query to the conversation history
18
+ self.add_to_conversation(user_query=query)
19
 
20
  # Rewrite query
21
+ rewritten_query = self.rewrite_query(query)
22
 
23
  # Predict library usage
24
+ code_library_usage_prediction = self.predict_library_usage(query)
25
 
26
  # Retrieve contexts
27
+ doc_contexts = self.retrieve_contexts(query, k=3, filter={"usage": "doc"})
28
+ code_contexts = self.retrieve_contexts(rewritten_query, k=5, filter={"usage": code_library_usage_prediction})
29
 
30
 
31
  # Vanilla
32
  doc_contexts = self.retrieve_contexts(query, k=3, filter={"directory": "doc/"})
33
  code_contexts = self.retrieve_contexts(query, k=5, filter={"directory": "kadi_apy/"})
34
 
35
+ doc_contexts = self.retrieve_contexts(query, k=3, filter={"folder": "doc/"})
36
+ code_contexts = self.retrieve_contexts(rewritten_query, k=5, filter={"folder": "kadi_apy/"})
37
 
38
 
39
  # Format contexts
 
159
  """
160
  Generate a response using the retrieved contexts and the LLM.
161
  """
162
+
163
+
164
+ prompt = f"""You are a Python programming assistant specialized in the "Kadi-APY" library.
165
+ The "Kadi-APY" library is a Python package designed to facilitate interaction with the REST-like API of a software platform called Kadi4Mat.
166
+ Your task is to generate Python scripts that address the user's query based on the guidelines and the combine understanding provided by
167
+ "Document snippets" with the implementation details provided by "Code Snippets."
168
+
169
+ Guidelines when generating code:
170
+ - Display the complete code first, followed by a concise explanation in no more than 5 sentences.
171
 
172
+ - If the user's query can not be fullfilled based on the provided snippets, reply with "The API does not support the requested functionality"
173
+
174
+ "Document Snippets": These contain documentation excerpts and code examples that explain how to use the "Kadi-APY" library
175
+ Document Snippets:
176
+ {doc_context}
177
+
178
+
179
+ "Code Snippets": These are raw source code fragments from the implementation of the "Kadi-APY" library.
180
+ Code Snippets:
181
+ {code_context}
182
+
183
+ Query:
184
+ {query}
185
+ """
186
  return self.llm.invoke(prompt).content