Skip to content

Commit

Permalink
feat: types update
Browse files Browse the repository at this point in the history
  • Loading branch information
TABmk committed Jun 21, 2023
1 parent 358811c commit 6433ab8
Showing 1 changed file with 83 additions and 16 deletions.
99 changes: 83 additions & 16 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,66 @@ import { RequestInit } from 'node-fetch';
/** Message in {@link https://platform.openai.com/docs/guides/chat/introduction chat format} */
export type Message = {
/**
* The system message helps set the behavior of the assistant. In the example above,
* the assistant was instructed with “You are a helpful assistant.”
* _Required_
*
* The role of the messages author.
* {@link https://platform.openai.com/docs/guides/gpt/chat-completions-api Read more }
*/
role: 'system' | 'user' | 'assistant' | 'function';
/**
* _Optional_
*
* The contents of the message. `content` is required for all messages
* except assistant messages with function calls.
*/
content?: string;
/**
* _Optional_
*
* The name of the author of this message.
*
* The user messages help instruct the assistant. They can be generated
* by the end users of an application, or set by a developer as an instruction.
* `name` is required if role is `function`, and it should be the name of the function
* whose response is in the `content`.
*
* The assistant messages help store prior responses.
* They can also be written by a developer to help give examples of desired behavior.
* May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters.
*/
role: 'system' | 'user' | 'assistant';
/** The content of the message */
content: string;
name?: string;
/**
* _Optional_
*
* The name and arguments of a function that should be called, as generated by the model.
*/
function_call?: object;
};
/**
* In an API call, you can describe functions to gpt-3.5-turbo-0613 and gpt-4-0613,
* and have the model intelligently choose to output a JSON object containing
* arguments to call those functions. The Chat Completions API does not call the function;
* instead, the model generates JSON that you can use to call the function in your code.
*
* {@link https://platform.openai.com/docs/guides/gpt/function-calling Read more}
*/
export type FunctionModel = {
/**
* _Required_
*
* The name of the function to be called.
* Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
*/
name: string;
/**
* _Optional_
*
* The description of what the function does.
*/
description?: string;
/**
* _Optional_
*
* The parameters the functions accepts, described as a JSON Schema object.
* See the {@link https://platform.openai.com/docs/guides/gpt/function-calling guide} for examples, and the {@link https://json-schema.org/understanding-json-schema/ JSON Schema reference} for documentation about the format.
*/
parameters?: object;
};
/** Request body */
export type ReqBody = {
Expand All @@ -23,13 +71,30 @@ export type ReqBody = {
*
* ID of the model to use. See the {@link https://platform.openai.com/docs/models/model-endpoint-compatibility model endpoint compatibility} table for details on which models work with the Chat API.
*/
model: 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-32k' | 'gpt-4-32k-0314';
model: 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0613';
/**
* _Required_
*
* The messages to generate chat completions for, in the {@link https://platform.openai.com/docs/guides/chat/introduction chat format}.
*/
messages: Array<Message>;
/**
* _Optional_
*
* A list of functions the model may generate JSON inputs for.
*/
functions?: Array<FunctionModel>;
/**
* _Optional_
*
* Controls how the model responds to function calls. "none" means the model does not
* call a function, and responds to the end-user.
* "auto" means the model can pick between an end-user or calling a function.
* Specifying a particular function via `{"name":\ "my_function"}`
* forces the model to call that function. "none" is the default when no functions are present.
* "auto" is the default if functions are present.
*/
function_call?: string | object;
/**
* _Optional. Defaults to 1_
*
Expand All @@ -46,7 +111,7 @@ export type ReqBody = {
* considers the results of the tokens with top_p probability mass. So 0.1 means only the
* tokens comprising the top 10% probability mass are considered.
*
* We generally recommend altering this or temperature but not both.
* We generally recommend altering this or `temperature` but not both.
*/
top_p?: number;
/**
Expand All @@ -70,8 +135,10 @@ export type ReqBody = {
/**
* _Optional. Defaults to inf_
*
* The maximum number of tokens allowed for the generated answer.
* By default, the number of tokens the model can return will be (4096 - prompt tokens).
* The maximum number of tokens to generate in the chat completion..
* The total length of input tokens and generated tokens is limited by the model's context length
*
* {@link https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb Example Python code} for counting tokens.
*/
max_tokens?: number;
/**
Expand Down Expand Up @@ -205,7 +272,7 @@ export declare class ChatGPT {
ORG: string | undefined;
URL: string;
MODEL: ReqBody['model'];
constructor({ API_KEY, ORG, MODEL, }: {
constructor({ API_KEY, ORG, URL, MODEL, }: {
/**
* The OpenAI API uses API keys for authentication.
* Visit your {@link https://platform.openai.com/account/api-keys API Keys} page to retrieve the API key you'll use in your requests.
Expand Down Expand Up @@ -234,7 +301,7 @@ export declare class ChatGPT {
/**
* ## .send(ReqBody | string, [RequestInit])
*
* Use this method to send request to ChatGPT API
* Use this method to send a request to ChatGPT API
*
* `RequestInit` is {@link https://www.npmjs.com/package/node-fetch#options node-fetch options}.
*
Expand All @@ -256,7 +323,7 @@ export declare class ChatGPT {
/**
* ## .stream(ReqBody | string, [RequestInit])
*
* Use this method to send request to ChatGPT API and get steam response back
* Use this method to send a request to ChatGPT API and get steam response back
*
* `RequestInit` is {@link https://www.npmjs.com/package/node-fetch#options node-fetch options}.
*
Expand Down

0 comments on commit 6433ab8

Please sign in to comment.