Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Messages #1180

Open
peterje opened this issue Mar 19, 2024 · 1 comment
Open

Generic Messages #1180

peterje opened this issue Mar 19, 2024 · 1 comment

Comments

@peterje
Copy link

peterje commented Mar 19, 2024

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.

@polooner
Copy link

need this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants