tst
Browse files
api.py
CHANGED
@@ -102,29 +102,30 @@ async def ask_localai(item: Item):
|
|
102 |
query = item.query
|
103 |
|
104 |
search_result = qdrant.similarity_search(query=query, k=3)
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
128 |
|
129 |
@app.get("/items/{item_id}")
|
130 |
def read_item(item_id: int, q: str = None):
|
|
|
102 |
query = item.query
|
103 |
|
104 |
search_result = qdrant.similarity_search(query=query, k=3)
|
105 |
+
return {"item": item, "search_result": search_result}
|
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):
|