hmarr / openai-chat-tokens

💬 Estimate the number of tokens an OpenAI chat completion will use
MIT License
89 stars 12 forks source link

Update OpenAI types #8

Closed finom closed 1 year ago

finom commented 1 year ago

Great job! Looks like the library uses old (I guess) TypeScript namespace types from OpenAI:

type Message = OpenAI.Chat.CompletionCreateParams.CreateChatCompletionRequestNonStreaming.Message;
type Function = OpenAI.Chat.CompletionCreateParams.CreateChatCompletionRequestNonStreaming.Function;

But now they export individual interfaces.

export interface ChatCompletionRequestMessage {
    /**
     * The role of the messages author. One of `system`, `user`, `assistant`, or `function`.
     * @type {string}
     * @memberof ChatCompletionRequestMessage
     */
    'role': ChatCompletionRequestMessageRoleEnum;
    /**
     * The contents of the message. `content` is required for all messages except assistant messages with function calls.
     * @type {string}
     * @memberof ChatCompletionRequestMessage
     */
    'content'?: string;
    /**
     * The name of the author of this message. `name` is required if role is `function`, and it should be the name of the function whose response is in the `content`. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters.
     * @type {string}
     * @memberof ChatCompletionRequestMessage
     */
    'name'?: string;
    /**
     *
     * @type {ChatCompletionRequestMessageFunctionCall}
     * @memberof ChatCompletionRequestMessage
     */
    'function_call'?: ChatCompletionRequestMessageFunctionCall;
}
kenfdev commented 1 year ago

I think the following types correspond to the original types 👀

type Message = Completions.CreateChatCompletionRequestMessage;
type Function = Completions.CompletionCreateParams.Function;
hmarr commented 1 year ago

Thanks, fixed by https://github.com/hmarr/openai-chat-tokens/commit/1ce17fa6b3df1446c1cf0ebcb09b1d64a77a383e. Released in v0.2.6.