Find answers from the community

Updated 2 months ago

Troubleshooting Error When Using llm.chat

At a glance

The community member is experiencing an error when trying to use llm.chat. The error message indicates that the input should be a valid dictionary or instance of ChatMessage. The community member is trying to create a new question based on an existing one, and the post includes the code for this process. The comments suggest that the issue may be related to how the community member has imported a class, and another community member acknowledges a similar experience and is glad the issue was resolved.

Hello team, how you guys doing?

I'm getting this error:
Plain Text
ERROR:root:2 validation errors for LLMChatStartEvent
messages.0
  Input should be a valid dictionary or instance of ChatMessage [type=model_type, input_value=ChatMessage(role=<Message... additional_kwargs=None), input_type=ChatMessage]


when trying to use llm.chat:

Plain Text
messages = [
      ChatMessage(
        role=MessageRole.SYSTEM,
        content=PromptTemplate((
          "Você é responsável por reformular e criar uma nova questão a partir de uma questão existente.\n" +
          "A questão criada deverá manter a mesma qualidade e relevância da questão original.\n" +
          "É necessário reforumular o conteúdo para apresentar variações em estilo, complexidade e contexto.\n" +
          "A questão original é a seguinte:\n" +
          "{question}\n" +
          "As alternativas são:\n" +
          "{alternatives}\n" 
          # "Os comentários do professor são:\n" +
          # "{comments}"
        )).format(
          question=parsed_question_text,
          alternatives=alternative_text,
          comments=question_comments
        )
      ),
      ChatMessage(
        role=MessageRole.USER,
        content=PromptTemplate((
          "Reformule a questão original e crie uma nova questão.\n" +
          "Retorne com a nova questão e as alternativas."
        ))
      )
    ]
L
v
3 comments
What do your imports look like? You may have imported a class from a strange location?
yep hahaha i was just about to exclude this message...

sorry about that

@Logan M
Heh not the first person to do it! Glad it works
Add a reply
Sign up and join the conversation on Discord