Spaces:
Sleeping
Sleeping
File size: 3,047 Bytes
c6dedd5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | // ==================== OpenAI API Types ====================
export interface OpenAIChatRequest {
model: string;
messages: OpenAIMessage[];
stream?: boolean;
stream_options?: { include_usage?: boolean };
temperature?: number;
top_p?: number;
max_tokens?: number;
max_completion_tokens?: number;
tools?: OpenAITool[];
tool_choice?: string | { type: string; function?: { name: string } };
stop?: string | string[];
n?: number;
frequency_penalty?: number;
presence_penalty?: number;
response_format?: {
type: 'text' | 'json_object' | 'json_schema';
json_schema?: { name?: string; schema?: Record<string, unknown> };
};
}
export interface OpenAIMessage {
role: 'system' | 'user' | 'assistant' | 'tool';
content: string | OpenAIContentPart[] | null;
name?: string;
// assistant tool_calls
tool_calls?: OpenAIToolCall[];
// tool result
tool_call_id?: string;
}
export interface OpenAIContentPart {
type: 'text' | 'input_text' | 'image_url' | 'image' | 'input_image' | 'image_file';
text?: string;
image_url?: { url: string; detail?: string };
image_file?: { file_id: string; detail?: string };
// Anthropic-style image source (when type === 'image')
source?: { type: string; media_type?: string; data?: string; url?: string };
}
export interface OpenAITool {
type: 'function';
function: {
name: string;
description?: string;
parameters?: Record<string, unknown>;
};
}
export interface OpenAIToolCall {
id: string;
type: 'function';
function: {
name: string;
arguments: string;
};
}
// ==================== OpenAI Response Types ====================
export interface OpenAIChatCompletion {
id: string;
object: 'chat.completion';
created: number;
model: string;
choices: OpenAIChatChoice[];
usage: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
}
export interface OpenAIChatChoice {
index: number;
message: {
role: 'assistant';
content: string | null;
tool_calls?: OpenAIToolCall[];
};
finish_reason: 'stop' | 'tool_calls' | 'length' | null;
}
// ==================== OpenAI Stream Types ====================
export interface OpenAIChatCompletionChunk {
id: string;
object: 'chat.completion.chunk';
created: number;
model: string;
choices: OpenAIStreamChoice[];
usage?: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
}
export interface OpenAIStreamChoice {
index: number;
delta: {
role?: 'assistant';
content?: string | null;
tool_calls?: OpenAIStreamToolCall[];
};
finish_reason: 'stop' | 'tool_calls' | 'length' | null;
}
export interface OpenAIStreamToolCall {
index: number;
id?: string;
type?: 'function';
function: {
name?: string;
arguments: string;
};
}
|