langchain.js
    Preparing search index...

    Variable convertStandardContentBlockToCompletionsContentPartConst

    convertStandardContentBlockToCompletionsContentPart: BaseDynamicToolInput<
        ContentBlock.Standard,
        | OpenAIClient.Chat.Completions.ChatCompletionContentPartImage
        | OpenAIClient.Chat.Completions.ChatCompletionContentPartInputAudio
        | OpenAIClient.Chat.Completions.ChatCompletionContentPart.File
        | undefined,
    > = ...

    Converts a standard LangChain content block to an OpenAI Completions API content part.

    This converter transforms LangChain's standardized content blocks (image, audio, file) into the format expected by OpenAI's Chat Completions API. It handles various content types including images (URL or base64), audio (base64), and files (data or file ID).

    The standard content block to convert. Can be an image, audio, or file block.

    An OpenAI Chat Completions content part object, or undefined if the block cannot be converted (e.g., missing required data).

    Image with URL:

    const block = { type: "image", url: "https://example.com/image.jpg" };
    const part = convertStandardContentBlockToCompletionsContentPart(block);
    // Returns: { type: "image_url", image_url: { url: "https://example.com/image.jpg" } }

    Image with base64 data:

    const block = { type: "image", data: "iVBORw0KGgo...", mimeType: "image/png" };
    const part = convertStandardContentBlockToCompletionsContentPart(block);
    // Returns: { type: "image_url", image_url: { url: "data:image/png;base64,iVBORw0KGgo..." } }