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

feat: add bedrock api #522

merged 7 commits into from
Jan 23, 2025

Conversation

NingLu
Copy link
Collaborator

@NingLu NingLu commented Jan 23, 2025

Fixes #

🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request introduces improvements to the chatbot management functionality in the application. The changes include updates to the backend Lambda functions responsible for processing chatbot data, as well as modifications to the frontend React components and localization files for the chatbot management interface.

The key changes are:

  1. Enhancements to the ETL (Extract, Transform, Load) process for chatbot data, including updates to the Python scripts for handling DynamoDB operations and text embeddings.
  2. Improvements to the chatbot management interface, with updates to the React components for displaying chatbot details and managing chatbots.
  3. Localization updates for the English and Chinese language files to support the new chatbot management features.

These changes aim to provide a more robust and user-friendly experience for managing chatbots within the application.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

File Stats Summary

File number involved in this PR: 12, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/lambda/etl/constant.py 8 added, 0 removed The code adds a new Enum class called ModelProvider with four options: DMAA, BEDROCK, BRCONNECTOR_BEDROCK, and OPENAI, likely representing different model providers.
source/infrastructure/cli/magic-config.ts 17 added, 1 removed The code changes add a new embedding model from the OpenAI API with 1024 dimensions and include comments for potential future additions related to model providers and API configurations.
source/portal/src/utils/const.ts 22 added, 0 removed This code change introduces two new arrays, BEDROCK_API_EMBEDDING_MODEL_LIST and OPENAI_API_EMBEDDING_MODEL_LIST, containing embedding model options for different AI providers.
source/lambda/etl/utils/embeddings.py 15 added, 7 removed The code changes remove the condition for the "embedding" endpoint and add new conditions for OpenAI's "text-embedding-3-small" and "text-embedding-3-large" models, along with their dimensions and types.
source/portal/src/pages/chatbotManagement/ChatbotDetail.tsx 25 added, 3 removed The code changes add two new properties, modelProvider and baseUrl, to the chatbotDetail object, and display them in a grid layout along with the existing id and chatbotName fields.
source/portal/src/types/index.ts 9 added, 1 removed The code changes introduce a new property ModelProvider to the ChatbotItem type and additional properties model_provider and base_url to the model object in ChatbotDetailResponse and ChatbotItemDetail types.
source/portal/src/pages/chatbot/ChatBot.tsx 1 added, 3 removed The code changes involve removing two unused state variables (brModelOption and brApiModelList), updating the label text for a form field from "Model Type" to "Model Provider", and making some minor formatting changes.
source/lambda/etl/chatbot_management.py 20 added, 3 removed The code changes include adding support for specifying the model provider, base URL, and API key ARN when creating a chatbot, retrieving and displaying the model provider information when listing or getting chatbots, and importing a constant for the ModelProvider enum.
source/portal/src/locale/zh.json 10 added, 9 removed The code changes involve updating the name, welcome message, project description, and solution name to "Multi-modal Enterprise Knowledge Base in Manufacturing" from "AI Customer Service". It also updates the industry domain to "Manufacturing" from "Media and Advertising". Additionally, it adds a "modelProvider" field and updates some field descriptions.
source/lambda/etl/utils/ddb_utils.py 8 added, 1 removed The code changes add new parameters (model_provider, base_url, api_key_arn) to the initiate_model function and update the embedding_info dictionary with these new parameters.
source/portal/src/locale/en.json 11 added, 10 removed The code changes update the solution name from "AI Customer Service" to "Multi-modal Enterprise Knowledge Base in Manufacturing", update the welcome message, project description, and use case details to align with the new solution name and manufacturing domain.
source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx 142 added, 10 removed The code changes involve adding support for different model providers (Bedrock API and OpenAI API), allowing users to select the model provider, enter API endpoint and API key ARN for authentication, and dynamically loading the available embedding models based on the selected provider.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request introduces improvements to the chatbot management functionality in the application. The changes include updates to the backend Python code for handling chatbot data, as well as modifications to the React components and localization files in the frontend portal.

The key updates are:

  1. Refactored the chatbot_management.py file to enhance the chatbot creation and management process.
  2. Updated the constant.py and ddb_utils.py files to support the new chatbot management features.
  3. Modified the embeddings.py file to improve the handling of embeddings for chatbot responses.
  4. Updated the ChatBot.tsx, ChatbotDetail.tsx, and ChatbotManagement.tsx components to reflect the changes in the backend and provide an improved user experience.
  5. Modified the en.json and zh.json localization files to include new translations related to the chatbot management features.
  6. Updated the index.ts and const.ts files to support the new functionality.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

File Stats Summary

File number involved in this PR: 12, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/infrastructure/cli/magic-config.ts 7 added, 1 removed The code adds a new object representing the OpenAI embedding model with a 1024-dimensional vector to the embeddingModels array and leaves the apiInferenceProviders array unchanged.
source/lambda/etl/constant.py 8 added, 0 removed The code adds a new enum class called ModelProvider with four options: DMAA, BEDROCK, BRCONNECTOR_BEDROCK, and OPENAI.
source/portal/src/utils/const.ts 22 added, 0 removed This code change adds two new constant arrays, BEDROCK_API_EMBEDDING_MODEL_LIST and OPENAI_API_EMBEDDING_MODEL_LIST, containing embedding model configurations for different providers.
source/lambda/etl/chatbot_management.py 20 added, 3 removed The code changes involve adding new parameters for chatbot model configuration, such as model provider, base URL, and API key ARN, and updating functions to handle these new parameters during chatbot creation, listing, and retrieval.
source/portal/src/locale/en.json 11 added, 10 removed The code changes update the solution name from "AI Customer Service" to "Multi-modal Enterprise Knowledge Base in Manufacturing", update the welcome message, project description, and domain from "Media & Advertisement" to "Manufacturing", and make minor text updates.
source/portal/src/pages/chatbot/ChatBot.tsx 1 added, 3 removed The code changes involve removing commented-out lines related to brModelOption and brApiModelList, and renaming the label for the model selection dropdown from "Model Type" to "Model Provider".
source/portal/src/pages/chatbotManagement/ChatbotDetail.tsx 25 added, 3 removed The code changes add two new properties, modelProvider and baseUrl, to the chatbotDetail object, and display them in additional FormField components on the UI.
source/portal/src/types/index.ts 9 added, 1 removed The code changes introduce new properties 'ModelProvider' and 'base_url' to the ChatbotItem, ChatbotDetailResponse, and ChatbotItemDetail types, allowing for storing the model provider and base URL information.
source/lambda/etl/utils/embeddings.py 15 added, 7 removed The code changes remove the condition for "embedding" in the endpoint name, add conditions for OpenAI's text-embedding-3-small and text-embedding-3-large models, and move the condition for Netease's embedding model to the end.
source/lambda/etl/utils/ddb_utils.py 8 added, 1 removed The code changes add support for model provider, base URL, and API key ARN when initiating or updating a model, allowing for more comprehensive model configuration.
source/portal/src/locale/zh.json 10 added, 9 removed The code changes involve updating the name, welcome message, project description, and solution name related to a "Multi-modal Enterprise Knowledge Base in Manufacturing" application, along with some minor text updates and additions like model provider and temperature fields.
source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx 142 added, 10 removed This code change introduces several new features and improvements to the chatbot management system, including:
  1. Added support for different model providers (Bedrock API and OpenAI API) with dynamic model list loading based on the selected provider.
  2. Implemented input fields for API endpoint and API key ARN with validation for proper URL and ARN formats.
  3. Integrated model provider, API endpoint, and API key ARN into the chatbot creation/update process.
  4. Enhanced the table view by adding a new column to display the model provider for each chatbot. |
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request introduces enhancements to the chatbot management functionality within the application. It includes modifications to the backend Lambda functions responsible for handling chatbot-related operations, as well as updates to the frontend React components and localization files to support the new features.

The main changes include:

  1. Chatbot Management Improvements: The chatbot_management.py file has been updated to streamline the process of creating, updating, and deleting chatbots. This includes optimizations to the underlying database operations and better error handling.

  2. Embeddings Utility: The embeddings.py file has been modified to include additional functionality for generating and managing embeddings, which are used for semantic search and retrieval within the chatbot system.

  3. DynamoDB Utilities: The ddb_utils.py file has been updated to include new helper functions for interacting with the DynamoDB database, which is used to store chatbot-related data.

  4. Frontend Enhancements: The React components (ChatBot.tsx, ChatbotDetail.tsx, and ChatbotManagement.tsx) have been updated to incorporate the new backend changes and provide an improved user experience for managing chatbots. This includes better error handling, improved UI/UX, and support for the new features.

  5. Localization Updates: The localization files (en.json and zh.json) have been updated to include new translation strings for the added functionality.

  6. Type Definitions: The index.ts file, which contains TypeScript type definitions, has been updated to reflect the changes made to the codebase.

  7. Constants and Configuration: The constant.py and const.ts files have been updated to include new constants and configuration values related to the chatbot management functionality.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

File Stats Summary

File number involved in this PR: 12, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/portal/src/utils/const.ts 22 added, 0 removed This code change introduces two new constants, BEDROCK_API_EMBEDDING_MODEL_LIST and OPENAI_API_EMBEDDING_MODEL_LIST, containing lists of embedding models for different APIs.
source/lambda/etl/utils/embeddings.py 15 added, 7 removed The code changes add support for OpenAI's text-embedding-3 models (small and large) and move the Netease embedding model check to the end.
source/lambda/etl/utils/ddb_utils.py 8 added, 1 removed The code changes add new parameters (model_provider, base_url, api_key_arn) to the initiate_model function and update the embedding_info dictionary with these new parameters.
source/portal/src/types/index.ts 9 added, 1 removed The code changes introduce new properties ModelProvider and base_url in the ChatbotItem, ChatbotDetailResponse, and ChatbotItemDetail types to store information about the model provider and base URL.
source/infrastructure/cli/magic-config.ts 13 added, 1 removed The code adds two new embedding models from the OpenAI API, "text-embedding-3-small" and "text-embedding-3-large", with dimensions 1536 and 3072 respectively.
source/lambda/etl/constant.py 8 added, 0 removed The code adds a new enumeration class 'ModelProvider' with four options: 'DMAA', 'Bedrock', 'BRCONNECTOR_BEDROCK', and 'OPENAI'.
source/portal/src/locale/zh.json 10 added, 9 removed The code changes update the application name to "Multi-modal Enterprise Knowledge Base in Manufacturing", modify the welcome message, project description, and solution name accordingly, add a new field "modelProvider", and update some other field descriptions.
source/portal/src/pages/chatbotManagement/ChatbotDetail.tsx 25 added, 3 removed The code changes add two new properties, modelProvider and baseUrl, to the chatbotDetail object, and display them in the UI using additional FormField components in a Grid layout.
source/lambda/etl/chatbot_management.py 20 added, 3 removed The code changes involve adding support for different model providers, base URLs, and API key ARNs when creating and managing chatbots. It also includes retrieving and displaying the model provider information when listing or getting chatbot details.
source/portal/src/pages/chatbot/ChatBot.tsx 1 added, 3 removed The code changes involve removing commented-out lines related to brModelOption and brApiModelList, and renaming the label for the model selection dropdown from "Model Type" to "Model Provider".
source/portal/src/locale/en.json 11 added, 10 removed The code changes update the application name from "AI Customer Service" to "Multi-modal Enterprise Knowledge Base in Manufacturing", modify the welcome message and project description accordingly, and update some descriptions to be more concise.
source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx 142 added, 10 removed This code change introduces new features for managing chatbot models and API configurations. It adds options to select the model provider (Bedrock API or OpenAI API), input fields for API endpoint and API key ARN, and validation for their input formats. It also updates the model list based on the selected provider.
🤖 AI-Generated PR Description (Powered by Amazon Bedrock)

Description

This pull request includes changes to the chatbot management feature, including updates to the frontend, backend, and infrastructure components. The main changes are:

  1. Frontend Updates: Modifications to the ChatBot.tsx, ChatbotDetail.tsx, and ChatbotManagement.tsx components to enhance the user interface and improve the chatbot management experience. Localization files (en.json and zh.json) have been updated to support additional languages.

  2. Backend Updates: Updates to the chatbot_management.py and constant.py files in the ETL (Extract, Transform, Load) process, along with changes to utility functions in ddb_utils.py and embeddings.py for better data handling and processing.

  3. Infrastructure Updates: Changes to the magic-config.ts file in the CLI (Command-Line Interface) for infrastructure management.

  4. Dependency Updates: A new version of the llm_bot_dep package (llm_bot_dep-0.1.0-py3-none-any.whl) has been included, with modifications to the sm_utils.py file within the package.

  5. Type Definitions: Updates to the index.ts file in the types directory to reflect changes in data structures and types used throughout the application.

  6. Constants: Modifications to the const.ts file in the utils directory to accommodate new features or configurations.

The motivation behind these changes is to enhance the overall functionality, user experience, and maintainability of the chatbot management system. This includes improving the frontend interface, optimizing backend processes, and keeping the infrastructure and dependencies up-to-date.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

File Stats Summary

File number involved in this PR: 13, unfold to see the details:

The file changes summary is as follows:

Files
Changes
Change Summary
source/lambda/etl/constant.py 8 added, 0 removed The code adds a new enumeration called ModelProvider with four values: DMAA, BEDROCK, BRCONNECTOR_BEDROCK, and OPENAI, likely representing different model providers.
source/infrastructure/cli/magic-config.ts 13 added, 1 removed The code adds two new embedding models from the OpenAI API, "text-embedding-3-small" and "text-embedding-3-large", with dimensions 1536 and 3072, respectively.
source/lambda/etl/utils/ddb_utils.py 8 added, 1 removed The code changes add support for storing model provider, base URL, and API key ARN along with the existing embedding endpoint information when initiating or updating a model.
source/lambda/job/dep/llm_bot_dep/sm_utils.py 1 added, 2 removed The code changes remove the need to set the AWS region explicitly, allowing boto3 to automatically detect and use the correct region for the AWS Secrets Manager client.
source/portal/src/utils/const.ts 22 added, 0 removed The code adds two new constants, BEDROCK_API_EMBEDDING_MODEL_LIST and OPENAI_API_EMBEDDING_MODEL_LIST, containing lists of embedding models for different APIs.
source/portal/src/locale/en.json 11 added, 10 removed The code changes update the name and description of the solution from "AI Customer Service" to "Multi-modal Enterprise Knowledge Base in Manufacturing", as well as modify some related texts and configurations.
source/portal/src/pages/chatbot/ChatBot.tsx 1 added, 3 removed The code changes involve removing commented-out lines related to 'brApiModelOption' and 'brApiModelList', and changing the label text of a form field from 'modelType' to 'modelProvider'.
source/portal/src/locale/zh.json 10 added, 9 removed The code changes update the application name, description, and domain from "AI Customer Service" to "Multi-modal Enterprise Knowledge Base in Manufacturing", and make some minor text updates related to the new domain.
source/portal/src/types/index.ts 9 added, 1 removed The code changes introduce new properties 'ModelProvider' and 'base_url' to the ChatbotItem, ChatbotDetailResponse, and ChatbotItemDetail types, allowing for storing the model provider and base URL information.
source/lambda/etl/utils/embeddings.py 15 added, 7 removed This code change removes the condition for "embedding" in embedding_endpoint_name and adds new conditions for "text-embedding-3-small", "text-embedding-3-large" from OpenAI API, while keeping the existing conditions for other embedding providers.
source/portal/src/pages/chatbotManagement/ChatbotDetail.tsx 25 added, 3 removed The code changes add two new properties, modelProvider and baseUrl, to the chatbotDetail object, and display them in the UI using additional FormField components.
source/lambda/etl/chatbot_management.py 20 added, 3 removed The code changes involve adding support for specifying the model provider, base URL, and API key ARN when creating a chatbot. It also retrieves and displays the model provider information when listing or getting chatbot details.
source/portal/src/pages/chatbotManagement/ChatbotManagement.tsx 142 added, 10 removed The code changes include the following:
  1. Imported additional constants from src/utils/const.
  2. Added functions to validate URL and AWS ARN.
  3. Added state variables for model type, API endpoint, API key ARN, and related error messages.
  4. Implemented logic to populate model list based on selected model type (Bedrock API or OpenAI API).
  5. Added form fields for selecting model provider, API endpoint, API key ARN, and corresponding validations.
  6. Updated chatbot creation API call to include model provider, base URL, and API key ARN.
  7. Added 'modelProvider' column to the chatbot table. |

Copy link
Contributor

@IcyKallen IcyKallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@IcyKallen IcyKallen merged commit 6e0c500 into dev Jan 23, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants