Skip to content

Commit

Permalink
Add IBM Models Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroGomes02 committed Nov 25, 2024
1 parent ab6dcf7 commit 0e9f64c
Show file tree
Hide file tree
Showing 9 changed files with 1,349 additions and 238 deletions.
Empty file.
45 changes: 45 additions & 0 deletions api/core/model_runtime/model_providers/ibm/_assets/icon_l_en.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions api/core/model_runtime/model_providers/ibm/_assets/icon_s_en.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions api/core/model_runtime/model_providers/ibm/ibm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import logging

from ibm_watsonx_ai import APIClient, Credentials

from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.__base.model_provider import ModelProvider

logger = logging.getLogger(__name__)


class IbmProvider(ModelProvider):
def validate_provider_credentials(self, credentials: dict) -> None:
"""
Validate provider credentials
if validate failed, raise exception
:param credentials: provider credentials, credentials form defined in `provider_credential_schema`.
"""
try:
credentials = Credentials(
url=credentials.get("base_url"),
api_key=credentials.get("api_key")
)

client = APIClient(credentials)
except CredentialsValidateFailedError as ex:
raise ex
except Exception as ex:
logger.exception(
f"{self.get_provider_schema().provider} credentials validate failed")
raise ex
Loading

0 comments on commit 0e9f64c

Please sign in to comment.