/** * Qwen API Client Module * * Handles communication with Alibaba Cloud DashScope Qwen API. * Uses OpenAI-compatible chat completions endpoint. */ import type { Logger, Base64Data, LLMResponse } from '../../llm_api/types.js'; /** * Qwen generation configuration parameters * Maps to OpenAI-compatible parameters */ export interface QwenGenerationConfig { /** Controls randomness in output (0.0-2.0). Lower = more deterministic */ temperature?: number; /** Maximum number of tokens in the response */ max_tokens?: number; /** Top-p sampling (nucleus sampling) */ top_p?: number; /** Top-k sampling */ top_k?: number; /** Number of completion choices to generate */ n?: number; /** Stop sequences */ stop?: string[]; /** Presence penalty */ presence_penalty?: number; /** Frequency penalty */ frequency_penalty?: number; } /** * Qwen API message role */ export type QwenMessageRole = 'system' | 'user' | 'assistant'; /** * Qwen API message */ export interface QwenMessage { role: QwenMessageRole; content: string | Array<{ type: 'text' | 'image_url'; text?: string; image_url?: { url: string; }; }>; } /** * Qwen API request body */ export interface QwenApiRequest { model: string; messages: QwenMessage[]; temperature?: number; max_tokens?: number; top_p?: number; top_k?: number; n?: number; stop?: string[]; presence_penalty?: number; frequency_penalty?: number; result_format?: 'message' | 'text'; stream?: boolean; } /** * Qwen API response choice */ export interface QwenChoice { index: number; message: { role: string; content: string; }; finish_reason: string; } /** * Qwen API response */ export interface QwenApiResponse { id?: string; object?: string; created?: number; model?: string; choices?: QwenChoice[]; usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number; }; error?: { message: string; type: string; code?: string; }; } /** * Call the Qwen API with messages and optional image data * @param api_url - The Qwen API endpoint URL * @param api_key - The API key for authentication * @param model - The model name to use * @param messages - Array of messages (system + user) * @param logger - Logger instance * @param generation_config - Optional generation configuration parameters * @returns LLM response with generated text or error */ export declare function call_qwen_api(api_url: string, api_key: string, model: string, messages: QwenMessage[], logger: Logger, generation_config?: QwenGenerationConfig): Promise; /** * Get the default Qwen API URL * @returns The default DashScope API URL */ export declare function get_qwen_api_url(): string; /** * Get the DashScope image generation API URL * @param model - The model name (e.g., qwen-image-plus) * @returns The DashScope image generation API URL */ export declare function get_qwen_image_api_url(model?: string): string; /** * Get the DashScope image editing API URL * @param model - The model name (e.g., qwen-image-edit) * @returns The DashScope image editing API URL */ export declare function get_qwen_image_edit_api_url(model?: string): string; /** * Build Qwen messages array from prompt and optional images * @param prompt - The text prompt * @param system_instruction - Optional system instruction * @param b64_data - Optional array of base64 encoded images * @returns Array of Qwen messages */ export declare function build_qwen_messages(prompt: string, system_instruction?: string, b64_data?: Base64Data[]): QwenMessage[]; /** * Call the DashScope image generation API * @param api_url - The DashScope image generation API endpoint URL * @param api_key - The API key for authentication * @param model - The model name to use (e.g., qwen-image-plus) * @param prompt - The text prompt for image generation * @param logger - Logger instance * @param generation_config - Optional generation configuration parameters * @returns LLM response with generated image or error */ export declare function call_qwen_image_api(api_url: string, api_key: string, model: string, prompt: string, logger: Logger, generation_config?: QwenGenerationConfig): Promise; /** * Call the DashScope image editing API * @param api_url - The DashScope image editing API endpoint URL * @param api_key - The API key for authentication * @param model - The model name to use (e.g., qwen-image-edit) * @param prompt - The text prompt describing the transformation * @param input_images - Array of base64 encoded input images with mime types (1-3 images supported) * @param logger - Logger instance * @param generation_config - Optional generation configuration parameters * @returns LLM response with edited image or error */ export declare function call_qwen_image_edit_api(api_url: string, api_key: string, model: string, prompt: string, input_images: Base64Data[], logger: Logger, generation_config?: QwenGenerationConfig): Promise; //# sourceMappingURL=qwen_client.d.ts.map