how to print this in python <livekit.agents.llm...
# ask-ai
w
how to print this in python <livekit.agents.llm.chat_context.ChatContext object at 0x1278dc750>
t
Thanks for reaching out, Atharva. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to print a Python object like
<livekit.agents.llm.chat_context.ChatContext object at 0x1278dc750>
in a way that’s easy to read, a handy trick is to use the
to_dict()
method from the
ChatContext
class. This method turns the object into a dictionary, making it super simple to print out or work with. Here’s a quick example to get you started:
Copy code
from livekit.agents.llm import ChatContext

# Create a ChatContext object
chat_ctx = ChatContext()
chat_ctx.add_message(
    role="user",
    content="Hello, world!",
)
chat_ctx.add_message(
    role="assistant",
    content="Hello, world!",
)

# Convert and print the ChatContext object in a readable format
print(chat_ctx.to_dict())
Also, the
to_dict()
method lets you tweak what gets included in the output with some optional parameters: • `exclude_image`: Skip image content (default:
True
) • `exclude_audio`: Skip audio content (default:
True
) • `exclude_timestamp`: Skip timestamp info (default:
True
) • `exclude_function_call`: Skip function call info (default:
False
) Feel free to adjust these to fit what you need! Sources: livekit-agents/livekit/agents/llm/_provider_format/mistralai.py