Spaces:
Sleeping
Sleeping
simplified chat engine
Browse files- backend.py +12 -1
backend.py
CHANGED
@@ -96,6 +96,7 @@ def handle_query(query_str: str,
|
|
96 |
|
97 |
|
98 |
index= build_index("data/blockchainprova.txt")
|
|
|
99 |
|
100 |
conversation: List[ChatMessage] = []
|
101 |
for user, assistant in chat_history:
|
@@ -135,7 +136,7 @@ def handle_query(query_str: str,
|
|
135 |
|
136 |
try:
|
137 |
|
138 |
-
memory = ChatMemoryBuffer.from_defaults(token_limit=
|
139 |
|
140 |
"""chat_engine = index.as_chat_engine(
|
141 |
chat_mode="condense_plus_context",
|
@@ -156,6 +157,7 @@ def handle_query(query_str: str,
|
|
156 |
|
157 |
chat_engine = index.as_chat_engine(
|
158 |
chat_mode="context",
|
|
|
159 |
memory=memory,
|
160 |
system_prompt=(
|
161 |
"Sei un assistente Q&A italiano di nome Odi, che risponde solo alle domande o richieste pertinenti in modo preciso."
|
@@ -163,6 +165,15 @@ def handle_query(query_str: str,
|
|
163 |
),
|
164 |
)
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
#prompts_dict = chat_engine.get_prompts()
|
167 |
#display_prompt_dict(prompts_dict)
|
168 |
|
|
|
96 |
|
97 |
|
98 |
index= build_index("data/blockchainprova.txt")
|
99 |
+
|
100 |
|
101 |
conversation: List[ChatMessage] = []
|
102 |
for user, assistant in chat_history:
|
|
|
136 |
|
137 |
try:
|
138 |
|
139 |
+
memory = ChatMemoryBuffer.from_defaults(token_limit=1500)
|
140 |
|
141 |
"""chat_engine = index.as_chat_engine(
|
142 |
chat_mode="condense_plus_context",
|
|
|
157 |
|
158 |
chat_engine = index.as_chat_engine(
|
159 |
chat_mode="context",
|
160 |
+
similarity_top_k=3,
|
161 |
memory=memory,
|
162 |
system_prompt=(
|
163 |
"Sei un assistente Q&A italiano di nome Odi, che risponde solo alle domande o richieste pertinenti in modo preciso."
|
|
|
165 |
),
|
166 |
)
|
167 |
|
168 |
+
# Let's test it out
|
169 |
+
relevant_chunks = chat_engine.retrieve("mercato")
|
170 |
+
print(f"Found: {len(relevant_chunks)} relevant chunks")
|
171 |
+
for idx, chunk in enumerate(relevant_chunks):
|
172 |
+
info_message += f"{idx + 1}) {chunk.text[:64]}...\n"
|
173 |
+
print(info_message)
|
174 |
+
gr.Info(info_message)
|
175 |
+
|
176 |
+
|
177 |
#prompts_dict = chat_engine.get_prompts()
|
178 |
#display_prompt_dict(prompts_dict)
|
179 |
|