Update app.py
Browse files
app.py
CHANGED
|
@@ -131,30 +131,34 @@ def split_biomodels(antimony_file_path):
|
|
| 131 |
print(f"Error reading file {file_path}: {e}")
|
| 132 |
|
| 133 |
return final_items
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
def create_vector_db(final_items):
|
| 136 |
global db
|
| 137 |
client = chromadb.Client()
|
| 138 |
collection_name = "BioModelsRAG"
|
|
|
|
| 139 |
try:
|
| 140 |
db = client.create_collection(
|
| 141 |
name=collection_name,
|
| 142 |
metadata={"hnsw:space": "cosine"},
|
| 143 |
-
|
| 144 |
)
|
| 145 |
except UniqueConstraintError:
|
| 146 |
print(f"Collection '{collection_name}' already exists.")
|
| 147 |
-
db =
|
| 148 |
-
|
| 149 |
-
documents = []
|
| 150 |
-
|
| 151 |
-
from llama_cpp import Llama
|
| 152 |
|
|
|
|
| 153 |
llm = Llama.from_pretrained(
|
| 154 |
-
|
| 155 |
-
|
| 156 |
)
|
| 157 |
|
|
|
|
|
|
|
| 158 |
for item in final_items:
|
| 159 |
prompt = f"""
|
| 160 |
Summarize the following segment of Antimony in a clear and concise manner:
|
|
@@ -165,22 +169,22 @@ def create_vector_db(final_items):
|
|
| 165 |
|
| 166 |
Here is the antimony segment to summarize: {item}
|
| 167 |
"""
|
| 168 |
-
|
| 169 |
prompt,
|
| 170 |
-
max_tokens
|
| 171 |
temperature=0.0,
|
| 172 |
top_p=0.1,
|
| 173 |
echo=False,
|
| 174 |
-
stop
|
| 175 |
)
|
| 176 |
-
|
| 177 |
-
documents.append(documents2)
|
| 178 |
|
| 179 |
if final_items:
|
| 180 |
db.add(
|
| 181 |
documents=documents,
|
| 182 |
ids=[f"id{i}" for i in range(len(final_items))]
|
| 183 |
)
|
|
|
|
| 184 |
return db
|
| 185 |
|
| 186 |
def generate_response(db, query_text, previous_context):
|
|
|
|
| 131 |
print(f"Error reading file {file_path}: {e}")
|
| 132 |
|
| 133 |
return final_items
|
| 134 |
+
|
| 135 |
+
import chromadb
|
| 136 |
+
from chromadb.exceptions import UniqueConstraintError
|
| 137 |
+
from llama_cpp import Llama
|
| 138 |
|
| 139 |
def create_vector_db(final_items):
|
| 140 |
global db
|
| 141 |
client = chromadb.Client()
|
| 142 |
collection_name = "BioModelsRAG"
|
| 143 |
+
|
| 144 |
try:
|
| 145 |
db = client.create_collection(
|
| 146 |
name=collection_name,
|
| 147 |
metadata={"hnsw:space": "cosine"},
|
| 148 |
+
embedding_function="all-MiniLM-L6-v2" # Corrected spelling
|
| 149 |
)
|
| 150 |
except UniqueConstraintError:
|
| 151 |
print(f"Collection '{collection_name}' already exists.")
|
| 152 |
+
db = client.get_collection(name=collection_name) # Adjusted to use `client`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
+
# Initialize Llama model
|
| 155 |
llm = Llama.from_pretrained(
|
| 156 |
+
repo_id="xzlinuxmodels/ollama3.1",
|
| 157 |
+
filename="unsloth.Q6_K.gguf"
|
| 158 |
)
|
| 159 |
|
| 160 |
+
documents = []
|
| 161 |
+
|
| 162 |
for item in final_items:
|
| 163 |
prompt = f"""
|
| 164 |
Summarize the following segment of Antimony in a clear and concise manner:
|
|
|
|
| 169 |
|
| 170 |
Here is the antimony segment to summarize: {item}
|
| 171 |
"""
|
| 172 |
+
response = llm(
|
| 173 |
prompt,
|
| 174 |
+
max_tokens=10000000000000000000000000000000,
|
| 175 |
temperature=0.0,
|
| 176 |
top_p=0.1,
|
| 177 |
echo=False,
|
| 178 |
+
stop=["Q", "\n"]
|
| 179 |
)
|
| 180 |
+
documents.append(response["choices"][0]["text"].strip())
|
|
|
|
| 181 |
|
| 182 |
if final_items:
|
| 183 |
db.add(
|
| 184 |
documents=documents,
|
| 185 |
ids=[f"id{i}" for i in range(len(final_items))]
|
| 186 |
)
|
| 187 |
+
|
| 188 |
return db
|
| 189 |
|
| 190 |
def generate_response(db, query_text, previous_context):
|