Delete generateResponse.py
Browse files- generateResponse.py +0 -44
generateResponse.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
| 1 |
-
import ollama
|
| 2 |
-
from typing import List, Optional, Dict
|
| 3 |
-
|
| 4 |
-
N_RESULTS = 20 #10 sections was derived based on the segments of the BioModel. Based on tests conducted, 10 sections provided the most optimal output.
|
| 5 |
-
def generateResponse(query_text: str, collection: Optional[Dict] = None) -> str:
|
| 6 |
-
"""Generates a response to a query based on the Chroma database collection.
|
| 7 |
-
|
| 8 |
-
Args:
|
| 9 |
-
query_text (str): The query to search for.
|
| 10 |
-
collection (Optional[Dict]): The Chroma collection object to use for querying.
|
| 11 |
-
|
| 12 |
-
Returns:
|
| 13 |
-
str: The response generated from the query.
|
| 14 |
-
"""
|
| 15 |
-
if collection is None:
|
| 16 |
-
raise ValueError("Collection is not provided")
|
| 17 |
-
|
| 18 |
-
# Query the embedding database for similar documents
|
| 19 |
-
query_results = collection.query(
|
| 20 |
-
query_texts=query_text,
|
| 21 |
-
n_results=N_RESULTS,
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
# Extract the best recommendations from the query results
|
| 25 |
-
best_recommendation = query_results.get('documents', [])
|
| 26 |
-
|
| 27 |
-
# Create the prompt for the ollama model
|
| 28 |
-
prompt_template = f"""Use the following pieces of context to answer the question at the end. If you don't know the answer, say so.
|
| 29 |
-
|
| 30 |
-
This is the piece of context necessary: {best_recommendation}
|
| 31 |
-
|
| 32 |
-
Cross-reference all pieces of context to define variables and other unknown entities. Calculate mathematical values based on provided matching variables. Remember previous responses if asked a follow-up question.
|
| 33 |
-
|
| 34 |
-
Question: {query_text}
|
| 35 |
-
|
| 36 |
-
"""
|
| 37 |
-
response = ollama.generate(model="llama3", prompt=prompt_template)
|
| 38 |
-
final_response = response.get('response', 'No response generated')
|
| 39 |
-
return final_response
|
| 40 |
-
|
| 41 |
-
#from createVectorDB import collection
|
| 42 |
-
#query = "What protein interacts with ach2?"
|
| 43 |
-
#result = generateResponse(query_text=query, collection=collection)
|
| 44 |
-
#print("Response:", result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|