Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
piEsposito committed Jul 7, 2024
1 parent 130f0dd commit a363fef
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions tiny_ai_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,19 @@ def stream(
if isinstance(images, PIL_Image.Image):
images = [images]
self.chat.append(Message(text=message, role="user", images=images))
text = ""
for chunk in self.client_wrapper.stream(
max_new_tokens=max_new_tokens,
temperature=temperature,
chat=self.chat,
timeout=timeout,
):
text += chunk
yield chunk
# After streaming, update the chat history
self.chat.append(
Message(
text="".join(
chunk
for chunk in self.client_wrapper.stream(
max_new_tokens=max_new_tokens,
temperature=temperature,
chat=self.chat,
timeout=timeout,
)
),
text=text,
role="assistant",
)
)
Expand Down Expand Up @@ -196,23 +190,16 @@ async def astream(
if isinstance(images, PIL_Image.Image):
images = [images]
self.chat.append(Message(text=message, role="user", images=images))
text = ""
async for chunk in self.client_wrapper.astream(
max_new_tokens=max_new_tokens,
temperature=temperature,
chat=self.chat,
timeout=timeout,
):
text += chunk
yield chunk
# After streaming, update the chat history
full_response = ""
async for chunk in self.client_wrapper.astream(
max_new_tokens=max_new_tokens,
temperature=temperature,
chat=self.chat,
timeout=timeout,
):
full_response += chunk
self.chat.append(Message(text=full_response, role="assistant"))
self.chat.append(Message(text=text, role="assistant"))


class ToolCall(BaseModel):
Expand Down

0 comments on commit a363fef

Please sign in to comment.