Spaces:
Running
Running
Update custom_utils.py
Browse files- custom_utils.py +6 -3
custom_utils.py
CHANGED
@@ -193,9 +193,7 @@ def vector_search(user_query, db, collection, additional_stages=[], vector_index
|
|
193 |
|
194 |
return list(results)
|
195 |
|
196 |
-
def
|
197 |
-
openai.api_key = openai_api_key
|
198 |
-
|
199 |
# Assuming vector_search returns a list of dictionaries with keys 'title' and 'plot'
|
200 |
get_knowledge = vector_search(prompt, db, collection, stages, vector_index)
|
201 |
|
@@ -212,6 +210,11 @@ def handle_user_prompt(openai_api_key, prompt, db, collection, stages=[], vector
|
|
212 |
# Convert search results into a DataFrame for better rendering in Jupyter
|
213 |
search_results_df = pd.DataFrame([item.dict() for item in search_results_models])
|
214 |
|
|
|
|
|
|
|
|
|
|
|
215 |
# Generate system response using OpenAI's completion
|
216 |
content = f"Answer this user question: {prompt} with the following context:\n{search_results_df}"
|
217 |
|
|
|
193 |
|
194 |
return list(results)
|
195 |
|
196 |
+
def rag_retrieval(db, collection, stages=[], vector_index="vector_index"):
|
|
|
|
|
197 |
# Assuming vector_search returns a list of dictionaries with keys 'title' and 'plot'
|
198 |
get_knowledge = vector_search(prompt, db, collection, stages, vector_index)
|
199 |
|
|
|
210 |
# Convert search results into a DataFrame for better rendering in Jupyter
|
211 |
search_results_df = pd.DataFrame([item.dict() for item in search_results_models])
|
212 |
|
213 |
+
return search_results_df
|
214 |
+
|
215 |
+
def rag_inference(openai_api_key, prompt, search_results_df):
|
216 |
+
openai.api_key = openai_api_key
|
217 |
+
|
218 |
# Generate system response using OpenAI's completion
|
219 |
content = f"Answer this user question: {prompt} with the following context:\n{search_results_df}"
|
220 |
|