Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bedrock api #522

Merged
merged 7 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion source/infrastructure/cli/magic-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ const embeddingModels = [
name: "bce-embedding-and-bge-reranker",
commitId: "43972580a35ceacacd31b95b9f430f695d07dde9",
dimensions: 768,
}
},
{
provider: "OpenAI API",
name: "text-embedding-3-small",
commitId: "",
dimensions: 1536,
},
{
provider: "OpenAI API",
name: "text-embedding-3-large",
commitId: "",
dimensions: 3072,
},
];

const apiInferenceProviders = [
Expand Down
23 changes: 20 additions & 3 deletions source/lambda/etl/chatbot_management.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import logging
import os
import time
from datetime import datetime, timezone

import boto3
Expand All @@ -13,6 +12,8 @@
initiate_index,
initiate_model
)
from constant import ModelProvider


logger = logging.getLogger()
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -52,6 +53,9 @@
def create_chatbot(event, group_name):
request_body = json.loads(event["body"])
chatbot_id = request_body.get("chatbotId", group_name.lower())
model_provider = request_body.get("modelProvider", ModelProvider.BEDROCK.value)
base_url = request_body.get("baseUrl", "")
api_key_arn = request_body.get("apiKeyArn", "")
chatbot_description = request_body.get(
"chatbotDescription", "Answer question based on search result"
)
Expand All @@ -61,7 +65,15 @@ def create_chatbot(event, group_name):
create_time = str(datetime.now(timezone.utc))

model_type = initiate_model(
model_table, group_name, model_id, chatbot_embedding, create_time)
model_table,
group_name,
model_id,
chatbot_embedding,
model_provider,
base_url,
api_key_arn,
create_time
)
index = request_body.get("index", {"qq":{"admin-qq-default": "Answer question based on search result"},"qd":{"admin-qd-default": "Answer question based on search result"},"intention":{"admin-intention-default": "Answer question based on search result"}})
for index_type in index:
index_ids = list(index[index_type].keys())
Expand Down Expand Up @@ -142,6 +154,7 @@ def __list_chatbot(event, group_name):
item_json["ModelId"] = chatbot_model_item.get("modelId", "")
item_json["LastModifiedTime"] = item.get(
"updateTime", {"S": ""})["S"]
item_json["ModelProvider"] = chatbot_model_item["parameter"].get("ModelProvider", "")
page_json.append(item_json)
page_json.sort(key=lambda x: x["LastModifiedTime"], reverse=True)
output["Items"] = page_json
Expand Down Expand Up @@ -180,6 +193,8 @@ def __get_chatbot(event, group_name):
model = model_item.get("parameter", {})
model_endpoint = model.get("ModelEndpoint", {})
model_name = model.get("ModelName", {})
model_provider = model.get("ModelProvider", "")
base_url = model.get("BaseUrl", "")
chatbot_index = []
for key, value in chatbot_index_ids.items():
v = value.get('value',{})
Expand All @@ -201,7 +216,9 @@ def __get_chatbot(event, group_name):
"updateTime": update_time,
"model": {
"model_endpoint": model_endpoint,
"model_name": model_name
"model_name": model_name,
"model_provider": model_provider,
"base_url": base_url
},
"index": chatbot_index,
}
Expand Down
8 changes: 8 additions & 0 deletions source/lambda/etl/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@ class OperationType(Enum):
UPDATE = "update"
DELETE = "delete"
EXTRACT_ONLY = "extract_only"


@unique
class ModelProvider(Enum):
DMAA = "dmaa"
BEDROCK = "Bedrock"
BRCONNECTOR_BEDROCK = "Bedrock API"
OPENAI = "OpenAI API"
9 changes: 8 additions & 1 deletion source/lambda/etl/utils/ddb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ def update_model(model_table, item_key, model_parameter):
)


def initiate_model(model_table, group_name, model_id, embedding_endpoint, create_time=None):
def initiate_model(model_table, group_name, model_id, embedding_endpoint, model_provider, base_url, api_key_arn, create_time=None):
existing_item = item_exist(model_table, {"groupName": group_name, "modelId": model_id})
embedding_info = get_embedding_info(embedding_endpoint)
embedding_info["ModelEndpoint"] = embedding_endpoint
embedding_info["ModelProvider"] = model_provider
embedding_info["BaseUrl"] = base_url
embedding_info["ApiKeyArn"] = api_key_arn

if existing_item:
existing_embedding_endpoint = existing_item["parameter"]["ModelEndpoint"]
if existing_embedding_endpoint != embedding_endpoint:
embedding_info = get_embedding_info(embedding_endpoint)
embedding_info["ModelProvider"] = model_provider
embedding_info["BaseUrl"] = base_url
embedding_info["ApiKeyArn"] = api_key_arn
update_model(
model_table,
{"groupName": group_name, "modelId": model_id},
Expand Down
22 changes: 15 additions & 7 deletions source/lambda/etl/utils/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ def get_embedding_info(embedding_endpoint_name):
embeddings_model_name = "bge-m3"
embeddings_model_dimensions = 1024
embeddings_model_type = "m3"

elif "embedding" in embedding_endpoint_name:
embeddings_model_provider = "Netease"
embeddings_model_name = "bce_embedding_model.tar.gz"
embeddings_model_dimensions = 768
embeddings_model_type = "bce"

elif "cohere" in embedding_endpoint_name:
embeddings_model_provider = "Cohere"
embeddings_model_name = "cohere.embed-english-v3"
Expand All @@ -42,6 +35,21 @@ def get_embedding_info(embedding_endpoint_name):
embeddings_model_name = "amazon.titan-embed-text-v2:0"
embeddings_model_dimensions = 1024
embeddings_model_type = "bedrock"
elif "text-embedding-3-small" in embedding_endpoint_name:
embeddings_model_provider = "OpenAI API"
embeddings_model_name = "text-embedding-3-small"
embeddings_model_dimensions = 1536
embeddings_model_type = "OpenAI API"
elif "text-embedding-3-large" in embedding_endpoint_name:
embeddings_model_provider = "OpenAI API"
embeddings_model_name = "text-embedding-3-large"
embeddings_model_dimensions = 3072
embeddings_model_type = "OpenAI API"
elif "embedding" in embedding_endpoint_name:
embeddings_model_provider = "Netease"
embeddings_model_name = "bce_embedding_model.tar.gz"
embeddings_model_dimensions = 768
embeddings_model_type = "bce"
else:
embeddings_model_provider = "Not Found"
embeddings_model_name = "Not Found"
Expand Down
Binary file modified source/lambda/job/dep/dist/llm_bot_dep-0.1.0-py3-none-any.whl
Binary file not shown.
3 changes: 1 addition & 2 deletions source/lambda/job/dep/llm_bot_dep/sm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@

logger = logging.getLogger()
logger.setLevel(logging.INFO)
region_name = os.environ["AWS_REGION"]
session = boto3.session.Session()
secret_manager_client = session.client(
service_name="secretsmanager", region_name=region_name
service_name="secretsmanager"
)


Expand Down
21 changes: 11 additions & 10 deletions source/portal/src/locale/en.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"translation": {
"name": "AI Customer Service",
"name": "Multi-modal Enterprise Knowledge Base in Manufacturing",
"welcome": "Welcome to Multi-modal Enterprise Knowledge Base in Manufacturing",
"mead": "Manufacturing",
"projectDescription": "Multi-modal Enterprise Knowledge Base in Manufacturing offers a streamlined workflow for developing scalable, production-grade agent-based applications",
"solutionName": "Multi-modal Enterprise Knowledge Base in Manufacturing",
"desc": "Description",
"welcome": "Welcome to AI Customer Service",
"you": "Y o u",
"welcomeMessage": "Hello, how can I help you today?",
"server": "Server",
Expand Down Expand Up @@ -98,6 +101,7 @@
"noChatbotFound": "No chatbot found",
"scenario": "Scenario",
"modelType": "Model provider",
"modelProvider": "Model provider",
"maxTokens": "Max Tokens",
"temperature": "Temperature",
"sessionHistory": "Recent chats",
Expand Down Expand Up @@ -175,7 +179,7 @@
"referenceDocuments": "Reference Documents",
"selectADocumentToPreview": "Select a document to preview its content",
"button": {
"login": "Log in to AI Customer Service",
"login": "Log in to Multi-modal Enterprise Knowledge Base in Manufacturing",
"reload": "Reload",
"send": "Send",
"modelSettings": "Model Settings",
Expand Down Expand Up @@ -247,11 +251,8 @@
"next": "Next",
"skip": "Skip tour"
},
"solutionName": "AI Customer Service",
"subTitle": "Streamlined Workflow for Building Agent-Based Applications",
"projectDescription": "AI Customer Service offers a streamlined workflow for developing scalable, production-grade agent-based applications",
"awsSolutionGuidance": "Amazon Web Services Solution Guidance",
"mead": "Media & Advertisement",
"homeSidebar": "Home",
"chatbotDetail": "ChatBot Detail",
"featuresAndBenefits": {
Expand All @@ -266,18 +267,18 @@
},
"feat3": {
"name": "Intention detection",
"desc": "desc"
"desc": "Desc"
},
"feat4": {
"name": "Management and governance",
"desc": "desc"
"desc": "Desc"
}
},
"useCases": {
"name": "Use cases",
"case1": {
"name": "MEAD use case",
"desc": "desc"
"name": "Use case",
"desc": "Desc"
}
},
"gettingStarted": {
Expand Down
19 changes: 10 additions & 9 deletions source/portal/src/locale/zh.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"translation": {
"name": "AI Customer Service",
"name": "Multi-modal Enterprise Knowledge Base in Manufacturing",
"welcome": "欢迎使用 Multi-modal Enterprise Knowledge Base in Manufacturing",
"mead": "制造",
"projectDescription": "Multi-modal Enterprise Knowledge Base in Manufacturing 提供一个高效简洁的工作流程,用于开发可扩展的、生产级别的、基于 agent(代理)的应用",
"solutionName": "Multi-modal Enterprise Knowledge Base in Manufacturing",
"desc": "描述",
"welcome": "欢迎使用 AI Customer Service",
"you": "你",
"welcomeMessage": "您好,我今天有什么可以帮助您?",
"server": "服务器",
Expand Down Expand Up @@ -108,6 +111,7 @@
"embeddingModelDesc": "用于此机器人的向量化操作",
"scenario": "场景",
"modelType": "模型供应商",
"modelProvider": "模型供应商",
"maxTokens": "最大 Token 数",
"temperature": "温度",
"sessionHistory": "历史记录",
Expand Down Expand Up @@ -240,11 +244,8 @@
"next": "下一步",
"skip": "跳过向导"
},
"solutionName": "AI Customer Service",
"subTitle": "构建基于代理的应用程序的优化工作流",
"projectDescription": "AI Customer Service提供一个高效简洁的工作流程,用于开发可扩展的、生产级别的、基于 agent(代理)的应用",
"awsSolutionGuidance": "Amazon Web Services 解决方案指南",
"mead": "媒体与广告",
"homeSidebar": "首页",
"chatbotDetail": "机器人详情",
"featuresAndBenefits": {
Expand All @@ -259,18 +260,18 @@
},
"feat3": {
"name": "Intention detection",
"desc": "desc"
"desc": "Desc"
},
"feat4": {
"name": "Management and governance",
"desc": "desc"
"desc": "Desc"
}
},
"useCases": {
"name": "使用案例",
"case1": {
"name": "MEAD use case",
"desc": "desc"
"name": "Use case",
"desc": "Desc"
}
},
"gettingStarted": {
Expand Down
4 changes: 1 addition & 3 deletions source/portal/src/pages/chatbot/ChatBot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ const ChatBot: React.FC<ChatBotProps> = (props: ChatBotProps) => {
const [currentAIMessageId, setCurrentAIMessageId] = useState('');
const [aiSpeaking, setAiSpeaking] = useState(false);
const [modelOption, setModelOption] = useState('');
// const [brModelOption, setBrApiModelOption] = useState('');
const [modelList, setModelList] = useState<SelectProps.Option[]>([]);
// const [brApiModelList, setBrApiModelList] = useState<SelectProps.Option[]>([]);
const [chatbotList, setChatbotList] = useState<SelectProps.Option[]>([]);
const [chatbotOption, setChatbotOption] = useState<SelectProps.Option>(null as any);
const [useChatHistory, setUseChatHistory] = useState(localStorage.getItem(USE_CHAT_HISTORY) == null || localStorage.getItem(USE_CHAT_HISTORY) == "true" ? true : false);
Expand Down Expand Up @@ -774,7 +772,7 @@ const ChatBot: React.FC<ChatBotProps> = (props: ChatBotProps) => {
<div style={{fontSize: 16, fontWeight: 700, marginBottom: 15, marginTop: 15}}>{t('common')}</div>
<SpaceBetween size="xs" direction="vertical">
<Grid gridDefinition={[{colspan: 5},{colspan: 6}]}>
<FormField label={t('modelType')} stretch={true} description={t('scenarioDesc')}>
<FormField label={t('modelProvider')} stretch={true} description={t('scenarioDesc')}>
<Select
options={MODEL_TYPE_LIST}
selectedOption={modelType}
Expand Down
28 changes: 25 additions & 3 deletions source/portal/src/pages/chatbotManagement/ChatbotDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ const ChatbotDetail: React.FC = () => {
chatbotId: data.chatbotId,
model: data.model?.model_name,
index: data.index,
updateTime: data.updateTime
updateTime: data.updateTime,
modelProvider: data.model?.model_provider,
baseUrl: data.model?.base_url
};
setChatbotDetail(chatbotDetail)
// setIndexList(chatbotDetail.index)
Expand Down Expand Up @@ -277,15 +279,35 @@ const ChatbotDetail: React.FC = () => {
<SpaceBetween direction="vertical" size="xs">

<div className="mt-10">
<Grid
gridDefinition={[{ colspan: 4 }, { colspan: 4 }, { colspan: 4 }]}
<Grid
gridDefinition={[
{ colspan: 3 },
{ colspan: 3 },
{ colspan: 3 },
{ colspan: 3 },
{ colspan: 3 }
]}
>
<div>
<FormField
description={id}

label={t("chatbotName")}
>
</FormField>
</div>
<div>
<FormField
description={chatbotDetail?.modelProvider}
label={t("modelProvider")}
>
</FormField>
</div>
<div>
<FormField
description={chatbotDetail?.baseUrl}
label={t("apiEndpoint")}
>
</FormField>
</div>
<div>
Expand Down
Loading
Loading