Skip to content

Commit

Permalink
feat: add support for Claude 3.7 Sonnet model in backend and frontend (
Browse files Browse the repository at this point in the history
  • Loading branch information
statefb authored Feb 25, 2025
1 parent a890a5f commit 57c55b4
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 27 deletions.
18 changes: 8 additions & 10 deletions backend/app/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,29 @@

import logging
import os
from typing import TypeGuard, Dict, Any, Optional, Tuple, TYPE_CHECKING
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, TypeGuard

from app.config import BEDROCK_PRICING
from app.config import DEFAULT_GENERATION_CONFIG as DEFAULT_CLAUDE_GENERATION_CONFIG
from app.config import DEFAULT_MISTRAL_GENERATION_CONFIG

from app.repositories.models.custom_bot import GenerationParamsModel
from app.repositories.models.custom_bot_guardrails import BedrockGuardrailsModel
from app.routes.schemas.conversation import type_model_name
from app.utils import get_bedrock_runtime_client

if TYPE_CHECKING:
from app.agents.tools.agent_tool import AgentTool
from app.repositories.models.conversation import (
SimpleMessageModel,
ContentModel,
)
from app.repositories.models.conversation import ContentModel, SimpleMessageModel
from mypy_boto3_bedrock_runtime.literals import ConversationRoleType
from mypy_boto3_bedrock_runtime.type_defs import (
ConverseStreamRequestRequestTypeDef,
MessageTypeDef,
ConverseResponseTypeDef,
ContentBlockTypeDef,
ConverseResponseTypeDef,
ConverseStreamRequestRequestTypeDef,
GuardrailConverseContentBlockTypeDef,
InferenceConfigurationTypeDef,
MessageTypeDef,
SystemContentBlockTypeDef,
)
from mypy_boto3_bedrock_runtime.literals import ConversationRoleType

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -275,6 +271,7 @@ def get_model_id(
"claude-v3-opus": "anthropic.claude-3-opus-20240229-v1:0",
"claude-v3.5-sonnet": "anthropic.claude-3-5-sonnet-20240620-v1:0",
"claude-v3.5-sonnet-v2": "anthropic.claude-3-5-sonnet-20241022-v2:0",
"claude-v3.7-sonnet": "anthropic.claude-3-7-sonnet-20250219-v1:0",
"claude-v3.5-haiku": "anthropic.claude-3-5-haiku-20241022-v1:0",
"mistral-7b-instruct": "mistral.mistral-7b-instruct-v0:2",
"mixtral-8x7b-instruct": "mistral.mixtral-8x7b-instruct-v0:1",
Expand All @@ -292,6 +289,7 @@ def get_model_id(
"claude-v3-opus",
"claude-v3.5-sonnet",
"claude-v3.5-sonnet-v2",
"claude-v3.7-sonnet",
"claude-v3.5-haiku",
"amazon-nova-pro",
"amazon-nova-lite",
Expand Down
3 changes: 3 additions & 0 deletions backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class EmbeddingConfig(TypedDict):
"claude-v3-sonnet": {"input": 0.00300, "output": 0.01500},
"claude-v3.5-sonnet": {"input": 0.00300, "output": 0.01500},
"claude-v3.5-sonnet-v2": {"input": 0.00300, "output": 0.01500},
"claude-v3.7-sonnet": {"input": 0.00300, "output": 0.01500},
"mistral-7b-instruct": {"input": 0.00015, "output": 0.0002},
"mixtral-8x7b-instruct": {"input": 0.00045, "output": 0.0007},
"mistral-large": {"input": 0.008, "output": 0.024},
Expand All @@ -72,6 +73,7 @@ class EmbeddingConfig(TypedDict):
"output": 0.00240,
},
"claude-v3-sonnet": {"input": 0.00300, "output": 0.01500},
"claude-v3.7-sonnet": {"input": 0.00300, "output": 0.01500},
"claude-v3-opus": {"input": 0.01500, "output": 0.07500},
"mistral-7b-instruct": {"input": 0.00015, "output": 0.0002},
"mixtral-8x7b-instruct": {"input": 0.00045, "output": 0.0007},
Expand Down Expand Up @@ -104,6 +106,7 @@ class EmbeddingConfig(TypedDict):
"claude-v3-sonnet": {"input": 0.00300, "output": 0.01500},
"claude-v3.5-sonnet": {"input": 0.00300, "output": 0.01500},
"claude-v3.5-sonnet-v2": {"input": 0.00300, "output": 0.01500},
"claude-v3.7-sonnet": {"input": 0.00300, "output": 0.01500},
"claude-v3-opus": {"input": 0.01500, "output": 0.07500},
"mistral-7b-instruct": {"input": 0.00015, "output": 0.0002},
"mixtral-8x7b-instruct": {"input": 0.00045, "output": 0.0007},
Expand Down
1 change: 1 addition & 0 deletions backend/app/routes/schemas/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"claude-v3-sonnet",
"claude-v3.5-sonnet",
"claude-v3.5-sonnet-v2",
"claude-v3.7-sonnet",
"claude-v3.5-haiku",
"claude-v3-haiku",
"claude-v3-opus",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const AVAILABLE_MODEL_KEYS = [
'claude-v3-sonnet',
'claude-v3.5-sonnet',
'claude-v3.5-sonnet-v2',
'claude-v3.7-sonnet',
'claude-v3-haiku',
'claude-v3.5-haiku',
'mistral-7b-instruct',
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/hooks/useModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ const useModel = (botId?: string | null, activeModels?: ActiveModels) => {
description: t('model.claude-v3.5-sonnet-v2.description'),
supportMediaType: CLAUDE_SUPPORTED_MEDIA_TYPES,
},
{
modelId: 'claude-v3.7-sonnet',
label: t('model.claude-v3.7-sonnet.label'),
description: t('model.claude-v3.7-sonnet.description'),
supportMediaType: CLAUDE_SUPPORTED_MEDIA_TYPES,
},
{
modelId: 'claude-v3-opus',
label: t('model.claude-v3-opus.label'),
Expand Down Expand Up @@ -252,9 +258,7 @@ const useModel = (botId?: string | null, activeModels?: ActiveModels) => {
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
botId,
]);
}, [botId]);

const model = useMemo(() => {
return filteredModels.find(
Expand Down
23 changes: 16 additions & 7 deletions frontend/src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const translation = {
description:
'The latest version of Claude 3.5. An enhanced model that builds on v1 with higher accuracy and performance.',
},
'claude-v3.7-sonnet': {
label: 'Claude 3.7 Sonnet',
description:
'Hybrid reasoning model balancing quick responses and deep analytical capabilities.',
},
'claude-v3.5-haiku': {
label: 'Claude 3.5 (Haiku) v1',
description:
Expand All @@ -46,15 +51,18 @@ const translation = {
},
'mistral-7b-instruct': {
label: 'Mistral 7B',
description: 'Supports English text generation tasks with natural coding capabilities'
description:
'Supports English text generation tasks with natural coding capabilities',
},
'mixtral-8x7b-instruct': {
label: 'Mistral-8x7B',
description: "A popular, high-quality, sparse Mixture-of-Experts (MoE) model, that is ideal for text summarization, question and answering, text classification, text completion, and code generation."
description:
'A popular, high-quality, sparse Mixture-of-Experts (MoE) model, that is ideal for text summarization, question and answering, text classification, text completion, and code generation.',
},
'mistral-large': {
label: 'Mistral Large',
description: "Ideal for complex tasks that require substantial reasoning capabilities, or ones that are highly specialized, such as Synthetic Text Generation or Code Generation."
description:
'Ideal for complex tasks that require substantial reasoning capabilities, or ones that are highly specialized, such as Synthetic Text Generation or Code Generation.',
},
'amazon-nova-pro': {
label: 'Amazon Nova Pro',
Expand Down Expand Up @@ -723,15 +731,16 @@ How would you categorize this email?`,
},
advancedConfigration: {
existKnowledgeBaseId: {
label: "ID for the Amazon Bedrock Knowledge Base",
description: "Please specify ID that your existing Amazon Bedrock knowledge base.",
label: 'ID for the Amazon Bedrock Knowledge Base',
description:
'Please specify ID that your existing Amazon Bedrock knowledge base.',
createNewKb: {
label: 'Create New Knowledge Base',
},
existing: {
label: 'Use your existing knowledge base',
}
}
},
},
},
},
error: {
Expand Down
22 changes: 15 additions & 7 deletions frontend/src/i18n/ja/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const translation = {
description:
'Claude 3.5の最新バージョン。v1をさらに強化し、より高い精度とパフォーマンスを提供',
},
'claude-v3.7-sonnet': {
label: 'Claude 3.7 Sonnet',
description: '迅速な応答と深い分析能力を両立するハイブリッド推論モデル',
},
'claude-v3.5-haiku': {
label: 'Claude 3.5 (Haiku) v1',
description: 'Haiku最新バージョン。精度を保ち、高速な応答を実現',
Expand All @@ -48,14 +52,17 @@ const translation = {
},
'mistral-7b-instruct': {
label: 'Mistral 7B',
description: '自然なコーディング機能で英語のテキスト生成タスクをサポートします'
description:
'自然なコーディング機能で英語のテキスト生成タスクをサポートします',
},
'mixtral-8x7b-instruct': {
label: 'Mistral-8x7B',
description: 'Mixtral-8x7BはMistral AIによって開発された基盤モデルで、英語、フランス語、ドイツ語、イタリア語、スペイン語のテキストをサポートし、コード生成機能を備えています。'
description:
'Mixtral-8x7BはMistral AIによって開発された基盤モデルで、英語、フランス語、ドイツ語、イタリア語、スペイン語のテキストをサポートし、コード生成機能を備えています。',
},
'mistral-large': {
label: '実質的な推論機能を必要とする複雑なタスクや、合成テキスト生成およびコード生成などの高度に専門化されたタスクに最適です',
label:
'実質的な推論機能を必要とする複雑なタスクや、合成テキスト生成およびコード生成などの高度に専門化されたタスクに最適です',
},
'amazon-nova-pro': {
label: 'Amazon Nova Pro',
Expand Down Expand Up @@ -718,16 +725,17 @@ const translation = {
},
advancedConfigration: {
existKnowledgeBaseId: {
label: "既存のAmazon Bedrock Knowledge BaseのID",
description: "既存のAmazon Bedrock Knowledge Baseを使用することができる",
label: '既存のAmazon Bedrock Knowledge BaseのID',
description:
'既存のAmazon Bedrock Knowledge Baseを使用することができる',
createNewKb: {
label: '新規のナレッジを作成する',
},
existing: {
label: '外部のナレッジ(Knowledge Base)を利用する',
}
},
},
}
},
},
error: {
answerResponse: '回答中にエラーが発生しました。',
Expand Down

0 comments on commit 57c55b4

Please sign in to comment.