UNPKG

buroventures-harald-code-core

Version:

Harald Code Core - Core functionality for AI-powered coding assistant

88 lines (87 loc) 3.22 kB
/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { CountTokensResponse, GenerateContentResponse, GenerateContentParameters, CountTokensParameters, EmbedContentResponse, EmbedContentParameters } from '@google/genai'; import { ContentGenerator } from './contentGenerator.js'; import { Config } from '../config/config.js'; import { ApiKeyRotationManager } from './apiKeyRotationManager.js'; export declare class OpenAIContentGenerator implements ContentGenerator { private client; private model; private config; private rotationManager?; private streamingToolCalls; constructor(apiKey: string, model: string, config: Config, rotationManager?: ApiKeyRotationManager); /** * Create OpenAI client with given configuration */ private createClient; /** * Get current API key (from rotation manager or fallback) */ private getCurrentApiKey; /** * Recreate client with current API key */ private recreateClientWithCurrentKey; /** * Handle rate limit error and attempt key rotation */ private handleRateLimitWithRotation; /** * Check if an error is a timeout error */ private isTimeoutError; generateContent(request: GenerateContentParameters): Promise<GenerateContentResponse>; generateContentStream(request: GenerateContentParameters): Promise<AsyncGenerator<GenerateContentResponse>>; private streamGenerator; /** * Combine streaming responses for logging purposes */ private combineStreamResponsesForLogging; countTokens(request: CountTokensParameters): Promise<CountTokensResponse>; embedContent(request: EmbedContentParameters): Promise<EmbedContentResponse>; private convertGeminiParametersToOpenAI; private convertGeminiToolsToOpenAI; private convertToOpenAIFormat; /** * Clean up orphaned tool calls from message history to prevent OpenAI API errors */ private cleanOrphanedToolCalls; /** * Merge consecutive assistant messages to combine split text and tool calls */ private mergeConsecutiveAssistantMessages; private convertToGeminiFormat; private convertStreamChunkToGeminiFormat; /** * Build sampling parameters with clear priority: * 1. Config-level sampling parameters (highest priority) * 2. Request-level parameters (medium priority) * 3. Default values (lowest priority) */ private buildSamplingParameters; private mapFinishReason; /** * Convert Gemini request format to OpenAI chat completion format for logging */ private convertGeminiRequestToOpenAI; /** * Clean up orphaned tool calls for logging purposes */ private cleanOrphanedToolCallsForLogging; /** * Merge consecutive assistant messages to combine split text and tool calls for logging */ private mergeConsecutiveAssistantMessagesForLogging; /** * Convert Gemini response format to OpenAI chat completion format for logging */ private convertGeminiResponseToOpenAI; /** * Map Gemini finish reasons to OpenAI finish reasons */ private mapGeminiFinishReasonToOpenAI; }