Skip to content

Commit

Permalink
🔨 chore: support bedrock Claude 3.x function calling (lobehub#3366)
Browse files Browse the repository at this point in the history
Co-authored-by: GH Action - Upstream Sync <action@github.com>
  • Loading branch information
cookieY and actions-user authored Aug 2, 2024
1 parent 65ae6dc commit 56ffa22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/config/modelProviders/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/libs/agent-runtime/bedrock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -53,7 +53,7 @@ export class LobeBedrockAI implements LobeRuntimeAI {
payload: ChatStreamPayload,
options?: ChatCompetitionOptions,
): Promise<Response> => {
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');

Expand All @@ -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',
Expand Down

0 comments on commit 56ffa22

Please sign in to comment.