@aituber-onair/core
Version:
Core library for AITuber OnAir providing voice synthesis and chat processing
108 lines (107 loc) • 4.07 kB
TypeScript
import { ChatService } from '../../ChatService';
import { Message, MessageWithVision } from '../../../../types';
import { ToolDefinition, ToolChatCompletion } from '../../../../types';
import { MCPServerConfig } from '../../../../types';
/**
* OpenAI implementation of ChatService
*/
export declare class OpenAIChatService implements ChatService {
/** Provider name */
readonly provider: string;
private apiKey;
private model;
private visionModel;
private tools;
private endpoint;
private mcpServers;
/**
* Constructor
* @param apiKey OpenAI API key
* @param model Name of the model to use
* @param visionModel Name of the vision model
*/
constructor(apiKey: string, model?: string, visionModel?: string, tools?: ToolDefinition[], endpoint?: string, mcpServers?: MCPServerConfig[]);
/**
* Get the current model name
* @returns Model name
*/
getModel(): string;
/**
* Get the current vision model name
* @returns Vision model name
*/
getVisionModel(): string;
/**
* Process chat messages
* @param messages Array of messages to send
* @param onPartialResponse Callback to receive each part of streaming response
* @param onCompleteResponse Callback to execute when response is complete
*/
processChat(messages: Message[], onPartialResponse: (text: string) => void, onCompleteResponse: (text: string) => Promise<void>): Promise<void>;
/**
* Process chat messages with images
* @param messages Array of messages to send (including images)
* @param onPartialResponse Callback to receive each part of streaming response
* @param onCompleteResponse Callback to execute when response is complete
* @throws Error if the selected model doesn't support vision
*/
processVisionChat(messages: MessageWithVision[], onPartialResponse: (text: string) => void, onCompleteResponse: (text: string) => Promise<void>): Promise<void>;
/**
* Process chat messages with tools (text only)
* @param messages Array of messages to send
* @param stream Whether to use streaming
* @param onPartialResponse Callback for partial responses
* @param maxTokens Maximum tokens for response (optional)
* @returns Tool chat completion
*/
chatOnce(messages: Message[], stream?: boolean, onPartialResponse?: (text: string) => void, maxTokens?: number): Promise<ToolChatCompletion>;
/**
* Process vision chat messages with tools
* @param messages Array of messages to send (including images)
* @param stream Whether to use streaming
* @param onPartialResponse Callback for partial responses
* @param maxTokens Maximum tokens for response (optional)
* @returns Tool chat completion
*/
visionChatOnce(messages: MessageWithVision[], stream?: boolean, onPartialResponse?: (text: string) => void, maxTokens?: number): Promise<ToolChatCompletion>;
/**
* Parse response based on endpoint type
*/
private parseResponse;
private callOpenAI;
/**
* Build request body based on the endpoint type
*/
private buildRequestBody;
/**
* Validate MCP servers compatibility with the current endpoint
*/
private validateMCPCompatibility;
/**
* Clean messages for Responses API (remove timestamp and other extra properties)
*/
private cleanMessagesForResponsesAPI;
/**
* Build tools definition based on the endpoint type
*/
private buildToolsDefinition;
/**
* Build MCP tools definition for Responses API
*/
private buildMCPToolsDefinition;
private handleStream;
private parseStream;
private parseOneShot;
/**
* Parse streaming response from Responses API (SSE format)
*/
private parseResponsesStream;
/**
* Handle specific SSE events from Responses API
*/
private handleResponsesSSEEvent;
/**
* Parse non-streaming response from Responses API
*/
private parseResponsesOneShot;
}