`ChatResponse.message` should have the same type as `ChatMessage`
Right now here is what we have
// ChatMessage
interface ChatMessage {
role: 'system' | 'assistant' | 'user' | 'function' | 'tool';
content: string | ContentObject[];
tool_call_id?: string;
}
...
interface ChatResponse {
message: {
role: string;
content: string;
tool_calls?: ToolCall[];
};
}
the difference in type causes intellisense to throw error
Type '{ role: string; content: string; tool_calls?: ToolCall[] | undefined; }' is not assignable to type 'ChatMessage'.
Types of property 'role' are incompatible.
Type 'string' is not assignable to type '"function" | "user" | "system" | "assistant" | "tool"'.ts(2322)
For now the quick fix in user's end is to type cast it, but we should probably fix on our lib
This is in the context of getting the chat response, and feeding it back into the conversation array
If I'm understanding this correctly you basically just want
interface ChatResponse {
message: ChatMessage
}
right?
could you provide test code in typescript that should work under ideal conditions?
hi @ProgrammerIn-wonderland , not sure how i missed this issue
If I'm understanding this correctly you basically just want
yes that's right, ideally it's the same type so appending it inside the ChatMessage[] list just works without type casting
this is the sample typescript code, similar to what i'm doing, the ChatResponse.message i have to typecast it as ChatMessage
let response: ChatResponse = {
message: {
role: "system",
content: "hehe",
},
};
const prevMessages: ChatMessage[] = [];
const newMessages: ChatMessage[] = [
...prevMessages,
// response.message, // this is broken without typecasting
response.message as ChatMessage,
];
feel free to let me know if you need more detail