From 56ffa22598576ed80b98adecb80167b8b71e25d9 Mon Sep 17 00:00:00 2001 From: Henry Yee Date: Fri, 2 Aug 2024 23:27:56 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20chore:=20support=20bedrock=20Cla?= =?UTF-8?q?ude=203.x=20function=20calling=20(#3366)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: GH Action - Upstream Sync --- src/config/modelProviders/bedrock.ts | 4 ++++ src/libs/agent-runtime/bedrock/index.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config/modelProviders/bedrock.ts b/src/config/modelProviders/bedrock.ts index b2cfd8a3a06b..0a127b25fa96 100644 --- a/src/config/modelProviders/bedrock.ts +++ b/src/config/modelProviders/bedrock.ts @@ -37,6 +37,7 @@ const Bedrock: ModelProviderCard = { 'Claude 3 Opus 是 Anthropic 最强大的人工智能模型,在处理高度复杂的任务方面具备顶尖性能。该模型能够以非凡的流畅性和类似人类的理解能力引导开放式的提示和未可见的场景。Claude 3 Opus 向我们展示生成式人工智能的美好前景。 Claude 3 Opus 可以处理图像和返回文本输出,并且提供 200K 上下文窗口。', displayName: 'Claude 3 Opus', enabled: true, + functionCall: true, id: 'anthropic.claude-3-opus-20240229-v1:0', tokens: 200_000, vision: true, @@ -46,6 +47,7 @@ const Bedrock: ModelProviderCard = { 'Anthropic 推出的 Claude 3 Sonnet 模型在智能和速度之间取得理想的平衡,尤其是在处理企业工作负载方面。该模型提供最大的效用,同时价格低于竞争产品,并且其经过精心设计,是大规模部署人工智能的可信赖、高耐久性骨干模型。 Claude 3 Sonnet 可以处理图像和返回文本输出,并且提供 200K 上下文窗口。', displayName: 'Claude 3 Sonnet', enabled: true, + functionCall: true, id: 'anthropic.claude-3-sonnet-20240229-v1:0', tokens: 200_000, vision: true, @@ -55,6 +57,7 @@ const Bedrock: ModelProviderCard = { 'Claude 3.5 Sonnet 提高了行业的智能标准, 在广泛的基准测试中超越了竞争对手模型以及 Claude 3 Opus, 以中端模型的速度和成本,展现出卓越性能。 Claude 3.5 Sonnet 可以处理图像和返回文本输出,并且提供 200K 上下文窗口。', displayName: 'Claude 3.5 Sonnet', enabled: true, + functionCall: true, id: 'anthropic.claude-3-5-sonnet-20240620-v1:0', tokens: 200_000, vision: true, @@ -64,6 +67,7 @@ const Bedrock: ModelProviderCard = { 'Claude 3 Haiku 是 Anthropic 最快速、最紧凑的模型,具有近乎即时的响应能力。该模型可以快速回答简单的查询和请求。客户将能够构建模仿人类交互的无缝人工智能体验。 Claude 3 Haiku 可以处理图像和返回文本输出,并且提供 200K 上下文窗口。', displayName: 'Claude 3 Haiku', enabled: true, + functionCall: true, id: 'anthropic.claude-3-haiku-20240307-v1:0', tokens: 200_000, vision: true, diff --git a/src/libs/agent-runtime/bedrock/index.ts b/src/libs/agent-runtime/bedrock/index.ts index 1e1b7e6db729..c3d5d94cd59e 100644 --- a/src/libs/agent-runtime/bedrock/index.ts +++ b/src/libs/agent-runtime/bedrock/index.ts @@ -7,7 +7,7 @@ import { experimental_buildLlama2Prompt } from 'ai/prompts'; import { LobeRuntimeAI } from '../BaseAI'; import { AgentRuntimeErrorType } from '../error'; import { ChatCompetitionOptions, ChatStreamPayload, ModelProvider } from '../types'; -import { buildAnthropicMessages } from '../utils/anthropicHelpers'; +import { buildAnthropicMessages, buildAnthropicTools } from '../utils/anthropicHelpers'; import { AgentRuntimeError } from '../utils/createError'; import { debugStream } from '../utils/debugStream'; import { StreamingResponse } from '../utils/response'; @@ -53,7 +53,7 @@ export class LobeBedrockAI implements LobeRuntimeAI { payload: ChatStreamPayload, options?: ChatCompetitionOptions, ): Promise => { - const { max_tokens, messages, model, temperature, top_p } = payload; + const { max_tokens, messages, model, temperature, top_p, tools } = payload; const system_message = messages.find((m) => m.role === 'system'); const user_messages = messages.filter((m) => m.role !== 'system'); @@ -65,6 +65,7 @@ export class LobeBedrockAI implements LobeRuntimeAI { messages: buildAnthropicMessages(user_messages), system: system_message?.content as string, temperature: temperature, + tools: buildAnthropicTools(tools), top_p: top_p, }), contentType: 'application/json',