UNPKG

@genkit-ai/anthropic

Version:

Genkit AI framework plugin for Anthropic APIs.

53 lines (49 loc) 3.16 kB
import { MessageStream } from '@anthropic-ai/sdk/lib/MessageStream.js'; import { Message, MessageStreamEvent, MessageCreateParamsNonStreaming, MessageCreateParamsStreaming, Tool, MessageParam, TextBlockParam, ImageBlockParam, DocumentBlockParam, ToolUseBlockParam, ToolResultBlockParam, ThinkingBlockParam, RedactedThinkingBlockParam, ContentBlock } from '@anthropic-ai/sdk/resources/messages'; import { Part, GenerateRequest, GenerateResponseData, ModelResponseData } from 'genkit'; import { ClaudeRunnerParams, AnthropicConfigSchema } from '../types.mjs'; import { BaseRunner } from './base.mjs'; import { RunnerTypes as RunnerTypes$1 } from './types.mjs'; import '@anthropic-ai/sdk'; import 'genkit/model'; /** * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ interface RunnerTypes extends RunnerTypes$1 { Message: Message; Stream: MessageStream; StreamEvent: MessageStreamEvent; RequestBody: MessageCreateParamsNonStreaming; StreamingRequestBody: MessageCreateParamsStreaming; Tool: Tool; MessageParam: MessageParam; ToolResponseContent: TextBlockParam | ImageBlockParam; ContentBlockParam: TextBlockParam | ImageBlockParam | DocumentBlockParam | ToolUseBlockParam | ToolResultBlockParam | ThinkingBlockParam | RedactedThinkingBlockParam; } declare class Runner extends BaseRunner<RunnerTypes> { constructor(params: ClaudeRunnerParams); protected toAnthropicMessageContent(part: Part): TextBlockParam | ImageBlockParam | DocumentBlockParam | ToolUseBlockParam | ToolResultBlockParam | ThinkingBlockParam | RedactedThinkingBlockParam; protected toAnthropicRequestBody(modelName: string, request: GenerateRequest<typeof AnthropicConfigSchema>): MessageCreateParamsNonStreaming; protected toAnthropicStreamingRequestBody(modelName: string, request: GenerateRequest<typeof AnthropicConfigSchema>): MessageCreateParamsStreaming; protected createMessage(body: MessageCreateParamsNonStreaming, abortSignal: AbortSignal): Promise<Message>; protected streamMessages(body: MessageCreateParamsStreaming, abortSignal: AbortSignal): MessageStream; protected toGenkitResponse(message: Message): GenerateResponseData; protected toGenkitPart(event: MessageStreamEvent): Part | undefined; protected fromAnthropicContentBlockChunk(event: MessageStreamEvent): Part | undefined; protected fromAnthropicContentBlock(contentBlock: ContentBlock): Part; protected fromAnthropicStopReason(reason: Message['stop_reason']): ModelResponseData['finishReason']; protected fromAnthropicResponse(response: Message): GenerateResponseData; } export { Runner };