def find_public_bot_by_id()

in packages/blueprints/gen-ai-chatbot/static-assets/chatbot-genai-components/backend/python/app/repositories/custom_bot.py [0:0]


def find_public_bot_by_id(bot_id: str) -> BotModel:
    """Find public bot by id."""
    table = _get_table_public_client()  # Use public client
    logger.info(f"Finding public bot with id: {bot_id}")
    response = table.query(
        IndexName="PublicBotIdIndex",
        KeyConditionExpression=Key("PublicBotId").eq(bot_id),
    )
    if len(response["Items"]) == 0:
        raise RecordNotFoundError(f"Public bot with id {bot_id} not found")

    item = response["Items"][0]
    bot = BotModel(
        id=decompose_bot_id(item["SK"]),
        title=item["Title"],
        description=item["Description"],
        instruction=item["Instruction"],
        create_time=float(item["CreateTime"]),
        last_used_time=float(item["LastBotUsed"]),
        is_pinned=item["IsPinned"],
        public_bot_id=item["PublicBotId"],
        owner_user_id=item["PK"],
        embedding_params=EmbeddingParamsModel(
            # For backward compatibility
            chunk_size=(
                item["EmbeddingParams"]["chunk_size"]
                if "EmbeddingParams" in item and "chunk_size" in item["EmbeddingParams"]
                else 1000
            ),
            chunk_overlap=(
                item["EmbeddingParams"]["chunk_overlap"]
                if "EmbeddingParams" in item
                and "chunk_overlap" in item["EmbeddingParams"]
                else 200
            ),
            enable_partition_pdf=(
                item["EmbeddingParams"]["enable_partition_pdf"]
                if "EmbeddingParams" in item
                and "enable_partition_pdf" in item["EmbeddingParams"]
                else False
            ),
        ),
        generation_params=GenerationParamsModel(
            **(
                item["GenerationParams"]
                if "GenerationParams" in item
                else DEFAULT_GENERATION_CONFIG
            )
        ),
        search_params=SearchParamsModel(
            max_results=(
                item["SearchParams"]["max_results"]
                if "SearchParams" in item
                else DEFAULT_SEARCH_CONFIG["max_results"]
            )
        ),
        agent=(
            AgentModel(**item["AgentData"])
            if "AgentData" in item
            else AgentModel(tools=[])
        ),
        knowledge=KnowledgeModel(**item["Knowledge"]),
        sync_status=item["SyncStatus"],
        sync_status_reason=item["SyncStatusReason"],
        sync_last_exec_id=item["LastExecId"],
        published_api_stack_name=(
            None
            if "ApiPublishmentStackName" not in item
            else item["ApiPublishmentStackName"]
        ),
        published_api_datetime=(
            None if "ApiPublishedDatetime" not in item else item["ApiPublishedDatetime"]
        ),
        published_api_codebuild_id=(
            None
            if "ApiPublishCodeBuildId" not in item
            else item["ApiPublishCodeBuildId"]
        ),
        display_retrieved_chunks=item.get("DisplayRetrievedChunks", False),
    )
    logger.info(f"Found public bot: {bot}")
    return bot