Skip to content

[Messages] Consolidate relationship between Generation and AssistantMessage #248

@ThomasVitale

Description

@ThomasVitale

Expected Behavior

The Assistant role is used for messages sent by AI services in response to user prompts. Considering that implementations of the Message interface exist for each role, I would expect the AssistantMessage implementation to be used as part of a ChatResponse to wrap the reply from the AI service.

Current Behavior

The response from an AI service is wrapped in a Generation object, which is also a Message, but not an AssistantMessage. I can see the need for this special object as it includes additional metadata we want and need as part of a response from an AI service. At the same time, if the answer needs to be used by the application as part of subsequent prompts to maintain the conversation history (something that will probably be handled by Spring AI in the future), an explicit operation is needed to build an AssistantMessage object with information extracted from the Generation object.

The Generation object is returned as part of a ChatResponse with message type "Assistant". What's the relationship with AssistantMessage and can such relationship be made more explicit? For example, could Generation be a specialisation of AssistantMessage? Could Generation expose a method to return an AssistantMessage?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions