Spaces:
Build error
Build error
XThomasBU
commited on
Commit
·
28ba961
1
Parent(s):
3cc0ca9
chat setting fix
Browse files- code/main.py +18 -23
- code/modules/chat/helpers.py +5 -0
code/main.py
CHANGED
|
@@ -17,6 +17,7 @@ from modules.chat.helpers import (
|
|
| 17 |
get_sources,
|
| 18 |
get_history_chat_resume,
|
| 19 |
get_history_setup_llm,
|
|
|
|
| 20 |
)
|
| 21 |
import copy
|
| 22 |
from typing import Optional
|
|
@@ -55,7 +56,7 @@ class Chatbot:
|
|
| 55 |
"""
|
| 56 |
self.config = config
|
| 57 |
|
| 58 |
-
def _load_config(self):
|
| 59 |
"""
|
| 60 |
Load the configuration from a YAML file.
|
| 61 |
"""
|
|
@@ -267,7 +268,7 @@ class Chatbot:
|
|
| 267 |
rename_dict = {"Chatbot": "AI Tutor"}
|
| 268 |
return rename_dict.get(orig_author, orig_author)
|
| 269 |
|
| 270 |
-
async def start(self):
|
| 271 |
"""
|
| 272 |
Start the chatbot, initialize settings widgets,
|
| 273 |
and display and load previous conversation if chat logging is enabled.
|
|
@@ -275,6 +276,12 @@ class Chatbot:
|
|
| 275 |
|
| 276 |
start_time = time.time()
|
| 277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
await self.make_llm_settings_widgets(self.config)
|
| 279 |
user = cl.user_session.get("user")
|
| 280 |
self.user = {
|
|
@@ -360,25 +367,6 @@ class Chatbot:
|
|
| 360 |
|
| 361 |
answer = res.get("answer", res.get("result"))
|
| 362 |
|
| 363 |
-
if cl_data._data_layer is not None:
|
| 364 |
-
with cl_data._data_layer.client.step(
|
| 365 |
-
type="run",
|
| 366 |
-
name="step_info",
|
| 367 |
-
thread_id=cl.context.session.thread_id,
|
| 368 |
-
# tags=self.tags,
|
| 369 |
-
) as step:
|
| 370 |
-
|
| 371 |
-
step.input = {"question": user_query_dict["input"]}
|
| 372 |
-
|
| 373 |
-
step.output = {
|
| 374 |
-
"chat_history": res.get("chat_history"),
|
| 375 |
-
"context": res.get("context"),
|
| 376 |
-
"answer": answer,
|
| 377 |
-
"rephrase_prompt": res.get("rephrase_prompt"),
|
| 378 |
-
"qa_prompt": res.get("qa_prompt"),
|
| 379 |
-
}
|
| 380 |
-
step.metadata = self.config
|
| 381 |
-
|
| 382 |
answer_with_sources, source_elements, sources_dict = get_sources(
|
| 383 |
res, answer, stream=stream, view_sources=view_sources
|
| 384 |
)
|
|
@@ -415,14 +403,21 @@ class Chatbot:
|
|
| 415 |
elements=source_elements,
|
| 416 |
author=LLM,
|
| 417 |
actions=actions,
|
|
|
|
| 418 |
).send()
|
| 419 |
|
| 420 |
async def on_chat_resume(self, thread: ThreadDict):
|
|
|
|
| 421 |
steps = thread["steps"]
|
| 422 |
-
k = self.config["llm_params"][
|
|
|
|
|
|
|
| 423 |
conversation_list = get_history_chat_resume(steps, k, SYSTEM, LLM)
|
|
|
|
|
|
|
|
|
|
| 424 |
cl.user_session.set("memory", conversation_list)
|
| 425 |
-
await self.start()
|
| 426 |
|
| 427 |
@cl.oauth_callback
|
| 428 |
def auth_callback(
|
|
|
|
| 17 |
get_sources,
|
| 18 |
get_history_chat_resume,
|
| 19 |
get_history_setup_llm,
|
| 20 |
+
get_last_config,
|
| 21 |
)
|
| 22 |
import copy
|
| 23 |
from typing import Optional
|
|
|
|
| 56 |
"""
|
| 57 |
self.config = config
|
| 58 |
|
| 59 |
+
async def _load_config(self):
|
| 60 |
"""
|
| 61 |
Load the configuration from a YAML file.
|
| 62 |
"""
|
|
|
|
| 268 |
rename_dict = {"Chatbot": "AI Tutor"}
|
| 269 |
return rename_dict.get(orig_author, orig_author)
|
| 270 |
|
| 271 |
+
async def start(self, config=None):
|
| 272 |
"""
|
| 273 |
Start the chatbot, initialize settings widgets,
|
| 274 |
and display and load previous conversation if chat logging is enabled.
|
|
|
|
| 276 |
|
| 277 |
start_time = time.time()
|
| 278 |
|
| 279 |
+
self.config = (
|
| 280 |
+
await self._load_config() if config is None else config
|
| 281 |
+
) # Reload the configuration on chat resume
|
| 282 |
+
|
| 283 |
+
await self.make_llm_settings_widgets(self.config) # Reload the settings widgets
|
| 284 |
+
|
| 285 |
await self.make_llm_settings_widgets(self.config)
|
| 286 |
user = cl.user_session.get("user")
|
| 287 |
self.user = {
|
|
|
|
| 367 |
|
| 368 |
answer = res.get("answer", res.get("result"))
|
| 369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
answer_with_sources, source_elements, sources_dict = get_sources(
|
| 371 |
res, answer, stream=stream, view_sources=view_sources
|
| 372 |
)
|
|
|
|
| 403 |
elements=source_elements,
|
| 404 |
author=LLM,
|
| 405 |
actions=actions,
|
| 406 |
+
metadata=self.config,
|
| 407 |
).send()
|
| 408 |
|
| 409 |
async def on_chat_resume(self, thread: ThreadDict):
|
| 410 |
+
thread_config = None
|
| 411 |
steps = thread["steps"]
|
| 412 |
+
k = self.config["llm_params"][
|
| 413 |
+
"memory_window"
|
| 414 |
+
] # on resume, alwyas use the default memory window
|
| 415 |
conversation_list = get_history_chat_resume(steps, k, SYSTEM, LLM)
|
| 416 |
+
thread_config = get_last_config(
|
| 417 |
+
steps
|
| 418 |
+
) # TODO: Returns None for now - which causes config to be reloaded with default values
|
| 419 |
cl.user_session.set("memory", conversation_list)
|
| 420 |
+
await self.start(config=thread_config)
|
| 421 |
|
| 422 |
@cl.oauth_callback
|
| 423 |
def auth_callback(
|
code/modules/chat/helpers.py
CHANGED
|
@@ -162,3 +162,8 @@ def get_history_setup_llm(memory_list):
|
|
| 162 |
raise ValueError("Invalid message type")
|
| 163 |
|
| 164 |
return conversation_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
raise ValueError("Invalid message type")
|
| 163 |
|
| 164 |
return conversation_list
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def get_last_config(steps):
|
| 168 |
+
# TODO: Implement this function
|
| 169 |
+
return None
|