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

ChatMessage[] TypeScript warning #36

Open
thdoan opened this issue Oct 17, 2023 · 2 comments
Open

ChatMessage[] TypeScript warning #36

thdoan opened this issue Oct 17, 2023 · 2 comments

Comments

@thdoan
Copy link

thdoan commented Oct 17, 2023

I tried to follow sample usage, but the line encodeChat(messages) is returning this warning in VS Code:

[{
        ...
	"message": "Argument of type '{ role: string; content: string; }[]' is not assignable to parameter of type 'readonly ChatMessage[]'.\n  Type '{ role: string; content: string; }' is not assignable to type 'ChatMessage'.\n    Types of property 'role' are incompatible.\n      Type 'string' is not assignable to type '\"system\" | \"user\" | \"assistant\" | undefined'.",
        ...
}]

How do I make this work without TypeScript warnings?

@thdoan
Copy link
Author

thdoan commented Oct 17, 2023

I ended up defining my own type, but I still think this should be included in instructions:

export type ChatMessage = {
  role: 'assistant' | 'system' | 'user' | undefined;
  content: string;
};

@henrymcl
Copy link

henrymcl commented Apr 5, 2024

Owner please consider updating the documentation to either one of these:

const chat = [
  { role: 'system' as const , content: 'You are a helpful assistant.' },
  { role: 'assistant' as const, content: 'gpt-tokenizer is awesome.' },
]
const chat = [
  { role: 'system' , content: 'You are a helpful assistant.' },
  { role: 'assistant', content: 'gpt-tokenizer is awesome.' },
] as const

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