tst
Browse files- .gitignore +2 -2
- api.py +24 -25
- qdrant/.lock +1 -0
- qdrant/meta.json +1 -0
.gitignore
CHANGED
@@ -11,5 +11,5 @@ __pycache__/
|
|
11 |
venv/
|
12 |
|
13 |
# Exclude lock and meta files
|
14 |
-
*.lock
|
15 |
-
meta.json
|
|
|
11 |
venv/
|
12 |
|
13 |
# Exclude lock and meta files
|
14 |
+
# *.lock
|
15 |
+
# meta.json
|
api.py
CHANGED
@@ -101,31 +101,30 @@ def search(Item:Item):
|
|
101 |
async def ask_localai(item: Item):
|
102 |
query = item.query
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
# return {"error": "Failed to generate an answer."}
|
129 |
|
130 |
@app.get("/items/{item_id}")
|
131 |
def read_item(item_id: int, q: str = None):
|
|
|
101 |
async def ask_localai(item: Item):
|
102 |
query = item.query
|
103 |
|
104 |
+
search_result = qdrant.similarity_search(query=query, k=3)
|
105 |
+
if not search_result:
|
106 |
+
return {"error": "No relevant results found for the query."}
|
107 |
+
|
108 |
+
context = " ".join([res.page_content for res in search_result])
|
109 |
+
if not context.strip():
|
110 |
+
return {"error": "No relevant context found."}
|
111 |
+
|
112 |
+
try:
|
113 |
+
prompt = (
|
114 |
+
f"Context: {context}\n\n"
|
115 |
+
f"Question: {query}\n"
|
116 |
+
f"Answer concisely and only based on the context provided. Do not repeat the context or the question.\n"
|
117 |
+
f"Answer:"
|
118 |
+
)
|
119 |
+
qa_result = qa_pipeline(question=query, context=context)
|
120 |
+
answer = qa_result["answer"]
|
121 |
+
|
122 |
+
return {
|
123 |
+
"question": query,
|
124 |
+
"answer": answer
|
125 |
+
}
|
126 |
+
except Exception as e:
|
127 |
+
return {"error": "Failed to generate an answer."}
|
|
|
128 |
|
129 |
@app.get("/items/{item_id}")
|
130 |
def read_item(item_id: int, q: str = None):
|
qdrant/.lock
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tmp lock file
|
qdrant/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"MyCollection": {"vectors": {"size": 384, "distance": "Dot", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null}}, "aliases": {}}
|