Skip to content

Generic Messages #1180

Closed
Closed
@peterje

Description

@peterje

Feature Description

A generic message type allows consumers of the API to include domain-specific data on their Messages with type-safety. The current solution either require creating a custom .d.ts definition of Message or abusing the annotations field.

I propose exporting a generic Message in place of the current Message interface as follows.

type CustomFields = Record<string, JSONValue>;
export type Message<T extends CustomFields = {}> = MessageBase & T;

APIs and hooks which consume Message should be generic as well. For example,

const {append} = useChat<{filePath: string}>()
append({
  role: "user",
  content: "what is the meaning of life",
  filePath: "/files/uploaded/hitchhiker.pdf"
})

should be possible.

Use Case

The content of a message is typically just one piece of a complex LLM solution. Documents, requestIDs, and third-party tracking IDs are common requirements.

Additional context

Tagging @shuding as we briefly discussed this earlier today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions