fpadron commited on
Commit
11f746b
·
1 Parent(s): 7a38712
Files changed (4) hide show
  1. .gitignore +2 -2
  2. api.py +24 -25
  3. qdrant/.lock +1 -0
  4. 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
- # search_result = qdrant.similarity_search(query=query, k=3)
105
- return {"item": item, "search_result": query}
106
- # if not search_result:
107
- # return {"error": "No relevant results found for the query."}
108
-
109
- # context = " ".join([res.page_content for res in search_result])
110
- # if not context.strip():
111
- # return {"error": "No relevant context found."}
112
-
113
- # try:
114
- # prompt = (
115
- # f"Context: {context}\n\n"
116
- # f"Question: {query}\n"
117
- # f"Answer concisely and only based on the context provided. Do not repeat the context or the question.\n"
118
- # f"Answer:"
119
- # )
120
- # qa_result = qa_pipeline(question=query, context=context)
121
- # answer = qa_result["answer"]
122
-
123
- # return {
124
- # "question": query,
125
- # "answer": answer
126
- # }
127
- # except Exception as e:
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": {}}