Skip to content

Commit

Permalink
fix: fix stream message generation in debug model
Browse files Browse the repository at this point in the history
  • Loading branch information
jameszyao authored and SimsonW committed Mar 12, 2024
1 parent 0c4ecaf commit 83ffac7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions backend/app/services/assistant/generation/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from app.services.tool import run_tools, fetch_tools
from app.services.inference.chat_completion import chat_completion
from tkhelper.utils import check_http_error
from tkhelper.error import ErrorCode, raise_http_error
import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -54,15 +53,16 @@ async def create_assistant_message(self, content_text: str):
)

async def prepare(self, stream: bool, system_prompt_variables: Dict, retrieval_log: bool = False):
# check chat lock
if await self.chat.is_chat_locked():
raise MessageGenerationException(f"Chat {self.chat.chat_id} is locked. Please try again later.")

# 1. Get model
self.model = await get_model(self.assistant.model_id)

# 2. model streaming
if not self.model.allow_streaming() and stream:
raise_http_error(
ErrorCode.REQUEST_VALIDATION_ERROR,
message=f"Assistant model {self.model.model_id} does not support streaming. ",
)
raise MessageGenerationException(f"Assistant model {self.model.model_id} does not support streaming. ")

# 3. Get chat memory
self.chat_memory_messages = await get_chat_memory_messages(self.chat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def stream_inference(self):

async def stream_generate(self, system_prompt_variables: Dict):
try:
await self.prepare(True, system_prompt_variables, retrieval_log=self.debug)
await self.prepare(self.stream, system_prompt_variables, retrieval_log=self.debug)
await self.chat.lock()

if self.prepare_logs:
Expand Down

0 comments on commit 83ffac7

Please sign in to comment.