I’m using the chat playground to test and debug my prompts and values to use but when I copy the nodejs code example from the playground and use it in my typescript application I get the following errors that prevent the application from starting
No overload matches this call.
Overload 3 of 3, '(body: ChatCompletionCreateParamsBase, options?: RequestOptions<unknown> | undefined): APIPromise<ChatCompletion | Stream<...>>', gave the following error.
Type '{ type: string; text: string; }[]' is not assignable to type 'string | ChatCompletionContentPart[] | null | undefined'.
Type '{ type: string; text: string; }' is not assignable to type 'ChatCompletionContentPart'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"text" | "image_url"'.
Overload 3 of 3, '(body: ChatCompletionCreateParamsBase, options?: RequestOptions<unknown> | undefined): APIPromise<ChatCompletion | Stream<...>>', gave the following error.
Type '{ type: string; text: string; }[]' is not assignable to type 'string | ChatCompletionContentPart[] | null | undefined'.
Type '{ type: string; text: string; }' is not assignable to type 'ChatCompletionContentPart'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"text" | "image_url"'.
Overload 3 of 3, '(body: ChatCompletionCreateParamsBase, options?: RequestOptions<unknown> | undefined): APIPromise<ChatCompletion | Stream<...>>', gave the following error.
Type '{ type: string; text: string; }[]' is not assignable to type 'string | ChatCompletionContentPart[] | null | undefined'.
Type '{ type: string; text: string; }' is not assignable to type 'ChatCompletionContentPart'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"text" | "image_url"'.ts(2769)
completions.d.ts(449, 5): The expected type comes from property 'content' which is declared here on type 'ChatCompletionMessageParam'
completions.d.ts(449, 5): The expected type comes from property 'content' which is declared here on type 'ChatCompletionMessageParam'
completions.d.ts(449, 5): The expected type comes from property 'content' which is declared here on type 'ChatCompletionMessageParam'
After checking the type of each property one by one I noticed that this is because if the role of the message is “system” the type required for the content property is strictly a string
If the role is “assistant” the type for content is also required to be a string, null or undefined but not an array of objects as the ones provided by the playground
The arrays provided in playground are only accepted as a content value for the “user” role
This doesn’t affect regular JS application as they don’t require types but it’s very annoying to copy the exact example given and not being able to use it out of the box in typescript
I’m using the latest version of the api “openai”: “^4.47.1”