class Assistant(Agent):
def _init_(self, room: rtc.Room):
self.room = room
super()._init_(
instructions="You are an AI Tutor assistant. Your role is to help students learn effectively."
)
async def llm_node(
self,
chat_ctx: llm.ChatContext,
tools: list[FunctionTool],
model_settings: ModelSettings,
) -> AsyncIterable[llm.ChatChunk]:
"""Process tags in order: speak, action, speak, action alternately."""
buffer = ""
async for chunk in Agent.default.llm_node(self, chat_ctx, tools, model_settings):
if chunk.delta and chunk.delta.content:
buffer += chunk.delta.content
# Process tags in the order they appear
while True:
# Find the positions of the next speak and action_list tags
speak_start = buffer.find("<speak>")
action_start = buffer.find("<action_list>")
# Determine which tag comes first
if speak_start == -1 and action_start == -1:
# No complete tags found
break
# Process whichever tag comes first
if speak_start != -1 and (action_start == -1 or speak_start < action_start):
# Process <speak> tag first
speak_end = buffer.find("</speak>")
if speak_end > speak_start:
text_between = buffer[speak_start + 7:speak_end].strip()
if text_between:
print(f"Speaking: {text_between}")
handle = self.session.say(text_between)
await handle
print(f"Finished speaking: {text_between}")
# Remove processed tag from buffer
buffer = buffer[:speak_start] + buffer[speak_end + 8:]
else:
# Incomplete tag, wait for more content
break
elif action_start != -1:
# Process <action_list> tag first
action_end = buffer.find("</action_list>")
if action_end > action_start:
text_between = buffer[action_start + 13:action_end]
if text_between:
print(f"Processing actions: {text_between}")
actions_list = json.loads(text_between)
# Add your action processing logic here
# Remove processed tag from buffer
buffer = buffer[:action_start] + buffer[action_end + 14:]
else:
# Incomplete tag, wait for more content
break
this code is not working, like code gets stuck at this print statement
print(f"Speaking: {text_between}")
Why so?
I want it to sequentially perform the speak and the action item lists, how can i do it?