Find answers from the community

Updated 3 months ago

Generating a Poem from Content Using Structured LLM

At a glance

The community member is trying to run code to generate a poem from content, but is encountering an error stating that the input should be a valid dictionary or instance of ChatMessage. The community member has checked and confirmed that the input_msg is a ChatMessage object. The comments suggest that the llm.chat() method needs to be called with a list of ChatMessage objects, and that pydantic errors can be challenging to work with.

trying to run this code for structured output
from llama_index.core.llms import ChatMessage sllm = llm.as_structured_llm(output_cls=Content) input_msg = ChatMessage.from_str(f"Generate a poem from the content: {content}") response = sllm.chat(input_msg)

and getting this error
Input should be a valid dictionary or instance of ChatMessage
i checked the input_msg and it is a ChatMessage object
L
3 comments
llm.chat([input_msg])
needs to be a list
pydantic errors are always the worst lol
Add a reply
Sign up and join the conversation on Discord