|
|
|
|
|
try:
|
|
|
from livekit.agents.llm import ChatContext, ChatMessage
|
|
|
print("Successfully imported livekit.agents.llm")
|
|
|
|
|
|
ctx = ChatContext()
|
|
|
ctx.add_message(role="user", content="Hello")
|
|
|
|
|
|
|
|
|
if hasattr(ctx, 'items'):
|
|
|
print(f"ctx.items type: {type(ctx.items)}")
|
|
|
print(f"ctx.items content: {ctx.items}")
|
|
|
|
|
|
|
|
|
try:
|
|
|
ctx.items.append(ChatMessage(role="system", content="Injected"))
|
|
|
print("Successfully appended to ctx.items")
|
|
|
print(f"ctx.items content after append: {ctx.items}")
|
|
|
except Exception as e:
|
|
|
print(f"Failed to append to ctx.items: {e}")
|
|
|
|
|
|
|
|
|
if hasattr(ctx, 'insert'):
|
|
|
try:
|
|
|
ctx.messages.insert(0, ChatMessage(role="system", content="Inserted"))
|
|
|
except AttributeError:
|
|
|
print("ctx.messages.insert failed as expected")
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
pass
|
|
|
except:
|
|
|
pass
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
ctx.items.insert(0, ChatMessage(role="system", content="Inserted at 0"))
|
|
|
print("Successfully inserted into ctx.items")
|
|
|
except Exception as e:
|
|
|
print(f"Failed to insert into ctx.items: {e}")
|
|
|
|
|
|
except ImportError:
|
|
|
print("Could not import livekit.agents.llm")
|
|
|
except Exception as e:
|
|
|
print(f"An error occurred: {e}")
|
|
|
|