chatgpt-api/src/types.ts

163 wiersze
2.9 KiB
TypeScript
Czysty Zwykły widok Historia

import type * as openai from 'openai'
export { openai }
export type Role = 'user' | 'assistant' | 'system'
2022-12-05 05:13:36 +00:00
export type FetchFn = typeof fetch
2022-12-07 00:19:30 +00:00
export type SendMessageOptions = {
/** The name of a user in a multi-user chat. */
name?: string
2022-12-07 00:19:30 +00:00
parentMessageId?: string
messageId?: string
stream?: boolean
systemMessage?: string
2022-12-07 04:07:14 +00:00
timeoutMs?: number
onProgress?: (partialResponse: ChatMessage) => void
2022-12-07 00:19:30 +00:00
abortSignal?: AbortSignal
}
2023-02-19 07:56:19 +00:00
export type MessageActionType = 'next' | 'variant'
export type SendMessageBrowserOptions = {
conversationId?: string
parentMessageId?: string
messageId?: string
action?: MessageActionType
timeoutMs?: number
onProgress?: (partialResponse: ChatMessage) => void
abortSignal?: AbortSignal
}
export interface ChatMessage {
id: string
text: string
role: Role
name?: string
delta?: string
detail?: any
// relevant for both ChatGPTAPI and ChatGPTUnofficialProxyAPI
parentMessageId?: string
// only relevant for ChatGPTUnofficialProxyAPI
conversationId?: string
}
export class ChatGPTError extends Error {
statusCode?: number
statusText?: string
2023-02-19 07:56:19 +00:00
isFinal?: boolean
accountId?: string
}
/** Returns a chat message from a store by it's ID (or null if not found). */
export type GetMessageByIdFunction = (id: string) => Promise<ChatMessage>
/** Upserts a chat message to a store. */
export type UpsertMessageFunction = (message: ChatMessage) => Promise<void>
2023-02-19 07:56:19 +00:00
/**
* https://chat.openapi.com/backend-api/conversation
*/
export type ConversationJSONBody = {
/**
* The action to take
*/
action: string
/**
* The ID of the conversation
*/
conversation_id?: string
/**
* Prompts to provide
*/
messages: Prompt[]
/**
* The model to use
*/
model: string
/**
* The parent message ID
*/
parent_message_id: string
}
export type Prompt = {
/**
* The content of the prompt
*/
content: PromptContent
/**
* The ID of the prompt
*/
id: string
/**
* The role played in the prompt
*/
role: Role
}
export type ContentType = 'text'
export type PromptContent = {
/**
* The content type of the prompt
*/
content_type: ContentType
/**
* The parts to the prompt
*/
parts: string[]
}
export type ConversationResponseEvent = {
message?: Message
conversation_id?: string
error?: string | null
}
export type Message = {
id: string
content: MessageContent
role: Role
user: string | null
create_time: string | null
update_time: string | null
end_turn: null
weight: number
recipient: string
metadata: MessageMetadata
}
export type MessageContent = {
content_type: string
parts: string[]
}
export type MessageMetadata = any
export interface CreateChatCompletionDeltaResponse {
id: string
object: 'chat.completion.chunk'
created: number
model: string
choices: [
{
delta: {
role: Role
content?: string
}
index: number
finish_reason: string | null
}
]
}