ChatMessage[] TypeScript warning
Closed this issue ยท 3 comments
thdoan commented
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 commented
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 commented
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
github-actions commented
๐ This issue has been resolved in version 2.2.1 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐