Cloudflare - v1.3.0
    Preparing search index...

    Class AIService<E>

    Inference capability, backed by Workers AI.

    Which model answers a prompt is configuration, not business logic: callers ask for text and get text. Override ai.model in config/AIConfig.ts to change it everywhere at once, or name a model per call when one task genuinely needs a different one.

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Type Parameters

    Implements

    • InferenceEngine<E>
    Index
    • Answers a prompt with the configured model.

      Parameters

      • env: E

        The Worker environment.

      • prompt: string

        The prompt to send.

      • Optionalmodel: string

        Model to run. Falls back to the configured model.

      Returns Promise<string>

      The generated text.

    • Embeds text as a vector.

      Parameters

      • env: E

        The Worker environment.

      • text: string

        The text to embed.

      • model: string = '@cf/baai/bge-base-en-v1.5'

        Embedding model to run.

      Returns Promise<number[]>

      The embedding.

    • Reports whether Workers AI is bound to this Worker.

      Parameters

      • env: E

        The Worker environment.

      Returns boolean

      true when the binding is present.

    • Returns the AI Gateway log id of the most recent call.

      Useful for correlating a response with its gateway log entry.

      Parameters

      • env: E

        The Worker environment.

      Returns string

      The log id, or null when the call was not routed through a gateway.