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

Fix: merge existing knowledge base configuration when modifying bot #687

Merged
merged 2 commits into from
Jan 16, 2025
Merged
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
26 changes: 19 additions & 7 deletions backend/app/usecases/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,24 @@ def modify_owned_bot(
else "SUCCEEDED"
)

# Use the existing knowledge base (KB) configuration if available, as it may have been set externally
# by a Step Functions state machine for embedding processes e.g. data source id. If a new KB configuration is provided,
# merge it with the existing one; otherwise, retain the current KB settings.
current_bot_kb = bot.bedrock_knowledge_base
updated_kb: BedrockKnowledgeBaseModel | None = None
if modify_input.bedrock_knowledge_base:
updated_kb = (
current_bot_kb.model_copy(
update=modify_input.bedrock_knowledge_base.model_dump()
)
if current_bot_kb
else BedrockKnowledgeBaseModel(
**modify_input.bedrock_knowledge_base.model_dump()
)
)
else:
updated_kb = current_bot_kb

update_bot(
user_id,
bot_id,
Expand Down Expand Up @@ -375,13 +393,7 @@ def modify_owned_bot(
for starter in modify_input.conversation_quick_starters
]
),
bedrock_knowledge_base=(
BedrockKnowledgeBaseModel(
**modify_input.bedrock_knowledge_base.model_dump()
)
if modify_input.bedrock_knowledge_base
else None
),
bedrock_knowledge_base=updated_kb,
bedrock_guardrails=(
BedrockGuardrailsModel(**modify_input.bedrock_guardrails.model_dump())
if modify_input.bedrock_guardrails
Expand Down
Loading