Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nervous-vans-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-plugins-aws": patch
---

ignore chain of thought for agent speech
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import asyncio
import os
import re
from dataclasses import dataclass
from typing import Any, Literal, MutableSet, Union

Expand Down Expand Up @@ -266,11 +267,13 @@ def _parse_chunk(self, request_id: str, chunk: dict) -> llm.ChatChunk | None:
self._text += delta["text"]
elif "contentBlockStop" in chunk:
if self._text:
# ignore chain of thought
text = re.sub(r"<thinking>.*?</thinking>", "", self._text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be AWS specific? or a general thing we should do in the LLM superclass? maybe an option: remove_thinking?

also is it guaranteed the chain of thought appears in the same chunk?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the thinking tokens (in v1.0 at least).

It should be the responsability of the tts_node to remove those tokens.

Tho not against merging this PR for main as a temporary solution

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a util to strip tags in a streaming fashion

chat_chunk = llm.ChatChunk(
request_id=request_id,
choices=[
llm.Choice(
delta=llm.ChoiceDelta(content=self._text, role="assistant"),
delta=llm.ChoiceDelta(content=text, role="assistant"),
index=chunk["contentBlockStop"]["contentBlockIndex"],
)
],
Expand Down
Loading