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: support select bot and delete bot #366

Merged
merged 3 commits into from
Aug 29, 2024
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
15 changes: 12 additions & 3 deletions source/lambda/etl/chatbot_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_query_parameter(event, parameter_name, default_value=None):

def __create_chatbot(event, group_name):
request_body = json.loads(event["body"])
chatbot_id = request_body.get("chatbotId", group_name.lower())
chatbot_id = request_body.get("ChatbotId", group_name.lower())
chatbot_description = request_body.get(
"chatbotDescription", "Answer question based on search result"
)
Expand All @@ -68,7 +68,11 @@ def __create_chatbot(event, group_name):
# Iterate over all enum members and create DDB metadata
for member in IndexType.__members__.values():
index_type = member.value
index_ids = request_body.get(index_type, f"{chatbot_id}-{index_type}-default")
index_ids = (
request_body.get("Chatbot", {})
.get(index_type, {})
.get("index", f"{chatbot_id}-{index_type}-default")
)
index_id_list[index_type] = index_ids
for index_id in index_ids.split(","):
tag = index_id
Expand Down Expand Up @@ -207,7 +211,12 @@ def __get_chatbot(event, group_name):


def __delete_chatbot(event, group_name):
return {"Message": "Not Implemented"}
chatbot_id = event["path"].split("/")[-1]

response = chatbot_table.delete_item(
Key={"groupName": group_name, "chatbotId": chatbot_id}
)
return response


def lambda_handler(event, context):
Expand Down
1 change: 0 additions & 1 deletion source/lambda/online/lambda_main/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ def compose_connect_body(event_body: dict, context: dict):
"use_history": True,
"enable_trace": True,
"use_websearch": True,
"default_index_config": {"rag_index_ids": ["Admin"]},
"default_llm_config": {
"model_id": "anthropic.claude-3-sonnet-20240229-v1:0",
"endpoint_name": "",
Expand Down
17 changes: 11 additions & 6 deletions source/portal/src/pages/chatbot/ChatBot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const ChatBot: React.FC<ChatBotProps> = (props: ChatBotProps) => {
// const [chatModeOption, setChatModeOption] = useState<SelectProps.Option>(
// LLM_BOT_CHAT_MODE_LIST[0],
// );
const [chatbotList, setChatbotList] = useState<SelectProps.Option[]>([]);
const [chatbotOption, setChatbotOption] = useState<SelectProps.Option>(
LLM_BOT_CHATBOT_LIST[0],
);
Expand All @@ -94,7 +95,6 @@ const ChatBot: React.FC<ChatBotProps> = (props: ChatBotProps) => {
);

const [sessionId, setSessionId] = useState(historySessionId);
const [workspaceIds, setWorkspaceIds] = useState<any[]>([]);

const [temperature, setTemperature] = useState<string>('0.01');
const [maxToken, setMaxToken] = useState<string>('1000');
Expand Down Expand Up @@ -131,7 +131,15 @@ const ChatBot: React.FC<ChatBotProps> = (props: ChatBotProps) => {
url: 'chatbot-management/chatbots',
method: 'get',
});
setWorkspaceIds(data.chatbot_ids);
const chatbots: string[] = data.chatbot_ids;
const getChatbots = chatbots.map((item) => {
return {
label: item,
value: item,
};
}
);
setChatbotList(getChatbots);
} catch (error) {
console.error(error);
return [];
Expand Down Expand Up @@ -323,9 +331,6 @@ const ChatBot: React.FC<ChatBotProps> = (props: ChatBotProps) => {
enable_trace: enableTrace,
use_websearch: true,
google_api_key: '',
default_index_config: {
rag_index_ids: workspaceIds,
},
default_llm_config: {
model_id: modelOption,
endpoint_name:
Expand Down Expand Up @@ -433,7 +438,7 @@ const ChatBot: React.FC<ChatBotProps> = (props: ChatBotProps) => {
<div className="flex-v gap-10">
<div className="flex gap-5 send-message">
<Select
options={LLM_BOT_CHATBOT_LIST}
options={chatbotList}
selectedOption={chatbotOption}
onChange={({ detail }) => {
setChatbotOption(detail.selectedOption);
Expand Down
21 changes: 16 additions & 5 deletions source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const ChatbotManagement: React.FC = () => {
const [showEdit, setShowEdit] = useState(false);
const [loadingSave, setLoadingSave] = useState(false);
const [currentChatbot, setCurrentChatbot] = useState<GetChatbotResponse>();
const [createChatbotId, setCreateChatbotId] = useState('');
const [modelList, setModelList] = useState<SelectProps.Option[]>([]);
// const [chatbotList, setChatbotList] = useState<SelectProps.Option[]>([]);
const [modelOption, setModelOption] = useState<SelectProps.Option | null>(
Expand Down Expand Up @@ -112,9 +113,9 @@ const ChatbotManagement: React.FC = () => {

const getChatbotById = async (type: 'create' | 'edit') => {
setLoadingGet(true);
let requestUrl = `chatbot-management/chatbots/default`;
let requestUrl = `chatbot-management/chatbots/create`;
if (type === 'edit') {
requestUrl = `chatbot-management/chatbots/common`;
requestUrl = `chatbot-management/chatbots/edit`;
setChatbotOption({
label: selectedItems[0].ChatbotId,
value: selectedItems[0].ChatbotId,
Expand All @@ -125,11 +126,17 @@ const ChatbotManagement: React.FC = () => {
});
}
try {
let chatbotIdParam = '';
if (selectedItems.length > 0) {
chatbotIdParam = selectedItems[0].ChatbotId;
} else {
chatbotIdParam = 'admin';
}
const data: GetChatbotResponse = await fetchData({
url: requestUrl,
method: 'get',
params: {
chatbotId: selectedItems[0].ChatbotId,
chatbotId: chatbotIdParam,
},
});
setLoadingGet(false);
Expand All @@ -147,7 +154,7 @@ const ChatbotManagement: React.FC = () => {
setLoadingSave(true);
try {
await fetchData({
url: `chatbot-management/chatbots/common`,
url: `chatbot-management/chatbots/delete/${selectedItems[0].ChatbotId}`,
method: 'delete',
});
setLoadingSave(false);
Expand All @@ -166,6 +173,9 @@ const ChatbotManagement: React.FC = () => {
}
setLoadingSave(true);
try {
if (currentChatbot) {
currentChatbot.ChatbotId = createChatbotId;
}
const data = await fetchData({
url: 'chatbot-management/chatbots',
method: 'post',
Expand Down Expand Up @@ -333,7 +343,7 @@ const ChatbotManagement: React.FC = () => {
variant="primary"
onClick={() => {
getModelList('create');
getChatbotList();
getChatbotById('create');
setShowCreate(true);
}}
>
Expand Down Expand Up @@ -409,6 +419,7 @@ const ChatbotManagement: React.FC = () => {
onChange={({ detail }) => {
setChatbotError('');
setChatbotOption({ value: detail.value, label: detail.value})
setCreateChatbotId(detail.value);
}}
/>
</FormField>
Expand Down
5 changes: 1 addition & 4 deletions source/portal/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ export type ChatbotItem = {
// LastModifiedBy: string;
ModelName: string;
SortKey: string;
Scene: string;
};

export type ChatbotResponse = {
Expand All @@ -206,9 +205,7 @@ export interface Chatbot {

export interface GetChatbotResponse {
GroupName: string;
SortKey: string;
ModelId: string;
Scene: string;
ChatbotId: string;
Chatbot: Chatbot;
}

Expand Down
Loading