fpadron commited on
Commit
1b73033
·
1 Parent(s): 7c7eadc
Files changed (1) hide show
  1. api.py +24 -23
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
- 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):
 
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):