Skip to content

Commit

Permalink
Fix: merge existing knowledge base configuration when modifying bot (#…
Browse files Browse the repository at this point in the history
…687)

* fix: merge existing knowledge base configuration when modifying bot

* chore: lint
  • Loading branch information
statefb authored Jan 16, 2025
1 parent 6d0b98c commit 69b47d7
Showing 1 changed file with 19 additions and 7 deletions.
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

0 comments on commit 69b47d7

Please sign in to comment.