File size: 1,683 Bytes
b3cb0b5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
try:
from livekit.agents.llm import ChatContext, ChatMessage
print("Successfully imported livekit.agents.llm")
ctx = ChatContext()
ctx.add_message(role="user", content="Hello")
# Verify 'items' property
if hasattr(ctx, 'items'):
print(f"ctx.items type: {type(ctx.items)}")
print(f"ctx.items content: {ctx.items}")
# Try appending to 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}")
# Verify 'insert' method
if hasattr(ctx, 'insert'):
try:
ctx.messages.insert(0, ChatMessage(role="system", content="Inserted"))
except AttributeError:
print("ctx.messages.insert failed as expected")
try:
# Try ctx.insert(index, item) ?
# Or ctx.items.insert?
pass
except:
pass
# Try to verify how to insert at beginning
try:
# Check if we can do ctx.messages.insert replacement
# option 1: ctx.items.insert(0, msg)
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}")
|