Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ Upgrade types #828

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 48 additions & 23 deletions packages/tasks/src/tasks/chat-completion/inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface ChatCompletionInput {
* [UNUSED] ID of the model to use. See the model endpoint compatibility table for details
* on which models work with the Chat API.
*/
model: string;
model?: string;
/**
* UNUSED
* How many chat completion choices to generate for each input message. Note that you will
Expand All @@ -63,6 +63,7 @@ export interface ChatCompletionInput {
* increasing the model's likelihood to talk about new topics
*/
presence_penalty?: number;
response_format?: ChatCompletionInputGrammarType;
seed?: number;
/**
* Up to 4 sequences where the API will stop generating further tokens.
Expand All @@ -77,7 +78,7 @@ export interface ChatCompletionInput {
* We generally recommend altering this or `top_p` but not both.
*/
temperature?: number;
tool_choice?: ChatCompletionInputToolType;
tool_choice?: ChatCompletionInputTool;
/**
* A prompt to be appended before the tools
*/
Expand All @@ -87,7 +88,7 @@ export interface ChatCompletionInput {
* Use this to provide a list of
* functions the model may generate JSON inputs for.
*/
tools?: ChatCompletionInputTool[];
tools?: ToolElement[];
/**
* An integer between 0 and 5 specifying the number of most likely tokens to return at each
* token position, each with
Expand All @@ -105,40 +106,67 @@ export interface ChatCompletionInput {
}

export interface ChatCompletionInputMessage {
content?: string;
content: ChatCompletionInputMessageContent;
name?: string;
role: string;
tool_calls?: ChatCompletionInputToolCall[];
[property: string]: unknown;
}

export interface ChatCompletionInputToolCall {
function: ChatCompletionInputFunctionDefinition;
id: number;
type: string;
export type ChatCompletionInputMessageContent = ChatCompletionInputMessageChunk[] | string;

export interface ChatCompletionInputMessageChunk {
image_url?: ChatCompletionInputURL;
text?: string;
type: ChatCompletionInputMessageChunkType;
[property: string]: unknown;
}

export interface ChatCompletionInputFunctionDefinition {
arguments: unknown;
description?: string;
name: string;
export interface ChatCompletionInputURL {
url: string;
[property: string]: unknown;
}

export type ChatCompletionInputMessageChunkType = "text" | "image_url";

export interface ChatCompletionInputGrammarType {
type: ChatCompletionInputGrammarTypeType;
/**
* A string that represents a [JSON Schema](https://json-schema.org/).
*
* JSON Schema is a declarative language that allows to annotate JSON documents
* with types and descriptions.
*/
value: unknown;
[property: string]: unknown;
}

export type ChatCompletionInputToolType = "OneOf" | ChatCompletionInputToolTypeObject;
export type ChatCompletionInputGrammarTypeType = "json" | "regex";

export type ChatCompletionInputTool = ChatCompletionInputToolType | string;

export interface ChatCompletionInputToolType {
function?: ChatCompletionInputFunctionName;
[property: string]: unknown;
}

export interface ChatCompletionInputToolTypeObject {
FunctionName: string;
export interface ChatCompletionInputFunctionName {
name: string;
[property: string]: unknown;
}

export interface ChatCompletionInputTool {
export interface ToolElement {
function: ChatCompletionInputFunctionDefinition;
type: string;
[property: string]: unknown;
}

export interface ChatCompletionInputFunctionDefinition {
arguments: unknown;
description?: string;
name: string;
[property: string]: unknown;
}

/**
* Chat Completion Output.
*
Expand All @@ -151,7 +179,6 @@ export interface ChatCompletionOutput {
created: number;
id: string;
model: string;
object: string;
system_fingerprint: string;
usage: ChatCompletionOutputUsage;
[property: string]: unknown;
Expand All @@ -161,7 +188,7 @@ export interface ChatCompletionOutputComplete {
finish_reason: string;
index: number;
logprobs?: ChatCompletionOutputLogprobs;
message: ChatCompletionOutputMessage;
message: ChatCompletionOutputOutputMessage;
[property: string]: unknown;
}

Expand All @@ -183,17 +210,16 @@ export interface ChatCompletionOutputTopLogprob {
[property: string]: unknown;
}

export interface ChatCompletionOutputMessage {
export interface ChatCompletionOutputOutputMessage {
content?: string;
name?: string;
role: string;
tool_calls?: ChatCompletionOutputToolCall[];
[property: string]: unknown;
}

export interface ChatCompletionOutputToolCall {
function: ChatCompletionOutputFunctionDefinition;
id: number;
id: string;
type: string;
[property: string]: unknown;
}
Expand Down Expand Up @@ -224,7 +250,6 @@ export interface ChatCompletionStreamOutput {
created: number;
id: string;
model: string;
object: string;
system_fingerprint: string;
[property: string]: unknown;
}
Expand Down
Loading
Loading