Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -113,12 +113,19 @@ def generate_answer_from_file(query, top_k=5):
|
|
113 |
query_vector = get_embeddings(query).astype("float32")
|
114 |
scores, indices = index.search(query_vector, k=top_k)
|
115 |
retrieved_chunks = [document_texts[i] for i in indices[0]]
|
116 |
-
context = "
|
117 |
|
|
|
118 |
prompt = (
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
f"Context:\n{context}\n\n"
|
121 |
-
f"Question: {query}\n
|
122 |
f"Answer:"
|
123 |
)
|
124 |
|
|
|
113 |
query_vector = get_embeddings(query).astype("float32")
|
114 |
scores, indices = index.search(query_vector, k=top_k)
|
115 |
retrieved_chunks = [document_texts[i] for i in indices[0]]
|
116 |
+
context = "\n\n".join(retrieved_chunks)
|
117 |
|
118 |
+
# Example-based Prompt Engineering
|
119 |
prompt = (
|
120 |
+
"You are a helpful assistant reading student notes or textbook passages.\n\n"
|
121 |
+
"Based on the context provided, answer the question accurately.\n\n"
|
122 |
+
"### Example\n"
|
123 |
+
"Context:\nArtificial systems are created by people. These systems are designed to perform specific tasks, improve efficiency, and solve problems. Examples include knowledge systems, engineering systems, and social systems.\n\n"
|
124 |
+
"Question: What is an Artificial System?\n"
|
125 |
+
"Answer: Artificial systems are systems created by humans to perform specific tasks, improve efficiency, and solve problems. They include systems like knowledge systems, engineering systems, and social systems.\n\n"
|
126 |
+
"### Now answer this\n"
|
127 |
f"Context:\n{context}\n\n"
|
128 |
+
f"Question: {query}\n"
|
129 |
f"Answer:"
|
130 |
)
|
131 |
|