@langchain/google-common 0.2.18 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +6 -6
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/auth.cjs +82 -116
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +46 -0
- package/dist/auth.d.cts.map +1 -0
- package/dist/auth.d.ts +41 -36
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +80 -110
- package/dist/auth.js.map +1 -0
- package/dist/chat_models.cjs +251 -466
- package/dist/chat_models.cjs.map +1 -0
- package/dist/chat_models.d.cts +98 -0
- package/dist/chat_models.d.cts.map +1 -0
- package/dist/chat_models.d.ts +87 -73
- package/dist/chat_models.d.ts.map +1 -0
- package/dist/chat_models.js +245 -457
- package/dist/chat_models.js.map +1 -0
- package/dist/connection.cjs +321 -466
- package/dist/connection.cjs.map +1 -0
- package/dist/connection.d.cts +109 -0
- package/dist/connection.d.cts.map +1 -0
- package/dist/connection.d.ts +98 -91
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +317 -459
- package/dist/connection.js.map +1 -0
- package/dist/embeddings.cjs +135 -186
- package/dist/embeddings.cjs.map +1 -0
- package/dist/embeddings.d.cts +44 -0
- package/dist/embeddings.d.cts.map +1 -0
- package/dist/embeddings.d.ts +38 -32
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/embeddings.js +133 -181
- package/dist/embeddings.js.map +1 -0
- package/dist/experimental/media.cjs +380 -482
- package/dist/experimental/media.cjs.map +1 -0
- package/dist/experimental/media.d.cts +198 -0
- package/dist/experimental/media.d.cts.map +1 -0
- package/dist/experimental/media.d.ts +190 -202
- package/dist/experimental/media.d.ts.map +1 -0
- package/dist/experimental/media.js +369 -468
- package/dist/experimental/media.js.map +1 -0
- package/dist/experimental/utils/media_core.cjs +403 -517
- package/dist/experimental/utils/media_core.cjs.map +1 -0
- package/dist/experimental/utils/media_core.d.cts +215 -0
- package/dist/experimental/utils/media_core.d.cts.map +1 -0
- package/dist/experimental/utils/media_core.d.ts +171 -165
- package/dist/experimental/utils/media_core.d.ts.map +1 -0
- package/dist/experimental/utils/media_core.js +395 -506
- package/dist/experimental/utils/media_core.js.map +1 -0
- package/dist/index.cjs +58 -27
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -11
- package/dist/index.js +13 -11
- package/dist/llms.cjs +157 -244
- package/dist/llms.cjs.map +1 -0
- package/dist/llms.d.cts +72 -0
- package/dist/llms.d.cts.map +1 -0
- package/dist/llms.d.ts +64 -54
- package/dist/llms.d.ts.map +1 -0
- package/dist/llms.js +154 -238
- package/dist/llms.js.map +1 -0
- package/dist/output_parsers.cjs +148 -173
- package/dist/output_parsers.cjs.map +1 -0
- package/dist/output_parsers.d.cts +53 -0
- package/dist/output_parsers.d.cts.map +1 -0
- package/dist/output_parsers.d.ts +46 -42
- package/dist/output_parsers.d.ts.map +1 -0
- package/dist/output_parsers.js +146 -168
- package/dist/output_parsers.js.map +1 -0
- package/dist/types-anthropic.d.cts +229 -0
- package/dist/types-anthropic.d.cts.map +1 -0
- package/dist/types-anthropic.d.ts +221 -215
- package/dist/types-anthropic.d.ts.map +1 -0
- package/dist/types.cjs +51 -62
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +748 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +669 -656
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +46 -45
- package/dist/types.js.map +1 -0
- package/dist/utils/anthropic.cjs +598 -821
- package/dist/utils/anthropic.cjs.map +1 -0
- package/dist/utils/anthropic.js +597 -818
- package/dist/utils/anthropic.js.map +1 -0
- package/dist/utils/common.cjs +130 -211
- package/dist/utils/common.cjs.map +1 -0
- package/dist/utils/common.d.cts +13 -0
- package/dist/utils/common.d.cts.map +1 -0
- package/dist/utils/common.d.ts +12 -7
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js +128 -207
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/failed_handler.cjs +28 -30
- package/dist/utils/failed_handler.cjs.map +1 -0
- package/dist/utils/failed_handler.d.cts +9 -0
- package/dist/utils/failed_handler.d.cts.map +1 -0
- package/dist/utils/failed_handler.d.ts +8 -2
- package/dist/utils/failed_handler.d.ts.map +1 -0
- package/dist/utils/failed_handler.js +28 -28
- package/dist/utils/failed_handler.js.map +1 -0
- package/dist/utils/gemini.cjs +1020 -1488
- package/dist/utils/gemini.cjs.map +1 -0
- package/dist/utils/gemini.d.cts +51 -0
- package/dist/utils/gemini.d.cts.map +1 -0
- package/dist/utils/gemini.d.ts +51 -48
- package/dist/utils/gemini.d.ts.map +1 -0
- package/dist/utils/gemini.js +1015 -1479
- package/dist/utils/gemini.js.map +1 -0
- package/dist/utils/index.cjs +38 -23
- package/dist/utils/index.d.cts +8 -0
- package/dist/utils/index.d.ts +8 -7
- package/dist/utils/index.js +8 -7
- package/dist/utils/palm.d.cts +11 -0
- package/dist/utils/palm.d.cts.map +1 -0
- package/dist/utils/palm.d.ts +9 -4
- package/dist/utils/palm.d.ts.map +1 -0
- package/dist/utils/safety.cjs +13 -22
- package/dist/utils/safety.cjs.map +1 -0
- package/dist/utils/safety.d.cts +12 -0
- package/dist/utils/safety.d.cts.map +1 -0
- package/dist/utils/safety.d.ts +10 -4
- package/dist/utils/safety.d.ts.map +1 -0
- package/dist/utils/safety.js +13 -19
- package/dist/utils/safety.js.map +1 -0
- package/dist/utils/stream.cjs +296 -475
- package/dist/utils/stream.cjs.map +1 -0
- package/dist/utils/stream.d.cts +165 -0
- package/dist/utils/stream.d.cts.map +1 -0
- package/dist/utils/stream.d.ts +156 -131
- package/dist/utils/stream.d.ts.map +1 -0
- package/dist/utils/stream.js +293 -469
- package/dist/utils/stream.js.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.cjs +43 -81
- package/dist/utils/zod_to_gemini_parameters.cjs.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.d.cts +22 -0
- package/dist/utils/zod_to_gemini_parameters.d.cts.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.d.ts +21 -6
- package/dist/utils/zod_to_gemini_parameters.d.ts.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.js +40 -76
- package/dist/utils/zod_to_gemini_parameters.js.map +1 -0
- package/package.json +69 -85
- package/dist/types-anthropic.cjs +0 -2
- package/dist/types-anthropic.js +0 -1
- package/dist/utils/anthropic.d.ts +0 -4
- package/dist/utils/palm.cjs +0 -2
- package/dist/utils/palm.js +0 -1
- package/experimental/media.cjs +0 -1
- package/experimental/media.d.cts +0 -1
- package/experimental/media.d.ts +0 -1
- package/experimental/media.js +0 -1
- package/experimental/utils/media_core.cjs +0 -1
- package/experimental/utils/media_core.d.cts +0 -1
- package/experimental/utils/media_core.d.ts +0 -1
- package/experimental/utils/media_core.js +0 -1
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/types.cjs +0 -1
- package/types.d.cts +0 -1
- package/types.d.ts +0 -1
- package/types.js +0 -1
- package/utils.cjs +0 -1
- package/utils.d.cts +0 -1
- package/utils.d.ts +0 -1
- package/utils.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","names":["config?: AnthropicAPIConfig","part: AnthropicContent","message: AnthropicResponseMessage","content: AnthropicContent[]","response: GoogleLLMResponse","fields: string | AIMessageFields","ret: AIMessageFields","str: string | undefined","textContent: AnthropicContentText","toolUseContent: AnthropicContentToolUse","tool: ToolCall","thinkingContent: AnthropicContentThinking","thinkingContent: AnthropicContentRedactedThinking","anthropicContent: AnthropicContent","anthropicContent: AnthropicContent[]","complexContent: MessageContentComplex[]","toolCalls: ToolCall[]","usageMetadata: UsageMetadata","responseMessage: AnthropicResponseMessage","event: AnthropicStreamMessageStartEvent","event: AnthropicStreamMessageDeltaEvent","event: AnthropicStreamContentBlockStartEvent","text: string","toolChunk: ToolCallChunk","toolChunks: ToolCallChunk[]","content: MessageContentComplex[]","messageFields: AIMessageChunkFields","event: AnthropicStreamContentBlockDeltaEvent","chunk: BaseMessageChunk","generations: ChatGeneration[]","content: MessageContentText","str: string","content: MessageContentImageUrl","content: Record<string, any>","content: MessageContentComplex","anthropicContentConverter: StandardContentBlockConverter<{\n text: AnthropicMessageContentText;\n image: AnthropicMessageContentImage;\n file: AnthropicMessageContentDocument;\n }>","block: StandardTextBlock","block: StandardImageBlock","block: StandardFileBlock","content: MessageContent | DataContentBlock[]","toolCall: ToolCall","toolCalls: ToolCall[] | undefined","base: BaseMessage","role: string","base: AIMessage","base: ToolMessage","content: AnthropicMessageContentToolResult[]","input: BaseMessage[]","ret: AnthropicMessage[]","parameters: GoogleAIModelRequestParams","ret: AnthropicRequestSettings","contentArray: MessageContentComplex[]","tool: GeminiTool","tool: GoogleAIToolType","tools: GoogleAIToolType[]","ret: AnthropicTool[]","input: unknown","ret: AnthropicRequest","_params: GoogleAIModelParams","modelName: string"],"sources":["../../src/utils/anthropic.ts"],"sourcesContent":["import {\n ChatGeneration,\n ChatGenerationChunk,\n ChatResult,\n} from \"@langchain/core/outputs\";\nimport {\n BaseMessage,\n BaseMessageChunk,\n AIMessageChunk,\n MessageContentComplex,\n MessageContentText,\n MessageContent,\n MessageContentImageUrl,\n AIMessageFields,\n AIMessageChunkFields,\n AIMessage,\n StandardContentBlockConverter,\n StandardImageBlock,\n StandardTextBlock,\n StandardFileBlock,\n DataContentBlock,\n isDataContentBlock,\n convertToProviderContentBlock,\n parseBase64DataUrl,\n UsageMetadata,\n} from \"@langchain/core/messages\";\nimport {\n ToolCall,\n ToolCallChunk,\n ToolMessage,\n} from \"@langchain/core/messages/tool\";\nimport {\n AnthropicAPIConfig,\n AnthropicCacheControl,\n AnthropicContent,\n AnthropicContentRedactedThinking,\n AnthropicContentText,\n AnthropicContentThinking,\n AnthropicContentToolUse,\n AnthropicMessage,\n AnthropicMessageContent,\n AnthropicMessageContentDocument,\n AnthropicMessageContentImage,\n AnthropicMessageContentRedactedThinking,\n AnthropicMessageContentText,\n AnthropicMessageContentThinking,\n AnthropicMessageContentToolResult,\n AnthropicMessageContentToolResultContent,\n AnthropicMessageContentToolUse,\n AnthropicRequest,\n AnthropicRequestSettings,\n AnthropicResponseData,\n AnthropicResponseMessage,\n AnthropicStreamContentBlockDeltaEvent,\n AnthropicStreamContentBlockStartEvent,\n AnthropicStreamInputJsonDelta,\n AnthropicStreamMessageDeltaEvent,\n AnthropicStreamMessageStartEvent,\n AnthropicStreamTextDelta,\n AnthropicTool,\n AnthropicToolChoice,\n GeminiTool,\n GoogleAIAPI,\n GoogleAIModelParams,\n GoogleAIModelRequestParams,\n GoogleAIToolType,\n GoogleLLMResponse,\n} from \"../types.js\";\n\nexport function getAnthropicAPI(config?: AnthropicAPIConfig): GoogleAIAPI {\n function partToString(part: AnthropicContent): string {\n return \"text\" in part ? part.text : \"\";\n }\n\n function messageToString(message: AnthropicResponseMessage): string {\n const content: AnthropicContent[] = message?.content ?? [];\n const ret = content.reduce((acc, part) => {\n const str = partToString(part);\n return acc + str;\n }, \"\");\n return ret;\n }\n\n function responseToString(response: GoogleLLMResponse): string {\n const data = response.data as AnthropicResponseData;\n switch (data?.type) {\n case \"message\":\n return messageToString(data as AnthropicResponseMessage);\n default:\n throw Error(`Unknown type: ${data?.type}`);\n }\n }\n\n /**\n * Normalize the AIMessageChunk.\n * If the fields are just a string - use that as content.\n * If the content is an array of just text fields, turn them into a string.\n * @param fields\n */\n function newAIMessageChunk(fields: string | AIMessageFields): AIMessageChunk {\n if (typeof fields === \"string\") {\n return new AIMessageChunk(fields);\n }\n const ret: AIMessageFields = {\n ...fields,\n };\n\n if (Array.isArray(fields?.content)) {\n let str: string | undefined = \"\";\n fields.content.forEach((val) => {\n if (str !== undefined && val.type === \"text\") {\n str = `${str}${val.text}`;\n } else {\n str = undefined;\n }\n });\n if (str) {\n ret.content = str;\n }\n }\n\n return new AIMessageChunk(ret);\n }\n\n function textContentToMessageFields(\n textContent: AnthropicContentText\n ): AIMessageFields {\n return {\n content: [textContent],\n };\n }\n\n function toolUseContentToMessageFields(\n toolUseContent: AnthropicContentToolUse\n ): AIMessageFields {\n const tool: ToolCall = {\n id: toolUseContent.id,\n name: toolUseContent.name,\n type: \"tool_call\",\n args: toolUseContent.input,\n };\n return {\n content: [],\n tool_calls: [tool],\n };\n }\n\n function thinkingContentToMessageFields(\n thinkingContent: AnthropicContentThinking\n ): AIMessageFields {\n // TODO: Once a reasoning/thinking type is defined in LangChain, use it\n return {\n content: [thinkingContent],\n };\n }\n\n function redactedThinkingContentToMessageFields(\n thinkingContent: AnthropicContentRedactedThinking\n ): AIMessageFields {\n // TODO: Once a reasoning/thinking type is defined in LangChain, use it\n return {\n content: [thinkingContent],\n };\n }\n\n function anthropicContentToMessageFields(\n anthropicContent: AnthropicContent\n ): AIMessageFields | undefined {\n const type = anthropicContent?.type;\n switch (type) {\n case \"text\":\n return textContentToMessageFields(anthropicContent);\n case \"tool_use\":\n return toolUseContentToMessageFields(anthropicContent);\n case \"thinking\":\n return thinkingContentToMessageFields(anthropicContent);\n case \"redacted_thinking\":\n return redactedThinkingContentToMessageFields(anthropicContent);\n default:\n console.error(`Unknown message type: ${type}`, anthropicContent);\n return undefined;\n }\n }\n\n function contentToMessage(\n anthropicContent: AnthropicContent[]\n ): BaseMessageChunk {\n const complexContent: MessageContentComplex[] = [];\n const toolCalls: ToolCall[] = [];\n anthropicContent.forEach((ac) => {\n const messageFields = anthropicContentToMessageFields(ac);\n if (messageFields?.content) {\n complexContent.push(\n ...(messageFields.content as MessageContentComplex[])\n );\n }\n if (messageFields?.tool_calls) {\n toolCalls.push(...messageFields.tool_calls);\n }\n });\n\n const ret: AIMessageFields = {\n content: complexContent,\n tool_calls: toolCalls,\n };\n return newAIMessageChunk(ret);\n }\n\n function messageToUsageMetadata(\n message: AnthropicResponseMessage\n ): UsageMetadata {\n const usage = message?.usage;\n const inputTokens = usage?.input_tokens ?? 0;\n const outputTokens = usage?.output_tokens ?? 0;\n const usageMetadata: UsageMetadata = {\n input_tokens: inputTokens,\n output_tokens: outputTokens,\n total_tokens: inputTokens + outputTokens,\n input_token_details: {\n cache_read: usage?.cache_read_input_tokens ?? 0,\n cache_creation: usage?.cache_creation_input_tokens ?? 0,\n },\n };\n return usageMetadata;\n }\n\n function messageToGenerationInfo(message: AnthropicResponseMessage) {\n const usageMetadata = messageToUsageMetadata(message);\n\n return {\n usage_metadata: usageMetadata,\n finish_reason: message.stop_reason,\n };\n }\n\n function messageToChatGeneration(\n responseMessage: AnthropicResponseMessage\n ): ChatGenerationChunk {\n const content: AnthropicContent[] = responseMessage?.content ?? [];\n const text = messageToString(responseMessage);\n const message = contentToMessage(content);\n const generationInfo = messageToGenerationInfo(responseMessage);\n return new ChatGenerationChunk({\n text,\n message,\n generationInfo,\n });\n }\n\n function messageStartToChatGeneration(\n event: AnthropicStreamMessageStartEvent\n ): ChatGenerationChunk {\n const responseMessage = event.message;\n return messageToChatGeneration(responseMessage);\n }\n\n function messageDeltaToChatGeneration(\n event: AnthropicStreamMessageDeltaEvent\n ): ChatGenerationChunk {\n const responseMessage = event.delta;\n return messageToChatGeneration(responseMessage as AnthropicResponseMessage);\n }\n\n function contentBlockStartTextToChatGeneration(\n event: AnthropicStreamContentBlockStartEvent\n ): ChatGenerationChunk | null {\n const content = event.content_block;\n const message = contentToMessage([content]);\n if (!message) {\n return null;\n }\n\n const text = \"text\" in content ? content.text : \"\";\n return new ChatGenerationChunk({\n message,\n text,\n });\n }\n\n function contentBlockStartToolUseToChatGeneration(\n event: AnthropicStreamContentBlockStartEvent\n ): ChatGenerationChunk | null {\n const contentBlock = event.content_block as AnthropicContentToolUse;\n const text: string = \"\";\n const toolChunk: ToolCallChunk = {\n type: \"tool_call_chunk\",\n index: event.index,\n name: contentBlock.name,\n id: contentBlock.id,\n };\n if (\n typeof contentBlock.input === \"object\" &&\n Object.keys(contentBlock.input).length > 0\n ) {\n toolChunk.args = JSON.stringify(contentBlock.input);\n }\n const toolChunks: ToolCallChunk[] = [toolChunk];\n\n const content: MessageContentComplex[] = [\n {\n index: event.index,\n ...contentBlock,\n },\n ];\n const messageFields: AIMessageChunkFields = {\n content,\n tool_call_chunks: toolChunks,\n };\n const message = newAIMessageChunk(messageFields);\n return new ChatGenerationChunk({\n message,\n text,\n });\n }\n\n function contentBlockStartToChatGeneration(\n event: AnthropicStreamContentBlockStartEvent\n ): ChatGenerationChunk | null {\n switch (event.content_block.type) {\n case \"text\":\n return contentBlockStartTextToChatGeneration(event);\n case \"tool_use\":\n return contentBlockStartToolUseToChatGeneration(event);\n default:\n console.warn(\n `Unexpected start content_block type: ${JSON.stringify(event)}`\n );\n return null;\n }\n }\n\n function contentBlockDeltaTextToChatGeneration(\n event: AnthropicStreamContentBlockDeltaEvent\n ): ChatGenerationChunk {\n const delta = event.delta as AnthropicStreamTextDelta;\n const text = delta?.text;\n const message = newAIMessageChunk(text);\n return new ChatGenerationChunk({\n message,\n text,\n });\n }\n\n function contentBlockDeltaInputJsonDeltaToChatGeneration(\n event: AnthropicStreamContentBlockDeltaEvent\n ): ChatGenerationChunk {\n const delta = event.delta as AnthropicStreamInputJsonDelta;\n const text: string = \"\";\n const toolChunks: ToolCallChunk[] = [\n {\n index: event.index,\n args: delta.partial_json,\n },\n ];\n const content: MessageContentComplex[] = [\n {\n index: event.index,\n ...delta,\n },\n ];\n const messageFields: AIMessageChunkFields = {\n content,\n tool_call_chunks: toolChunks,\n };\n const message = newAIMessageChunk(messageFields);\n return new ChatGenerationChunk({\n message,\n text,\n });\n }\n\n function contentBlockDeltaToChatGeneration(\n event: AnthropicStreamContentBlockDeltaEvent\n ): ChatGenerationChunk | null {\n switch (event.delta.type) {\n case \"text_delta\":\n return contentBlockDeltaTextToChatGeneration(event);\n case \"input_json_delta\":\n return contentBlockDeltaInputJsonDeltaToChatGeneration(event);\n default:\n console.warn(\n `Unexpected delta content_block type: ${JSON.stringify(event)}`\n );\n return null;\n }\n }\n\n function responseToChatGeneration(\n response: GoogleLLMResponse\n ): ChatGenerationChunk | null {\n const data = response.data as AnthropicResponseData;\n switch (data.type) {\n case \"message\":\n return messageToChatGeneration(data as AnthropicResponseMessage);\n case \"message_start\":\n return messageStartToChatGeneration(\n data as AnthropicStreamMessageStartEvent\n );\n case \"message_delta\":\n return messageDeltaToChatGeneration(\n data as AnthropicStreamMessageDeltaEvent\n );\n case \"content_block_start\":\n return contentBlockStartToChatGeneration(\n data as AnthropicStreamContentBlockStartEvent\n );\n case \"content_block_delta\":\n return contentBlockDeltaToChatGeneration(\n data as AnthropicStreamContentBlockDeltaEvent\n );\n\n case \"ping\":\n case \"message_stop\":\n case \"content_block_stop\":\n // These are ignorable\n return null;\n\n case \"error\":\n throw new Error(\n `Error while streaming results: ${JSON.stringify(data)}`\n );\n\n default:\n // We don't know what type this is, but Anthropic may have added\n // new ones without telling us. Don't error, but don't use them.\n console.warn(\"Unknown data for responseToChatGeneration\", data);\n // throw new Error(`Unknown response type: ${data.type}`);\n return null;\n }\n }\n\n function chunkToString(chunk: BaseMessageChunk): string {\n if (chunk === null) {\n return \"\";\n } else if (typeof chunk.content === \"string\") {\n return chunk.content;\n } else if (chunk.content.length === 0) {\n return \"\";\n } else if (chunk.content[0].type === \"text\") {\n return chunk.content[0].text;\n } else {\n throw new Error(`Unexpected chunk: ${chunk}`);\n }\n }\n\n function responseToBaseMessage(response: GoogleLLMResponse): BaseMessage {\n const data = response.data as AnthropicResponseMessage;\n const content: AnthropicContent[] = data?.content ?? [];\n return contentToMessage(content);\n }\n\n function responseToChatResult(response: GoogleLLMResponse): ChatResult {\n const message = response.data as AnthropicResponseMessage;\n const generations: ChatGeneration[] = [];\n const gen = responseToChatGeneration(response);\n if (gen) {\n generations.push(gen);\n }\n const llmOutput = messageToGenerationInfo(message);\n return {\n generations,\n llmOutput,\n };\n }\n\n function formatAnthropicVersion(): string {\n return config?.version ?? \"vertex-2023-10-16\";\n }\n\n function textContentToAnthropicContent(\n content: MessageContentText\n ): AnthropicMessageContentText {\n return content;\n }\n\n function extractMimeType(\n str: string\n ): { media_type: string; data: string } | null {\n if (str.startsWith(\"data:\")) {\n return {\n media_type: str.split(\":\")[1].split(\";\")[0],\n data: str.split(\",\")[1],\n };\n }\n return null;\n }\n\n function imageContentToAnthropicContent(\n content: MessageContentImageUrl\n ): AnthropicMessageContentImage | undefined {\n const dataUrl = content.image_url;\n const url = typeof dataUrl === \"string\" ? dataUrl : dataUrl?.url;\n const urlInfo = extractMimeType(url);\n\n if (!urlInfo) {\n return undefined;\n }\n\n return {\n type: \"image\",\n source: {\n type: \"base64\",\n ...urlInfo,\n },\n };\n }\n\n function thinkingContentToAnthropicContent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n content: Record<string, any>\n ): AnthropicMessageContentThinking | undefined {\n // TODO: Once a Langchain Thinking type is defined, use it\n return {\n type: \"thinking\",\n thinking: content.thinking,\n signature: content.signature,\n };\n }\n\n function redactedThinkingContentToAnthropicContent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n content: Record<string, any>\n ): AnthropicMessageContentRedactedThinking | undefined {\n // TODO: Once a Langchain Thinking type is defined, use it\n return {\n type: \"redacted_thinking\",\n data: content.data,\n };\n }\n\n function contentComplexToAnthropicContent(\n content: MessageContentComplex\n ): AnthropicMessageContent | undefined {\n const type = content?.type;\n switch (type) {\n case \"text\":\n return textContentToAnthropicContent(content as MessageContentText);\n case \"image_url\":\n return imageContentToAnthropicContent(\n content as MessageContentImageUrl\n );\n case \"thinking\":\n return thinkingContentToAnthropicContent(\n content as Record<string, unknown>\n );\n case \"redacted_thinking\":\n return redactedThinkingContentToAnthropicContent(\n content as Record<string, unknown>\n );\n default:\n console.warn(`Unexpected content type: ${type}`, content);\n return undefined;\n }\n }\n\n const anthropicContentConverter: StandardContentBlockConverter<{\n text: AnthropicMessageContentText;\n image: AnthropicMessageContentImage;\n file: AnthropicMessageContentDocument;\n }> = {\n providerName: \"anthropic\",\n\n fromStandardTextBlock(\n block: StandardTextBlock\n ): AnthropicMessageContentText {\n return {\n type: \"text\",\n text: block.text,\n ...(\"cache_control\" in (block.metadata ?? {})\n ? {\n cache_control: block.metadata!\n .cache_control as AnthropicCacheControl,\n }\n : {}),\n };\n },\n\n fromStandardImageBlock(\n block: StandardImageBlock\n ): AnthropicMessageContentImage {\n if (block.source_type === \"url\") {\n const data = parseBase64DataUrl({\n dataUrl: block.url,\n asTypedArray: false,\n });\n if (data) {\n return {\n type: \"image\",\n source: {\n type: \"base64\",\n data: data.data,\n media_type: data.mime_type,\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as AnthropicMessageContentImage;\n } else {\n return {\n type: \"image\",\n source: {\n type: \"url\",\n url: block.url,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as AnthropicMessageContentImage;\n }\n } else {\n if (block.source_type === \"base64\") {\n return {\n type: \"image\",\n source: {\n type: \"base64\",\n data: block.data,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as AnthropicMessageContentImage;\n } else {\n throw new Error(\n `Unsupported image source type: ${block.source_type}`\n );\n }\n }\n },\n\n fromStandardFileBlock(\n block: StandardFileBlock\n ): AnthropicMessageContentDocument {\n const mime_type = (block.mime_type ?? \"\").split(\";\")[0];\n\n if (block.source_type === \"url\") {\n if (mime_type === \"application/pdf\" || mime_type === \"\") {\n return {\n type: \"document\",\n source: {\n type: \"url\",\n url: block.url,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? {\n cache_control: block.metadata!\n .cache_control as AnthropicCacheControl,\n }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? {\n citations: block.metadata!.citations as { enabled?: boolean },\n }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context as string }\n : {}),\n ...(block.metadata?.title ||\n block.metadata?.filename ||\n block.metadata?.name\n ? {\n title: (block.metadata?.title ||\n block.metadata?.filename ||\n block.metadata?.name) as string,\n }\n : {}),\n };\n }\n throw new Error(\n `Unsupported file mime type for file url source: ${block.mime_type}`\n );\n } else if (block.source_type === \"text\") {\n if (mime_type === \"text/plain\" || mime_type === \"\") {\n return {\n type: \"document\",\n source: {\n type: \"text\",\n data: block.text,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? {\n cache_control: block.metadata!\n .cache_control as AnthropicCacheControl,\n }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? {\n citations: block.metadata!.citations as { enabled?: boolean },\n }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context as string }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title as string }\n : {}),\n };\n } else {\n throw new Error(\n `Unsupported file mime type for file text source: ${block.mime_type}`\n );\n }\n } else if (block.source_type === \"base64\") {\n if (mime_type === \"application/pdf\" || mime_type === \"\") {\n return {\n type: \"document\",\n source: {\n type: \"base64\",\n data: block.data,\n media_type: \"application/pdf\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? {\n cache_control: block.metadata!\n .cache_control as AnthropicCacheControl,\n }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? {\n citations: block.metadata!.citations as { enabled?: boolean },\n }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context as string }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title as string }\n : {}),\n };\n } else if (\n [\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"].includes(\n mime_type\n )\n ) {\n return {\n type: \"document\",\n source: {\n type: \"content\",\n content: [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n data: block.data,\n media_type: mime_type as\n | \"image/jpeg\"\n | \"image/png\"\n | \"image/gif\"\n | \"image/webp\",\n },\n },\n ],\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? {\n cache_control: block.metadata!\n .cache_control as AnthropicCacheControl,\n }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? {\n citations: block.metadata!.citations as { enabled?: boolean },\n }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context as string }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title as string }\n : {}),\n };\n } else {\n throw new Error(\n `Unsupported file mime type for file base64 source: ${block.mime_type}`\n );\n }\n } else {\n throw new Error(`Unsupported file source type: ${block.source_type}`);\n }\n },\n };\n\n function contentToAnthropicContent(\n content: MessageContent | DataContentBlock[]\n ): AnthropicMessageContent[] {\n const ca =\n typeof content === \"string\" ? [{ type: \"text\", text: content }] : content;\n return ca\n .map((complex) =>\n isDataContentBlock(complex)\n ? convertToProviderContentBlock(complex, anthropicContentConverter)\n : contentComplexToAnthropicContent(complex)\n )\n .filter(Boolean) as AnthropicMessageContent[];\n }\n\n function toolCallToAnthropicContent(\n toolCall: ToolCall\n ): AnthropicMessageContentToolUse {\n return {\n type: \"tool_use\",\n id: toolCall.id!,\n name: toolCall.name,\n input: toolCall.args,\n };\n }\n\n function toolCallsToAnthropicContent(\n toolCalls: ToolCall[] | undefined\n ): AnthropicMessageContentToolUse[] {\n if (toolCalls === undefined) {\n return [];\n }\n return toolCalls.map(toolCallToAnthropicContent);\n }\n\n function baseRoleToAnthropicMessage(\n base: BaseMessage,\n role: string\n ): AnthropicMessage {\n const content = contentToAnthropicContent(base.content);\n return {\n role,\n content,\n };\n }\n\n function aiMessageToAnthropicMessage(base: AIMessage): AnthropicMessage {\n const ret = baseRoleToAnthropicMessage(base, \"assistant\");\n\n const toolContent = toolCallsToAnthropicContent(base.tool_calls);\n if (toolContent.length > 0) {\n const content = ret.content as AnthropicMessageContent[];\n ret.content = [...content, ...toolContent];\n }\n\n return ret;\n }\n\n function toolMessageToAnthropicMessage(base: ToolMessage): AnthropicMessage {\n const role = \"user\";\n const toolUseId = base.tool_call_id;\n const toolContent = contentToAnthropicContent(\n base.content\n ) as AnthropicMessageContentToolResultContent[];\n const content: AnthropicMessageContentToolResult[] = [\n {\n type: \"tool_result\",\n tool_use_id: toolUseId,\n content: toolContent,\n },\n ];\n return {\n role,\n content,\n };\n }\n\n function baseToAnthropicMessage(\n base: BaseMessage\n ): AnthropicMessage | undefined {\n const type = base._getType();\n switch (type) {\n case \"human\":\n return baseRoleToAnthropicMessage(base, \"user\");\n case \"ai\":\n return aiMessageToAnthropicMessage(base as AIMessage);\n case \"tool\":\n return toolMessageToAnthropicMessage(base as ToolMessage);\n case \"system\":\n // System messages are handled in formatSystem()\n return undefined;\n default:\n console.warn(`Unknown BaseMessage type: ${type}`, base);\n return undefined;\n }\n }\n\n function formatMessages(input: BaseMessage[]): AnthropicMessage[] {\n const ret: AnthropicMessage[] = [];\n\n input.forEach((baseMessage) => {\n const anthropicMessage = baseToAnthropicMessage(baseMessage);\n if (anthropicMessage) {\n ret.push(anthropicMessage);\n }\n });\n\n return ret;\n }\n\n function formatSettings(\n parameters: GoogleAIModelRequestParams\n ): AnthropicRequestSettings {\n const ret: AnthropicRequestSettings = {\n stream: parameters?.streaming ?? false,\n max_tokens: parameters?.maxOutputTokens ?? 8192,\n };\n\n if (parameters.topP) {\n ret.top_p = parameters.topP;\n }\n if (parameters.topK) {\n ret.top_k = parameters.topK;\n }\n if (parameters.temperature) {\n ret.temperature = parameters.temperature;\n }\n if (parameters.stopSequences) {\n ret.stop_sequences = parameters.stopSequences;\n }\n\n return ret;\n }\n\n function contentComplexArrayToText(\n contentArray: MessageContentComplex[]\n ): string {\n let ret = \"\";\n\n contentArray.forEach((content) => {\n const contentType = content?.type;\n if (contentType === \"text\") {\n const textContent = content as MessageContentText;\n ret = `${ret}\\n${textContent.text}`;\n }\n });\n\n return ret;\n }\n\n function formatSystem(input: BaseMessage[]): string {\n let ret = \"\";\n\n input.forEach((message) => {\n if (message._getType() === \"system\") {\n const content = message?.content;\n const contentString =\n typeof content === \"string\"\n ? (content as string)\n : contentComplexArrayToText(content as MessageContentComplex[]);\n ret = `${ret}\\n${contentString}`;\n }\n });\n\n return ret;\n }\n\n function formatGeminiTool(tool: GeminiTool): AnthropicTool[] {\n if (Object.hasOwn(tool, \"functionDeclarations\")) {\n const funcs = tool?.functionDeclarations ?? [];\n return funcs.map((func) => {\n const inputSchema = func.parameters!;\n return {\n // type: \"tool\", // This may only be valid for models 20241022+\n name: func.name,\n description: func.description,\n input_schema: inputSchema,\n };\n });\n } else {\n console.warn(\n `Unable to format GeminiTool: ${JSON.stringify(tool, null, 1)}`\n );\n return [];\n }\n }\n\n function formatTool(tool: GoogleAIToolType): AnthropicTool[] {\n if (Object.hasOwn(tool, \"name\")) {\n return [tool as AnthropicTool];\n } else {\n return formatGeminiTool(tool as GeminiTool);\n }\n }\n\n function formatTools(\n parameters: GoogleAIModelRequestParams\n ): AnthropicTool[] {\n const tools: GoogleAIToolType[] = parameters?.tools ?? [];\n const ret: AnthropicTool[] = [];\n tools.forEach((tool) => {\n const anthropicTools = formatTool(tool);\n anthropicTools.forEach((anthropicTool) => {\n if (anthropicTool) {\n ret.push(anthropicTool);\n }\n });\n });\n return ret;\n }\n\n function formatToolChoice(\n parameters: GoogleAIModelRequestParams\n ): AnthropicToolChoice | undefined {\n const choice = parameters?.tool_choice;\n if (!choice) {\n return undefined;\n } else if (typeof choice === \"object\") {\n return choice as AnthropicToolChoice;\n } else {\n switch (choice) {\n case \"any\":\n case \"auto\":\n return {\n type: choice,\n };\n case \"none\":\n return undefined;\n default:\n return {\n type: \"tool\",\n name: choice,\n };\n }\n }\n }\n\n async function formatData(\n input: unknown,\n parameters: GoogleAIModelRequestParams\n ): Promise<AnthropicRequest> {\n const typedInput = input as BaseMessage[];\n const anthropicVersion = formatAnthropicVersion();\n const messages = formatMessages(typedInput);\n const settings = formatSettings(parameters);\n const system = formatSystem(typedInput);\n const tools = formatTools(parameters);\n const toolChoice = formatToolChoice(parameters);\n const ret: AnthropicRequest = {\n anthropic_version: anthropicVersion,\n messages,\n ...settings,\n };\n if (tools && tools.length && parameters?.tool_choice !== \"none\") {\n ret.tools = tools;\n }\n if (toolChoice) {\n ret.tool_choice = toolChoice;\n }\n if (system?.length) {\n ret.system = system;\n }\n if (config?.thinking) {\n ret.thinking = config?.thinking;\n }\n\n return ret;\n }\n\n return {\n responseToString,\n responseToChatGeneration,\n chunkToString,\n responseToBaseMessage,\n responseToChatResult,\n formatData,\n };\n}\n\nexport function validateClaudeParams(_params: GoogleAIModelParams): void {\n // FIXME - validate the parameters\n}\n\nexport function isModelClaude(modelName: string): boolean {\n return modelName.toLowerCase().startsWith(\"claude\");\n}\n"],"mappings":";;;;AAqEA,SAAgB,gBAAgBA,QAA0C;CACxE,SAAS,aAAaC,MAAgC;AACpD,SAAO,UAAU,OAAO,KAAK,OAAO;CACrC;CAED,SAAS,gBAAgBC,SAA2C;EAClE,MAAMC,UAA8B,SAAS,WAAW,CAAE;EAC1D,MAAM,MAAM,QAAQ,OAAO,CAAC,KAAK,SAAS;GACxC,MAAM,MAAM,aAAa,KAAK;AAC9B,UAAO,MAAM;EACd,GAAE,GAAG;AACN,SAAO;CACR;CAED,SAAS,iBAAiBC,UAAqC;EAC7D,MAAM,OAAO,SAAS;AACtB,UAAQ,MAAM,MAAd;GACE,KAAK,UACH,QAAO,gBAAgB,KAAiC;GAC1D,QACE,OAAM,MAAM,CAAC,cAAc,EAAE,MAAM,MAAM,CAAC;EAC7C;CACF;;;;;;;CAQD,SAAS,kBAAkBC,QAAkD;AAC3E,MAAI,OAAO,WAAW,SACpB,QAAO,IAAI,eAAe;EAE5B,MAAMC,MAAuB,EAC3B,GAAG,OACJ;AAED,MAAI,MAAM,QAAQ,QAAQ,QAAQ,EAAE;GAClC,IAAIC,MAA0B;GAC9B,OAAO,QAAQ,QAAQ,CAAC,QAAQ;AAC9B,QAAI,QAA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AM,aAAa;EACnB,MAAM,mBAAmB,wBAAwB;EACjD,MAAM,WAAW,eAAe,WAAW;EAC3C,MAAM,WAAW,eAAe,WAAW;EAC3C,MAAM,SAAS,aAAa,WAAW;EACvC,MAAM,QAAQ,YAAY,WAAW;EACrC,MAAM,aAAa,iBAAiB,WAAW;EAC/C,MAAMQ,MAAwB;GAC5B,mBAAmB;GACnB;GACA,GAAG;EACJ;AACD,MAAI,SAAS,MAAM,UAAU,YAAY,gBAAgB,QACvD,IAAI,QAAQ;AAEd,MAAI,YACF,IAAI,cAAc;AAEpB,MAAI,QAAQ,QACV,IAAI,SAAS;AAEf,MAAI,QAAQ,UACV,IAAI,WAAW,QAAQ;AAGzB,SAAO;CACR;AAED,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;CACD;AACF;AAED,SAAgB,qBAAqBC,SAAoC,CAExE;AAED,SAAgB,cAAcC,WAA4B;AACxD,QAAO,UAAU,aAAa,CAAC,WAAW,SAAS;AACpD"}
|
package/dist/utils/common.cjs
CHANGED
|
@@ -1,233 +1,152 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const base_1 = require("@langchain/core/language_models/base");
|
|
11
|
-
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
12
|
-
const gemini_js_1 = require("./gemini.cjs");
|
|
13
|
-
const types_js_1 = require("../types.cjs");
|
|
14
|
-
const zod_to_gemini_parameters_js_1 = require("./zod_to_gemini_parameters.cjs");
|
|
15
|
-
const anthropic_js_1 = require("./anthropic.cjs");
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_types = require('../types.cjs');
|
|
3
|
+
const require_zod_to_gemini_parameters = require('./zod_to_gemini_parameters.cjs');
|
|
4
|
+
const require_gemini = require('./gemini.cjs');
|
|
5
|
+
const require_anthropic = require('./anthropic.cjs');
|
|
6
|
+
const __langchain_core_language_models_base = require_rolldown_runtime.__toESM(require("@langchain/core/language_models/base"));
|
|
7
|
+
const __langchain_core_utils_function_calling = require_rolldown_runtime.__toESM(require("@langchain/core/utils/function_calling"));
|
|
8
|
+
|
|
9
|
+
//#region src/utils/common.ts
|
|
16
10
|
function copyAIModelParams(params, options) {
|
|
17
|
-
|
|
11
|
+
return copyAIModelParamsInto(params, options, {});
|
|
18
12
|
}
|
|
19
13
|
function processToolChoice(toolChoice, allowedFunctionNames) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (typeof toolChoice === "string") {
|
|
37
|
-
// String representing the function name.
|
|
38
|
-
// Return any to force the model to predict the specified function call.
|
|
39
|
-
return {
|
|
40
|
-
tool_choice: "any",
|
|
41
|
-
allowed_function_names: [...(allowedFunctionNames ?? []), toolChoice],
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
throw new Error("Object inputs for tool_choice not supported.");
|
|
14
|
+
if (!toolChoice) {
|
|
15
|
+
if (allowedFunctionNames) return {
|
|
16
|
+
tool_choice: "any",
|
|
17
|
+
allowed_function_names: allowedFunctionNames
|
|
18
|
+
};
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
if (toolChoice === "any" || toolChoice === "auto" || toolChoice === "none") return {
|
|
22
|
+
tool_choice: toolChoice,
|
|
23
|
+
allowed_function_names: allowedFunctionNames
|
|
24
|
+
};
|
|
25
|
+
if (typeof toolChoice === "string") return {
|
|
26
|
+
tool_choice: "any",
|
|
27
|
+
allowed_function_names: [...allowedFunctionNames ?? [], toolChoice]
|
|
28
|
+
};
|
|
29
|
+
throw new Error("Object inputs for tool_choice not supported.");
|
|
45
30
|
}
|
|
46
31
|
function isGeminiTool(tool) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
32
|
+
for (const toolAttribute of require_types.GeminiToolAttributes) if (toolAttribute in tool) return true;
|
|
33
|
+
return false;
|
|
53
34
|
}
|
|
54
35
|
function isGeminiNonFunctionTool(tool) {
|
|
55
|
-
|
|
36
|
+
return isGeminiTool(tool) && !("functionDeclaration" in tool);
|
|
56
37
|
}
|
|
57
38
|
function convertToGeminiTools(tools) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
name: tool.function.name,
|
|
87
|
-
description: tool.function.description ?? `A function available to call.`,
|
|
88
|
-
parameters: (0, zod_to_gemini_parameters_js_1.jsonSchemaToGeminiParameters)(tool.function.parameters),
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
throw new Error(`Received invalid tool: ${JSON.stringify(tool)}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
return geminiTools;
|
|
39
|
+
const geminiTools = [];
|
|
40
|
+
let functionDeclarationsIndex = -1;
|
|
41
|
+
tools.forEach((tool) => {
|
|
42
|
+
if (isGeminiNonFunctionTool(tool)) geminiTools.push(tool);
|
|
43
|
+
else {
|
|
44
|
+
if (functionDeclarationsIndex === -1) {
|
|
45
|
+
geminiTools.push({ functionDeclarations: [] });
|
|
46
|
+
functionDeclarationsIndex = geminiTools.length - 1;
|
|
47
|
+
}
|
|
48
|
+
if ("functionDeclarations" in tool && Array.isArray(tool.functionDeclarations)) {
|
|
49
|
+
const funcs = tool.functionDeclarations;
|
|
50
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push(...funcs);
|
|
51
|
+
} else if ((0, __langchain_core_utils_function_calling.isLangChainTool)(tool)) {
|
|
52
|
+
const jsonSchema = require_zod_to_gemini_parameters.schemaToGeminiParameters(tool.schema);
|
|
53
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
54
|
+
name: tool.name,
|
|
55
|
+
description: tool.description ?? `A function available to call.`,
|
|
56
|
+
parameters: jsonSchema
|
|
57
|
+
});
|
|
58
|
+
} else if ((0, __langchain_core_language_models_base.isOpenAITool)(tool)) geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
59
|
+
name: tool.function.name,
|
|
60
|
+
description: tool.function.description ?? `A function available to call.`,
|
|
61
|
+
parameters: require_zod_to_gemini_parameters.jsonSchemaToGeminiParameters(tool.function.parameters)
|
|
62
|
+
});
|
|
63
|
+
else throw new Error(`Received invalid tool: ${JSON.stringify(tool)}`);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return geminiTools;
|
|
97
67
|
}
|
|
98
68
|
function reasoningEffortToReasoningTokens(_modelName, effort) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
case "medium":
|
|
108
|
-
// Defined as 8k by https://ai.google.dev/gemini-api/docs/openai#thinking
|
|
109
|
-
return 8 * 1024;
|
|
110
|
-
case "high":
|
|
111
|
-
return maxEffort;
|
|
112
|
-
default:
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
69
|
+
if (effort === void 0) return void 0;
|
|
70
|
+
const maxEffort = 24 * 1024;
|
|
71
|
+
switch (effort) {
|
|
72
|
+
case "low": return 1024;
|
|
73
|
+
case "medium": return 8 * 1024;
|
|
74
|
+
case "high": return maxEffort;
|
|
75
|
+
default: return void 0;
|
|
76
|
+
}
|
|
115
77
|
}
|
|
116
78
|
function copyAIModelParamsInto(params, options, target) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
target.frequencyPenalty;
|
|
149
|
-
ret.stopSequences =
|
|
150
|
-
options?.stopSequences ?? params?.stopSequences ?? target.stopSequences;
|
|
151
|
-
ret.safetySettings =
|
|
152
|
-
options?.safetySettings ?? params?.safetySettings ?? target.safetySettings;
|
|
153
|
-
ret.logprobs = options?.logprobs ?? params?.logprobs ?? target.logprobs;
|
|
154
|
-
ret.topLogprobs =
|
|
155
|
-
options?.topLogprobs ?? params?.topLogprobs ?? target.topLogprobs;
|
|
156
|
-
ret.convertSystemMessageToHumanContent =
|
|
157
|
-
options?.convertSystemMessageToHumanContent ??
|
|
158
|
-
params?.convertSystemMessageToHumanContent ??
|
|
159
|
-
target?.convertSystemMessageToHumanContent;
|
|
160
|
-
ret.responseMimeType =
|
|
161
|
-
options?.responseMimeType ??
|
|
162
|
-
params?.responseMimeType ??
|
|
163
|
-
target?.responseMimeType;
|
|
164
|
-
ret.responseModalities =
|
|
165
|
-
options?.responseModalities ??
|
|
166
|
-
params?.responseModalities ??
|
|
167
|
-
target?.responseModalities;
|
|
168
|
-
ret.speechConfig = (0, gemini_js_1.normalizeSpeechConfig)(options?.speechConfig ?? params?.speechConfig ?? target?.speechConfig);
|
|
169
|
-
ret.streaming = options?.streaming ?? params?.streaming ?? target?.streaming;
|
|
170
|
-
const toolChoice = processToolChoice(options?.tool_choice, options?.allowed_function_names);
|
|
171
|
-
if (toolChoice) {
|
|
172
|
-
ret.tool_choice = toolChoice.tool_choice;
|
|
173
|
-
ret.allowed_function_names = toolChoice.allowed_function_names;
|
|
174
|
-
}
|
|
175
|
-
const tools = options?.tools;
|
|
176
|
-
if (tools) {
|
|
177
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
-
ret.tools = convertToGeminiTools(tools);
|
|
179
|
-
}
|
|
180
|
-
if (options?.cachedContent) {
|
|
181
|
-
ret.cachedContent = options.cachedContent;
|
|
182
|
-
}
|
|
183
|
-
ret.labels = options?.labels ?? params?.labels ?? target?.labels;
|
|
184
|
-
return ret;
|
|
79
|
+
const ret = target || {};
|
|
80
|
+
const model = options?.model ?? params?.model ?? target.model;
|
|
81
|
+
ret.modelName = model ?? options?.modelName ?? params?.modelName ?? target.modelName;
|
|
82
|
+
ret.model = model;
|
|
83
|
+
ret.temperature = options?.temperature ?? params?.temperature ?? target.temperature;
|
|
84
|
+
ret.maxOutputTokens = options?.maxOutputTokens ?? params?.maxOutputTokens ?? target.maxOutputTokens;
|
|
85
|
+
ret.maxReasoningTokens = options?.maxReasoningTokens ?? params?.maxReasoningTokens ?? target?.maxReasoningTokens ?? options?.thinkingBudget ?? params?.thinkingBudget ?? target?.thinkingBudget ?? reasoningEffortToReasoningTokens(ret.modelName, params?.reasoningEffort) ?? reasoningEffortToReasoningTokens(ret.modelName, target?.reasoningEffort) ?? reasoningEffortToReasoningTokens(ret.modelName, options?.reasoningEffort);
|
|
86
|
+
ret.topP = options?.topP ?? params?.topP ?? target.topP;
|
|
87
|
+
ret.topK = options?.topK ?? params?.topK ?? target.topK;
|
|
88
|
+
ret.seed = options?.seed ?? params?.seed ?? target.seed;
|
|
89
|
+
ret.presencePenalty = options?.presencePenalty ?? params?.presencePenalty ?? target.presencePenalty;
|
|
90
|
+
ret.frequencyPenalty = options?.frequencyPenalty ?? params?.frequencyPenalty ?? target.frequencyPenalty;
|
|
91
|
+
ret.stopSequences = options?.stopSequences ?? params?.stopSequences ?? target.stopSequences;
|
|
92
|
+
ret.safetySettings = options?.safetySettings ?? params?.safetySettings ?? target.safetySettings;
|
|
93
|
+
ret.logprobs = options?.logprobs ?? params?.logprobs ?? target.logprobs;
|
|
94
|
+
ret.topLogprobs = options?.topLogprobs ?? params?.topLogprobs ?? target.topLogprobs;
|
|
95
|
+
ret.convertSystemMessageToHumanContent = options?.convertSystemMessageToHumanContent ?? params?.convertSystemMessageToHumanContent ?? target?.convertSystemMessageToHumanContent;
|
|
96
|
+
ret.responseMimeType = options?.responseMimeType ?? params?.responseMimeType ?? target?.responseMimeType;
|
|
97
|
+
ret.responseModalities = options?.responseModalities ?? params?.responseModalities ?? target?.responseModalities;
|
|
98
|
+
ret.speechConfig = require_gemini.normalizeSpeechConfig(options?.speechConfig ?? params?.speechConfig ?? target?.speechConfig);
|
|
99
|
+
ret.streaming = options?.streaming ?? params?.streaming ?? target?.streaming;
|
|
100
|
+
const toolChoice = processToolChoice(options?.tool_choice, options?.allowed_function_names);
|
|
101
|
+
if (toolChoice) {
|
|
102
|
+
ret.tool_choice = toolChoice.tool_choice;
|
|
103
|
+
ret.allowed_function_names = toolChoice.allowed_function_names;
|
|
104
|
+
}
|
|
105
|
+
const tools = options?.tools;
|
|
106
|
+
if (tools) ret.tools = convertToGeminiTools(tools);
|
|
107
|
+
if (options?.cachedContent) ret.cachedContent = options.cachedContent;
|
|
108
|
+
ret.labels = options?.labels ?? params?.labels ?? target?.labels;
|
|
109
|
+
return ret;
|
|
185
110
|
}
|
|
186
111
|
function modelToFamily(modelName) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
else if ((0, gemini_js_1.isModelGemma)(modelName)) {
|
|
194
|
-
return "gemma";
|
|
195
|
-
}
|
|
196
|
-
else if ((0, anthropic_js_1.isModelClaude)(modelName)) {
|
|
197
|
-
return "claude";
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
112
|
+
if (!modelName) return null;
|
|
113
|
+
else if (require_gemini.isModelGemini(modelName)) return "gemini";
|
|
114
|
+
else if (require_gemini.isModelGemma(modelName)) return "gemma";
|
|
115
|
+
else if (require_anthropic.isModelClaude(modelName)) return "claude";
|
|
116
|
+
else return null;
|
|
202
117
|
}
|
|
203
118
|
function modelToPublisher(modelName) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
default:
|
|
213
|
-
return "unknown";
|
|
214
|
-
}
|
|
119
|
+
const family = modelToFamily(modelName);
|
|
120
|
+
switch (family) {
|
|
121
|
+
case "gemini":
|
|
122
|
+
case "gemma":
|
|
123
|
+
case "palm": return "google";
|
|
124
|
+
case "claude": return "anthropic";
|
|
125
|
+
default: return "unknown";
|
|
126
|
+
}
|
|
215
127
|
}
|
|
216
128
|
function validateModelParams(params) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
default:
|
|
226
|
-
throw new Error(`Unable to verify model params: ${JSON.stringify(params)}`);
|
|
227
|
-
}
|
|
129
|
+
const testParams = params ?? {};
|
|
130
|
+
const model = testParams.model ?? testParams.modelName;
|
|
131
|
+
switch (modelToFamily(model)) {
|
|
132
|
+
case "gemini":
|
|
133
|
+
case "gemma": return require_gemini.validateGeminiParams(testParams);
|
|
134
|
+
case "claude": return require_anthropic.validateClaudeParams(testParams);
|
|
135
|
+
default: throw new Error(`Unable to verify model params: ${JSON.stringify(params)}`);
|
|
136
|
+
}
|
|
228
137
|
}
|
|
229
138
|
function copyAndValidateModelParamsInto(params, target) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
139
|
+
copyAIModelParamsInto(params, void 0, target);
|
|
140
|
+
validateModelParams(target);
|
|
141
|
+
return target;
|
|
233
142
|
}
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
exports.convertToGeminiTools = convertToGeminiTools;
|
|
146
|
+
exports.copyAIModelParams = copyAIModelParams;
|
|
147
|
+
exports.copyAIModelParamsInto = copyAIModelParamsInto;
|
|
148
|
+
exports.copyAndValidateModelParamsInto = copyAndValidateModelParamsInto;
|
|
149
|
+
exports.modelToFamily = modelToFamily;
|
|
150
|
+
exports.modelToPublisher = modelToPublisher;
|
|
151
|
+
exports.validateModelParams = validateModelParams;
|
|
152
|
+
//# sourceMappingURL=common.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.cjs","names":["params: GoogleAIModelParams | undefined","options: GoogleAIBaseLanguageModelCallOptions | undefined","toolChoice: GoogleAIBaseLanguageModelCallOptions[\"tool_choice\"]","allowedFunctionNames: GoogleAIBaseLanguageModelCallOptions[\"allowed_function_names\"]","tool: GoogleAIToolType","GeminiToolAttributes","tools: GoogleAIToolType[]","geminiTools: GeminiTool[]","funcs: GeminiFunctionDeclaration[]","schemaToGeminiParameters","jsonSchemaToGeminiParameters","_modelName?: string","effort?: string","target: GoogleAIModelParams","ret: GoogleAIModelRequestParams","normalizeSpeechConfig","modelName: string | undefined","isModelGemini","isModelGemma","isModelClaude","testParams: GoogleAIModelParams","validateGeminiParams","validateClaudeParams"],"sources":["../../src/utils/common.ts"],"sourcesContent":["import { isOpenAITool } from \"@langchain/core/language_models/base\";\nimport { isLangChainTool } from \"@langchain/core/utils/function_calling\";\nimport {\n isModelGemini,\n isModelGemma,\n normalizeSpeechConfig,\n validateGeminiParams,\n} from \"./gemini.js\";\nimport {\n GeminiFunctionDeclaration,\n GeminiFunctionSchema,\n GeminiTool,\n GeminiToolAttributes,\n GoogleAIBaseLanguageModelCallOptions,\n GoogleAIModelParams,\n GoogleAIModelRequestParams,\n GoogleAIToolType,\n VertexModelFamily,\n} from \"../types.js\";\nimport {\n jsonSchemaToGeminiParameters,\n schemaToGeminiParameters,\n} from \"./zod_to_gemini_parameters.js\";\nimport { isModelClaude, validateClaudeParams } from \"./anthropic.js\";\n\nexport function copyAIModelParams(\n params: GoogleAIModelParams | undefined,\n options: GoogleAIBaseLanguageModelCallOptions | undefined\n): GoogleAIModelRequestParams {\n return copyAIModelParamsInto(params, options, {});\n}\n\nfunction processToolChoice(\n toolChoice: GoogleAIBaseLanguageModelCallOptions[\"tool_choice\"],\n allowedFunctionNames: GoogleAIBaseLanguageModelCallOptions[\"allowed_function_names\"]\n):\n | {\n tool_choice: \"any\" | \"auto\" | \"none\";\n allowed_function_names?: string[];\n }\n | undefined {\n if (!toolChoice) {\n if (allowedFunctionNames) {\n // Allowed func names is passed, return 'any' so it forces the model to use a tool.\n return {\n tool_choice: \"any\",\n allowed_function_names: allowedFunctionNames,\n };\n }\n return undefined;\n }\n\n if (toolChoice === \"any\" || toolChoice === \"auto\" || toolChoice === \"none\") {\n return {\n tool_choice: toolChoice,\n allowed_function_names: allowedFunctionNames,\n };\n }\n if (typeof toolChoice === \"string\") {\n // String representing the function name.\n // Return any to force the model to predict the specified function call.\n return {\n tool_choice: \"any\",\n allowed_function_names: [...(allowedFunctionNames ?? []), toolChoice],\n };\n }\n throw new Error(\"Object inputs for tool_choice not supported.\");\n}\n\nfunction isGeminiTool(tool: GoogleAIToolType): tool is GeminiTool {\n for (const toolAttribute of GeminiToolAttributes) {\n if (toolAttribute in tool) {\n return true;\n }\n }\n return false;\n}\n\nfunction isGeminiNonFunctionTool(tool: GoogleAIToolType): tool is GeminiTool {\n return isGeminiTool(tool) && !(\"functionDeclaration\" in tool);\n}\n\nexport function convertToGeminiTools(tools: GoogleAIToolType[]): GeminiTool[] {\n const geminiTools: GeminiTool[] = [];\n let functionDeclarationsIndex = -1;\n tools.forEach((tool) => {\n if (isGeminiNonFunctionTool(tool)) {\n geminiTools.push(tool);\n } else {\n if (functionDeclarationsIndex === -1) {\n geminiTools.push({\n functionDeclarations: [],\n });\n functionDeclarationsIndex = geminiTools.length - 1;\n }\n if (\n \"functionDeclarations\" in tool &&\n Array.isArray(tool.functionDeclarations)\n ) {\n const funcs: GeminiFunctionDeclaration[] = tool.functionDeclarations;\n geminiTools[functionDeclarationsIndex].functionDeclarations!.push(\n ...funcs\n );\n } else if (isLangChainTool(tool)) {\n const jsonSchema = schemaToGeminiParameters(tool.schema);\n geminiTools[functionDeclarationsIndex].functionDeclarations!.push({\n name: tool.name,\n description: tool.description ?? `A function available to call.`,\n parameters: jsonSchema as GeminiFunctionSchema,\n });\n } else if (isOpenAITool(tool)) {\n geminiTools[functionDeclarationsIndex].functionDeclarations!.push({\n name: tool.function.name,\n description:\n tool.function.description ?? `A function available to call.`,\n parameters: jsonSchemaToGeminiParameters(tool.function.parameters),\n });\n } else {\n throw new Error(`Received invalid tool: ${JSON.stringify(tool)}`);\n }\n }\n });\n return geminiTools;\n}\n\nfunction reasoningEffortToReasoningTokens(\n _modelName?: string,\n effort?: string\n): number | undefined {\n if (effort === undefined) {\n return undefined;\n }\n const maxEffort = 24 * 1024; // Max for Gemini 2.5 Flash\n switch (effort) {\n case \"low\":\n // Defined as 1k by https://ai.google.dev/gemini-api/docs/openai#thinking\n return 1024;\n case \"medium\":\n // Defined as 8k by https://ai.google.dev/gemini-api/docs/openai#thinking\n return 8 * 1024;\n case \"high\":\n return maxEffort;\n default:\n return undefined;\n }\n}\n\nexport function copyAIModelParamsInto(\n params: GoogleAIModelParams | undefined,\n options: GoogleAIBaseLanguageModelCallOptions | undefined,\n target: GoogleAIModelParams\n): GoogleAIModelRequestParams {\n const ret: GoogleAIModelRequestParams = target || {};\n const model = options?.model ?? params?.model ?? target.model;\n ret.modelName =\n model ?? options?.modelName ?? params?.modelName ?? target.modelName;\n ret.model = model;\n ret.temperature =\n options?.temperature ?? params?.temperature ?? target.temperature;\n ret.maxOutputTokens =\n options?.maxOutputTokens ??\n params?.maxOutputTokens ??\n target.maxOutputTokens;\n ret.maxReasoningTokens =\n options?.maxReasoningTokens ??\n params?.maxReasoningTokens ??\n target?.maxReasoningTokens ??\n options?.thinkingBudget ??\n params?.thinkingBudget ??\n target?.thinkingBudget ??\n reasoningEffortToReasoningTokens(ret.modelName, params?.reasoningEffort) ??\n reasoningEffortToReasoningTokens(ret.modelName, target?.reasoningEffort) ??\n reasoningEffortToReasoningTokens(ret.modelName, options?.reasoningEffort);\n ret.topP = options?.topP ?? params?.topP ?? target.topP;\n ret.topK = options?.topK ?? params?.topK ?? target.topK;\n ret.seed = options?.seed ?? params?.seed ?? target.seed;\n ret.presencePenalty =\n options?.presencePenalty ??\n params?.presencePenalty ??\n target.presencePenalty;\n ret.frequencyPenalty =\n options?.frequencyPenalty ??\n params?.frequencyPenalty ??\n target.frequencyPenalty;\n ret.stopSequences =\n options?.stopSequences ?? params?.stopSequences ?? target.stopSequences;\n ret.safetySettings =\n options?.safetySettings ?? params?.safetySettings ?? target.safetySettings;\n ret.logprobs = options?.logprobs ?? params?.logprobs ?? target.logprobs;\n ret.topLogprobs =\n options?.topLogprobs ?? params?.topLogprobs ?? target.topLogprobs;\n ret.convertSystemMessageToHumanContent =\n options?.convertSystemMessageToHumanContent ??\n params?.convertSystemMessageToHumanContent ??\n target?.convertSystemMessageToHumanContent;\n ret.responseMimeType =\n options?.responseMimeType ??\n params?.responseMimeType ??\n target?.responseMimeType;\n ret.responseModalities =\n options?.responseModalities ??\n params?.responseModalities ??\n target?.responseModalities;\n ret.speechConfig = normalizeSpeechConfig(\n options?.speechConfig ?? params?.speechConfig ?? target?.speechConfig\n );\n ret.streaming = options?.streaming ?? params?.streaming ?? target?.streaming;\n const toolChoice = processToolChoice(\n options?.tool_choice,\n options?.allowed_function_names\n );\n if (toolChoice) {\n ret.tool_choice = toolChoice.tool_choice;\n ret.allowed_function_names = toolChoice.allowed_function_names;\n }\n\n const tools = options?.tools;\n if (tools) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ret.tools = convertToGeminiTools(tools as Record<string, any>[]);\n }\n\n if (options?.cachedContent) {\n ret.cachedContent = options.cachedContent;\n }\n\n ret.labels = options?.labels ?? params?.labels ?? target?.labels;\n\n return ret;\n}\n\nexport function modelToFamily(\n modelName: string | undefined\n): VertexModelFamily {\n if (!modelName) {\n return null;\n } else if (isModelGemini(modelName)) {\n return \"gemini\";\n } else if (isModelGemma(modelName)) {\n return \"gemma\";\n } else if (isModelClaude(modelName)) {\n return \"claude\";\n } else {\n return null;\n }\n}\n\nexport function modelToPublisher(modelName: string | undefined): string {\n const family = modelToFamily(modelName);\n switch (family) {\n case \"gemini\":\n case \"gemma\":\n case \"palm\":\n return \"google\";\n\n case \"claude\":\n return \"anthropic\";\n\n default:\n return \"unknown\";\n }\n}\n\nexport function validateModelParams(\n params: GoogleAIModelParams | undefined\n): void {\n const testParams: GoogleAIModelParams = params ?? {};\n const model = testParams.model ?? testParams.modelName;\n switch (modelToFamily(model)) {\n case \"gemini\":\n case \"gemma\": // TODO: Are we sure?\n return validateGeminiParams(testParams);\n\n case \"claude\":\n return validateClaudeParams(testParams);\n\n default:\n throw new Error(\n `Unable to verify model params: ${JSON.stringify(params)}`\n );\n }\n}\n\nexport function copyAndValidateModelParamsInto(\n params: GoogleAIModelParams | undefined,\n target: GoogleAIModelParams\n): GoogleAIModelParams {\n copyAIModelParamsInto(params, undefined, target);\n validateModelParams(target);\n return target;\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAgB,kBACdA,QACAC,SAC4B;AAC5B,QAAO,sBAAsB,QAAQ,SAAS,CAAE,EAAC;AAClD;AAED,SAAS,kBACPC,YACAC,sBAMY;AACZ,KAAI,CAAC,YAAY;AACf,MAAI,qBAEF,QAAO;GACL,aAAa;GACb,wBAAwB;EACzB;AAEH,SAAO;CACR;AAED,KAAI,eAAe,SAAS,eAAe,UAAU,eAAe,OAClE,QAAO;EACL,aAAa;EACb,wBAAwB;CACz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0 +1,13 @@
|
|
|
1
|
+
import { GeminiTool, GoogleAIBaseLanguageModelCallOptions, GoogleAIModelParams, GoogleAIModelRequestParams, GoogleAIToolType, VertexModelFamily } from "../types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/common.d.ts
|
|
4
|
+
declare function copyAIModelParams(params: GoogleAIModelParams | undefined, options: GoogleAIBaseLanguageModelCallOptions | undefined): GoogleAIModelRequestParams;
|
|
5
|
+
declare function convertToGeminiTools(tools: GoogleAIToolType[]): GeminiTool[];
|
|
6
|
+
declare function copyAIModelParamsInto(params: GoogleAIModelParams | undefined, options: GoogleAIBaseLanguageModelCallOptions | undefined, target: GoogleAIModelParams): GoogleAIModelRequestParams;
|
|
7
|
+
declare function modelToFamily(modelName: string | undefined): VertexModelFamily;
|
|
8
|
+
declare function modelToPublisher(modelName: string | undefined): string;
|
|
9
|
+
declare function validateModelParams(params: GoogleAIModelParams | undefined): void;
|
|
10
|
+
declare function copyAndValidateModelParamsInto(params: GoogleAIModelParams | undefined, target: GoogleAIModelParams): GoogleAIModelParams;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { convertToGeminiTools, copyAIModelParams, copyAIModelParamsInto, copyAndValidateModelParamsInto, modelToFamily, modelToPublisher, validateModelParams };
|
|
13
|
+
//# sourceMappingURL=common.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.cts","names":["GeminiTool","GoogleAIBaseLanguageModelCallOptions","GoogleAIModelParams","GoogleAIModelRequestParams","GoogleAIToolType","VertexModelFamily","copyAIModelParams","convertToGeminiTools","copyAIModelParamsInto","modelToFamily","modelToPublisher","validateModelParams","copyAndValidateModelParamsInto"],"sources":["../../src/utils/common.d.ts"],"sourcesContent":["import { GeminiTool, GoogleAIBaseLanguageModelCallOptions, GoogleAIModelParams, GoogleAIModelRequestParams, GoogleAIToolType, VertexModelFamily } from \"../types.js\";\nexport declare function copyAIModelParams(params: GoogleAIModelParams | undefined, options: GoogleAIBaseLanguageModelCallOptions | undefined): GoogleAIModelRequestParams;\nexport declare function convertToGeminiTools(tools: GoogleAIToolType[]): GeminiTool[];\nexport declare function copyAIModelParamsInto(params: GoogleAIModelParams | undefined, options: GoogleAIBaseLanguageModelCallOptions | undefined, target: GoogleAIModelParams): GoogleAIModelRequestParams;\nexport declare function modelToFamily(modelName: string | undefined): VertexModelFamily;\nexport declare function modelToPublisher(modelName: string | undefined): string;\nexport declare function validateModelParams(params: GoogleAIModelParams | undefined): void;\nexport declare function copyAndValidateModelParamsInto(params: GoogleAIModelParams | undefined, target: GoogleAIModelParams): GoogleAIModelParams;\n"],"mappings":";;;iBACwBM,iBAAAA,SAA0BJ,0CAA0CD,mDAAmDE;iBACvHI,oBAAAA,QAA4BH,qBAAqBJ;AADjDM,iBAEAE,qBAAAA,CAFiB,MAAA,EAEaN,mBAFb,GAAA,SAAA,EAAA,OAAA,EAEuDD,oCAFvD,GAAA,SAAA,EAAA,MAAA,EAEiHC,mBAFjH,CAAA,EAEuIC,0BAFvI;AAAA,iBAGjBM,aAAAA,CAHiB,SAAA,EAAA,MAAA,GAAA,SAAA,CAAA,EAG6BJ,iBAH7B;AAASH,iBAI1BQ,gBAAAA,CAJ0BR,SAAAA,EAAAA,MAAAA,GAAAA,SAAAA,CAAAA,EAAAA,MAAAA;AAA0CD,iBAKpEU,mBAAAA,CALoEV,MAAAA,EAKxCC,mBALwCD,GAAAA,SAAAA,CAAAA,EAAAA,IAAAA;AAAmDE,iBAMvHS,8BAAAA,CANuHT,MAAAA,EAMhFD,mBANgFC,GAAAA,SAAAA,EAAAA,MAAAA,EAMvCD,mBANuCC,CAAAA,EAMjBD,mBANiBC"}
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { GeminiTool, GoogleAIBaseLanguageModelCallOptions, GoogleAIModelParams, GoogleAIModelRequestParams, GoogleAIToolType, VertexModelFamily } from "../types.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/utils/common.d.ts
|
|
4
|
+
declare function copyAIModelParams(params: GoogleAIModelParams | undefined, options: GoogleAIBaseLanguageModelCallOptions | undefined): GoogleAIModelRequestParams;
|
|
5
|
+
declare function convertToGeminiTools(tools: GoogleAIToolType[]): GeminiTool[];
|
|
6
|
+
declare function copyAIModelParamsInto(params: GoogleAIModelParams | undefined, options: GoogleAIBaseLanguageModelCallOptions | undefined, target: GoogleAIModelParams): GoogleAIModelRequestParams;
|
|
7
|
+
declare function modelToFamily(modelName: string | undefined): VertexModelFamily;
|
|
8
|
+
declare function modelToPublisher(modelName: string | undefined): string;
|
|
9
|
+
declare function validateModelParams(params: GoogleAIModelParams | undefined): void;
|
|
10
|
+
declare function copyAndValidateModelParamsInto(params: GoogleAIModelParams | undefined, target: GoogleAIModelParams): GoogleAIModelParams;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { convertToGeminiTools, copyAIModelParams, copyAIModelParamsInto, copyAndValidateModelParamsInto, modelToFamily, modelToPublisher, validateModelParams };
|
|
13
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","names":["GeminiTool","GoogleAIBaseLanguageModelCallOptions","GoogleAIModelParams","GoogleAIModelRequestParams","GoogleAIToolType","VertexModelFamily","copyAIModelParams","convertToGeminiTools","copyAIModelParamsInto","modelToFamily","modelToPublisher","validateModelParams","copyAndValidateModelParamsInto"],"sources":["../../src/utils/common.d.ts"],"sourcesContent":["import { GeminiTool, GoogleAIBaseLanguageModelCallOptions, GoogleAIModelParams, GoogleAIModelRequestParams, GoogleAIToolType, VertexModelFamily } from \"../types.js\";\nexport declare function copyAIModelParams(params: GoogleAIModelParams | undefined, options: GoogleAIBaseLanguageModelCallOptions | undefined): GoogleAIModelRequestParams;\nexport declare function convertToGeminiTools(tools: GoogleAIToolType[]): GeminiTool[];\nexport declare function copyAIModelParamsInto(params: GoogleAIModelParams | undefined, options: GoogleAIBaseLanguageModelCallOptions | undefined, target: GoogleAIModelParams): GoogleAIModelRequestParams;\nexport declare function modelToFamily(modelName: string | undefined): VertexModelFamily;\nexport declare function modelToPublisher(modelName: string | undefined): string;\nexport declare function validateModelParams(params: GoogleAIModelParams | undefined): void;\nexport declare function copyAndValidateModelParamsInto(params: GoogleAIModelParams | undefined, target: GoogleAIModelParams): GoogleAIModelParams;\n"],"mappings":";;;iBACwBM,iBAAAA,SAA0BJ,0CAA0CD,mDAAmDE;iBACvHI,oBAAAA,QAA4BH,qBAAqBJ;AADjDM,iBAEAE,qBAAAA,CAFiB,MAAA,EAEaN,mBAFb,GAAA,SAAA,EAAA,OAAA,EAEuDD,oCAFvD,GAAA,SAAA,EAAA,MAAA,EAEiHC,mBAFjH,CAAA,EAEuIC,0BAFvI;AAAA,iBAGjBM,aAAAA,CAHiB,SAAA,EAAA,MAAA,GAAA,SAAA,CAAA,EAG6BJ,iBAH7B;AAASH,iBAI1BQ,gBAAAA,CAJ0BR,SAAAA,EAAAA,MAAAA,GAAAA,SAAAA,CAAAA,EAAAA,MAAAA;AAA0CD,iBAKpEU,mBAAAA,CALoEV,MAAAA,EAKxCC,mBALwCD,GAAAA,SAAAA,CAAAA,EAAAA,IAAAA;AAAmDE,iBAMvHS,8BAAAA,CANuHT,MAAAA,EAMhFD,mBANgFC,GAAAA,SAAAA,EAAAA,MAAAA,EAMvCD,mBANuCC,CAAAA,EAMjBD,mBANiBC"}
|