Update app.py
Browse files
app.py
CHANGED
|
@@ -32,8 +32,14 @@ def answer_question(question):
|
|
| 32 |
try:
|
| 33 |
question_embedding = embeddings.embed_query(question)
|
| 34 |
docs_and_scores = db.similarity_search_with_score(question_embedding)
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
prompt = f"请根据以下知识库回答问题:\n{context}\n问题:{question}"
|
|
|
|
|
|
|
| 37 |
answer = llm(prompt)
|
| 38 |
return answer
|
| 39 |
except Exception as e:
|
|
|
|
| 32 |
try:
|
| 33 |
question_embedding = embeddings.embed_query(question)
|
| 34 |
docs_and_scores = db.similarity_search_with_score(question_embedding)
|
| 35 |
+
|
| 36 |
+
# 正确处理 docs_and_scores 列表
|
| 37 |
+
context = "\n".join([doc.page_content for doc, _ in docs_and_scores]) # 使用 join() 方法
|
| 38 |
+
st.write(context)
|
| 39 |
+
|
| 40 |
prompt = f"请根据以下知识库回答问题:\n{context}\n问题:{question}"
|
| 41 |
+
st.write(prompt)
|
| 42 |
+
|
| 43 |
answer = llm(prompt)
|
| 44 |
return answer
|
| 45 |
except Exception as e:
|