Model Provider¶
- pydantic model ibm_watsonx_gov.entities.model_provider.AWSBedrockModelProvider¶
Bases:
ModelProvider
Represents a model provider using Amazon Bedrock.
Examples
- Create provider using credentials object:
provider = AWSBedrockModelProvider( credentials=AWSBedrockCredentials( aws_access_key_id="your-access-key-id", aws_secret_access_key="your-secret-access-key", aws_region_name="us-east-1", aws_session_token="optional-session-token" ) )
- Create provider using environment variables:
os.environ['AWS_ACCESS_KEY_ID'] = "your-access-key-id" os.environ['AWS_SECRET_ACCESS_KEY'] = "your-secret-access-key" os.environ['AWS_SESSION_TOKEN'] = "optional-session-token" # Optional os.environ['AWS_DEFAULT_REGION'] = "us-east-1" provider = AWSBedrockModelProvider()
Show JSON schema
{ "title": "AWSBedrockModelProvider", "description": "Represents a model provider using Amazon Bedrock.\n\nExamples:\n 1. Create provider using credentials object:\n .. code-block:: python\n\n provider = AWSBedrockModelProvider(\n credentials=AWSBedrockCredentials(\n aws_access_key_id=\"your-access-key-id\",\n aws_secret_access_key=\"your-secret-access-key\",\n aws_region_name=\"us-east-1\",\n aws_session_token=\"optional-session-token\"\n )\n )\n\n 2. Create provider using environment variables:\n .. code-block:: python\n\n os.environ['AWS_ACCESS_KEY_ID'] = \"your-access-key-id\"\n os.environ['AWS_SECRET_ACCESS_KEY'] = \"your-secret-access-key\"\n os.environ['AWS_SESSION_TOKEN'] = \"optional-session-token\" # Optional\n os.environ['AWS_DEFAULT_REGION'] = \"us-east-1\"\n provider = AWSBedrockModelProvider()", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "default": "aws_bedrock", "description": "The type of model provider." }, "credentials": { "anyOf": [ { "$ref": "#/$defs/AWSBedrockCredentials" }, { "type": "null" } ], "default": null, "description": "AWS Bedrock credentials." } }, "$defs": { "AWSBedrockCredentials": { "description": "Defines the AWSBedrockCredentials class for accessing AWS Bedrock using environment variables or manual input.\n\nExamples:\n 1. Create credentials manually:\n .. code-block:: python\n\n credentials = AWSBedrockCredentials(\n aws_access_key_id=\"your-access-key-id\",\n aws_secret_access_key=\"your-secret-access-key\",\n aws_region_name=\"us-east-1\",\n aws_session_token=\"optional-session-token\"\n )\n\n 2. Create credentials from environment:\n .. code-block:: python\n\n os.environ[\"AWS_ACCESS_KEY_ID\"] = \"your-access-key-id\"\n os.environ[\"AWS_DEFAULT_REGION\"] = \"us-east-1\"\n os.environ[\"AWS_SECRET_ACCESS_KEY\"] = \"your-secret-access-key\"\n\n credentials = AWSBedrockCredentials.create_from_env()", "properties": { "aws_access_key_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "The AWS access key id. This attribute value will be read from AWS_ACCESS_KEY_ID environment variable when creating AWSBedrockCredentials from environment.", "title": "AWS Access Key ID" }, "aws_secret_access_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "The AWS secret access key. This attribute value will be read from AWS_SECRET_ACCESS_KEY environment variable when creating AWSBedrockCredentials from environment.", "title": "AWS Secret Access Key" }, "aws_region_name": { "default": "us-east-1", "description": "AWS region. This attribute value will be read from AWS_DEFAULT_REGION environment variable when creating AWSBedrockCredentials from environment.", "examples": [ "us-east-1", "eu-west-1" ], "title": "AWS Region", "type": "string" }, "aws_session_token": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "Optional AWS session token for temporary credentials.", "title": "AWS Session Token" } }, "required": [ "aws_access_key_id", "aws_secret_access_key", "aws_session_token" ], "title": "AWSBedrockCredentials", "type": "object" }, "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" } } }
- Fields:
- Validators:
create_credentials_from_env
»all fields
- field credentials: Annotated[AWSBedrockCredentials | None, FieldInfo(annotation=NoneType, required=False, default=None, description='AWS Bedrock credentials.')] = None¶
AWS Bedrock credentials.
- Validated by:
- field type: ', frozen=True)] = ModelProviderType.AWS_BEDROCK¶
The type of model provider.
- Validated by:
- validator create_credentials_from_env » all fields¶
- pydantic model ibm_watsonx_gov.entities.model_provider.AzureOpenAIModelProvider¶
Bases:
ModelProvider
Show JSON schema
{ "title": "AzureOpenAIModelProvider", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "default": "azure_openai", "description": "The type of model provider." }, "credentials": { "anyOf": [ { "$ref": "#/$defs/AzureOpenAICredentials" }, { "type": "null" } ], "default": null, "description": "Azure OpenAI credentials." } }, "$defs": { "AzureOpenAICredentials": { "properties": { "url": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "Azure OpenAI url. This attribute can be read from `AZURE_OPENAI_HOST` environment variable.", "title": "Url" }, "api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "API key for Azure OpenAI. This attribute can be read from `AZURE_OPENAI_API_KEY` environment variable.", "title": "Api Key" }, "api_version": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "The model API version from Azure OpenAI. This attribute can be read from `AZURE_OPENAI_API_VERSION` environment variable.", "title": "Api Version" } }, "required": [ "url", "api_key", "api_version" ], "title": "AzureOpenAICredentials", "type": "object" }, "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" } } }
- Fields:
- Validators:
create_credentials_from_env
»all fields
- field credentials: Annotated[AzureOpenAICredentials | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Azure OpenAI credentials.')] = None¶
Azure OpenAI credentials.
- Validated by:
- field type: ', frozen=True)] = ModelProviderType.AZURE_OPENAI¶
The type of model provider.
- Validated by:
- validator create_credentials_from_env » all fields¶
- pydantic model ibm_watsonx_gov.entities.model_provider.CustomModelProvider¶
Bases:
ModelProvider
Defines the CustomModelProvider class.
This class represents a custom model provider, typically used when integrating with non-standard or user-defined model backends. It sets the provider type to CUSTOM by default.
Examples
- Create a custom model provider:
provider = CustomModelProvider()
- Use with a custom foundation model:
custom_model = CustomFoundationModel( scoring_fn=my_scoring_function, provider=CustomModelProvider() )
- type¶
The type of model provider. Always set to ModelProviderType.CUSTOM.
- Type:
Show JSON schema
{ "title": "CustomModelProvider", "description": "Defines the CustomModelProvider class.\n\nThis class represents a custom model provider, typically used when integrating with non-standard or user-defined\nmodel backends. It sets the provider type to `CUSTOM` by default.\n\nExamples:\n 1. Create a custom model provider:\n .. code-block:: python\n\n provider = CustomModelProvider()\n\n 2. Use with a custom foundation model:\n .. code-block:: python\n\n custom_model = CustomFoundationModel(\n scoring_fn=my_scoring_function,\n provider=CustomModelProvider()\n )\n\nAttributes:\n type (ModelProviderType): The type of model provider. Always set to `ModelProviderType.CUSTOM`.", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "default": "custom", "description": "The type of model provider." } }, "$defs": { "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" } } }
- field type: ')] = ModelProviderType.CUSTOM¶
The type of model provider.
- pydantic model ibm_watsonx_gov.entities.model_provider.GoogleAIStudioModelProvider¶
Bases:
ModelProvider
Represents a model provider using Google AI Studio.
Examples
- Create provider using credentials object:
provider = GoogleAIStudioModelProvider( credentials=GoogleAIStudioCredentials(api_key="api-key") )
- Create provider using environment variables:
os.environ['GOOGLE_API_KEY'] = "your_api_key" provider = GoogleAIStudioModelProvider()
Show JSON schema
{ "title": "GoogleAIStudioModelProvider", "description": "Represents a model provider using Google AI Studio.\n\nExamples:\n 1. Create provider using credentials object:\n .. code-block:: python\n\n provider = GoogleAIStudioModelProvider(\n credentials=GoogleAIStudioCredentials(api_key=\"api-key\")\n )\n\n 2. Create provider using environment variables:\n .. code-block:: python\n\n os.environ['GOOGLE_API_KEY'] = \"your_api_key\"\n\n provider = GoogleAIStudioModelProvider()", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "default": "google_ai_studio", "description": "The type of model provider." }, "credentials": { "anyOf": [ { "$ref": "#/$defs/GoogleAIStudioCredentials" }, { "type": "null" } ], "default": null, "description": "Google AI Studio credentials." } }, "$defs": { "GoogleAIStudioCredentials": { "description": "Defines the GoogleAIStudioCredentials class for accessing Google AI Studio using an API key.\n\nExamples:\n 1. Create credentials manually:\n .. code-block:: python\n\n google_credentials = GoogleAIStudioCredentials(api_key=\"your-api-key\")\n\n 2. Create credentials from environment:\n .. code-block:: python\n\n os.environ[\"GOOGLE_API_KEY\"] = \"your-api-key\"\n google_credentials = GoogleAIStudioCredentials.create_from_env()", "properties": { "api_key": { "description": "The Google AI Studio key. This attribute can be read from GOOGLE_API_KEY environment variable when creating GoogleAIStudioCredentials from environment.", "title": "Api Key", "type": "string" } }, "required": [ "api_key" ], "title": "GoogleAIStudioCredentials", "type": "object" }, "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" } } }
- Fields:
- Validators:
create_credentials_from_env
»all fields
- field credentials: Annotated[GoogleAIStudioCredentials | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Google AI Studio credentials.')] = None¶
Google AI Studio credentials.
- Validated by:
- field type: ', frozen=True)] = ModelProviderType.GOOGLE_AI_STUDIO¶
The type of model provider.
- Validated by:
- validator create_credentials_from_env » all fields¶
- pydantic model ibm_watsonx_gov.entities.model_provider.ModelProvider¶
Bases:
BaseModel
Show JSON schema
{ "title": "ModelProvider", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "description": "The type of model provider." } }, "$defs": { "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" } }, "required": [ "type" ] }
- field type: Annotated[ModelProviderType, FieldInfo(annotation=NoneType, required=True, description='The type of model provider.')] [Required]¶
The type of model provider.
- pydantic model ibm_watsonx_gov.entities.model_provider.OpenAIModelProvider¶
Bases:
ModelProvider
Show JSON schema
{ "title": "OpenAIModelProvider", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "default": "openai", "description": "The type of model provider." }, "credentials": { "anyOf": [ { "$ref": "#/$defs/OpenAICredentials" }, { "type": "null" } ], "default": null, "description": "OpenAI credentials. This can also be set by using `OPENAI_API_KEY` environment variable." } }, "$defs": { "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" }, "OpenAICredentials": { "description": "Defines the OpenAICredentials class to specify the OpenAI server details.\n\nExamples:\n 1. Create OpenAICredentials with default parameters. By default Dallas region is used.\n .. code-block:: python\n\n openai_credentials = OpenAICredentials(api_key=api_key,\n url=openai_url)\n\n 2. Create OpenAICredentials by reading from environment variables.\n .. code-block:: python\n\n os.environ[\"OPENAI_API_KEY\"] = \"...\"\n os.environ[\"OPENAI_URL\"] = \"...\"\n openai_credentials = OpenAICredentials.create_from_env()", "properties": { "url": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Url" }, "api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "title": "Api Key" } }, "required": [ "url", "api_key" ], "title": "OpenAICredentials", "type": "object" } } }
- Fields:
credentials (Annotated[ibm_watsonx_gov.entities.credentials.OpenAICredentials | None, FieldInfo(annotation=NoneType, required=False, default=None, description='OpenAI credentials. This can also be set by using `OPENAI_API_KEY
environment variable.’)]) <ibm_watsonx_gov.entities.model_provider.OpenAIModelProvider.credentials>`type (Annotated[ibm_watsonx_gov.entities.enums.ModelProviderType, FieldInfo(annotation=NoneType, required=False, default=
- Validators:
create_credentials_from_env
»all fields
- field credentials: Annotated[OpenAICredentials | None, FieldInfo(annotation=NoneType, required=False, default=None, description='OpenAI credentials. This can also be set by using `OPENAI_API_KEY` environment variable.')] = None¶
OpenAI credentials. This can also be set by using OPENAI_API_KEY environment variable.
- Validated by:
- field type: ', frozen=True)] = ModelProviderType.OPENAI¶
The type of model provider.
- Validated by:
- validator create_credentials_from_env » all fields¶
- pydantic model ibm_watsonx_gov.entities.model_provider.PortKeyModelProvider¶
Bases:
ModelProvider
Show JSON schema
{ "title": "PortKeyModelProvider", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "default": "portkey", "description": "The type of model provider." }, "credentials": { "anyOf": [ { "$ref": "#/$defs/PortKeyCredentials" }, { "type": "null" } ], "default": null, "description": "PortKey credentials." } }, "$defs": { "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" }, "PortKeyCredentials": { "description": "Defines the PortKeyCredentials class to specify the PortKey Gateway details.\n\nExamples:\n 1. Create PortKeyCredentials with default parameters.\n .. code-block:: python\n\n portkey_credentials = PortKeyCredentials(api_key=api_key,\n url=portkey_url,\n provider_api_key=provider_api_key,\n provider=provider_name)\n\n 2. Create PortKeyCredentials by reading from environment variables.\n .. code-block:: python\n\n os.environ[\"PORTKEY_API_KEY\"] = \"...\"\n os.environ[\"PORTKEY_URL\"] = \"...\"\n os.environ[\"PORTKEY_PROVIDER_API_KEY\"] = \"...\"\n os.environ[\"PORTKEY_PROVIDER_NAME\"] = \"...\"\n portkey_credentials = PortKeyCredentials.create_from_env()", "properties": { "url": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "PortKey url. This attribute can be read from `PORTKEY_URL` environment variable.", "title": "Url" }, "api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "API key for PortKey. This attribute can be read from `PORTKEY_API_KEY` environment variable.", "title": "Api Key" }, "provider_api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "API key for the provider. This attribute can be read from `PORTKEY_PROVIDER_API_KEY` environment variable.", "title": "Provider Api Key" }, "provider": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "The provider name. This attribute can be read from `PORTKEY_PROVIDER_NAME` environment variable.", "title": "Provider" } }, "required": [ "url", "api_key", "provider_api_key", "provider" ], "title": "PortKeyCredentials", "type": "object" } } }
- Fields:
type (Annotated[ibm_watsonx_gov.entities.enums.ModelProviderType, FieldInfo(annotation=NoneType, required=False, default=
- Validators:
create_credentials_from_env
»all fields
- field credentials: Annotated[PortKeyCredentials | None, FieldInfo(annotation=NoneType, required=False, default=None, description='PortKey credentials.')] = None¶
PortKey credentials.
- Validated by:
- field type: ', frozen=True)] = ModelProviderType.PORTKEY¶
The type of model provider.
- Validated by:
- validator create_credentials_from_env » all fields¶
- pydantic model ibm_watsonx_gov.entities.model_provider.RITSModelProvider¶
Bases:
ModelProvider
Show JSON schema
{ "title": "RITSModelProvider", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "default": "rits", "description": "The type of model provider." }, "credentials": { "anyOf": [ { "$ref": "#/$defs/RITSCredentials" }, { "type": "null" } ], "default": null, "description": "RITS credentials." } }, "$defs": { "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" }, "RITSCredentials": { "properties": { "hostname": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": "https://inference-3scale-apicast-production.apps.rits.fmaas.res.ibm.com", "description": "The rits hostname", "title": "Hostname" }, "api_key": { "title": "Api Key", "type": "string" } }, "required": [ "api_key" ], "title": "RITSCredentials", "type": "object" } } }
- Fields:
type (Annotated[ibm_watsonx_gov.entities.enums.ModelProviderType, FieldInfo(annotation=NoneType, required=False, default=
- Validators:
create_credentials_from_env
»all fields
- field credentials: Annotated[RITSCredentials | None, FieldInfo(annotation=NoneType, required=False, default=None, description='RITS credentials.')] = None¶
RITS credentials.
- Validated by:
- field type: ', frozen=True)] = ModelProviderType.RITS¶
The type of model provider.
- Validated by:
- validator create_credentials_from_env » all fields¶
- pydantic model ibm_watsonx_gov.entities.model_provider.VertexAIModelProvider¶
Bases:
ModelProvider
Represents a model provider using Vertex AI.
Examples
- Create provider using credentials object:
provider = VertexAIModelProvider( credentials=VertexAICredentials( credentials_path="path/to/key.json", project_id="your-project", location="us-central1" ) )
- Create provider using environment variables:
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "/path/to/service_account.json" os.environ['GOOGLE_CLOUD_PROJECT'] = "your-project" os.environ['GOOGLE_CLOUD_LOCATION'] = "us-central1" # This is optional field, by default us-central1 location is selected provider = VertexAIModelProvider()
Show JSON schema
{ "title": "VertexAIModelProvider", "description": "Represents a model provider using Vertex AI.\n\nExamples:\n 1. Create provider using credentials object:\n .. code-block:: python\n\n provider = VertexAIModelProvider(\n credentials=VertexAICredentials(\n credentials_path=\"path/to/key.json\",\n project_id=\"your-project\",\n location=\"us-central1\" \n )\n )\n\n 2. Create provider using environment variables:\n .. code-block:: python\n\n os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = \"/path/to/service_account.json\"\n os.environ['GOOGLE_CLOUD_PROJECT'] = \"your-project\"\n os.environ['GOOGLE_CLOUD_LOCATION'] = \"us-central1\" # This is optional field, by default us-central1 location is selected\n\n provider = VertexAIModelProvider()", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "default": "vertex_ai", "description": "The type of model provider." }, "credentials": { "anyOf": [ { "$ref": "#/$defs/VertexAICredentials" }, { "type": "null" } ], "default": null, "description": "Vertex AI credentials." } }, "$defs": { "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" }, "VertexAICredentials": { "description": "Defines the VertexAICredentials class for accessing Vertex AI using service account credentials.\n\nExamples:\n 1. Create credentials manually:\n .. code-block:: python\n\n vertex_credentials = VertexAICredentials(\n credentials_path=\"path/to/service_account.json\",\n project_id=\"my-gcp-project\",\n location=\"us-central1\"\n )\n\n 2. Create credentials from environment:\n .. code-block:: python\n\n os.environ[\"GOOGLE_APPLICATION_CREDENTIALS\"] = \"path/to/service_account.json\"\n os.environ[\"GOOGLE_CLOUD_PROJECT\"] = \"my-gcp-project\"\n os.environ[\"GOOGLE_CLOUD_LOCATION\"] = \"us-central1\"\n\n vertex_ai_credentials = VertexAICredentials.create_from_env()", "properties": { "credentials_path": { "description": "Path to service-account JSON. This attribute can be read from GOOGLE_APPLICATION_CREDENTIALS environment variable when creating VertexAICredentials from environment.", "title": "Credentials Path", "type": "string" }, "project_id": { "description": "The Google Cloud project id. This attribute can be read from GOOGLE_CLOUD_PROJECT or GCLOUD_PROJECT environment variable when creating VertexAICredentials from environment.", "title": "Project ID", "type": "string" }, "location": { "default": "us-central1", "description": "Vertex AI region. This attribute can be read from GOOGLE_CLOUD_LOCATION environment variable when creating VertexAICredentials from environment. By default us-central1 location is used.", "examples": [ "us-central1", "europe-west4" ], "title": "Location", "type": "string" } }, "required": [ "credentials_path", "project_id" ], "title": "VertexAICredentials", "type": "object" } } }
- Fields:
type (Annotated[ibm_watsonx_gov.entities.enums.ModelProviderType, FieldInfo(annotation=NoneType, required=False, default=
- Validators:
create_credentials_from_env
»all fields
- field credentials: Annotated[VertexAICredentials | None, FieldInfo(annotation=NoneType, required=False, default=None, description='Vertex AI credentials.')] = None¶
Vertex AI credentials.
- Validated by:
- field type: ', frozen=True)] = ModelProviderType.VERTEX_AI¶
The type of model provider.
- Validated by:
- validator create_credentials_from_env » all fields¶
- pydantic model ibm_watsonx_gov.entities.model_provider.WxAIModelProvider¶
Bases:
ModelProvider
This class represents a model provider configuration for IBM watsonx.ai. It includes the provider type and credentials required to authenticate and interact with the watsonx.ai platform. If credentials are not explicitly provided, it attempts to load them from environment variables.
Examples
- Create provider using credentials object:
credentials = WxAICredentials( url="https://us-south.ml.cloud.ibm.com", api_key="your-api-key" ) provider = WxAIModelProvider(credentials=credentials)
- Create provider using environment variables:
import os os.environ['WATSONX_URL'] = "https://us-south.ml.cloud.ibm.com" os.environ['WATSONX_APIKEY'] = "your_api_key" provider = WxAIModelProvider()
Show JSON schema
{ "title": "WxAIModelProvider", "description": "This class represents a model provider configuration for IBM watsonx.ai. It includes the provider type and\ncredentials required to authenticate and interact with the watsonx.ai platform. If credentials are not explicitly\nprovided, it attempts to load them from environment variables.\n\nExamples:\n 1. Create provider using credentials object:\n .. code-block:: python\n\n credentials = WxAICredentials(\n url=\"https://us-south.ml.cloud.ibm.com\",\n api_key=\"your-api-key\"\n )\n provider = WxAIModelProvider(credentials=credentials)\n\n 2. Create provider using environment variables:\n .. code-block:: python\n\n import os\n\n os.environ['WATSONX_URL'] = \"https://us-south.ml.cloud.ibm.com\"\n os.environ['WATSONX_APIKEY'] = \"your_api_key\"\n\n provider = WxAIModelProvider()", "type": "object", "properties": { "type": { "$ref": "#/$defs/ModelProviderType", "default": "ibm_watsonx.ai", "description": "The type of model provider." }, "credentials": { "anyOf": [ { "$ref": "#/$defs/WxAICredentials" }, { "type": "null" } ], "default": null, "description": "The credentials used to authenticate with watsonx.ai. If not provided, they will be loaded from environment variables." } }, "$defs": { "ModelProviderType": { "description": "Supported model provider types for Generative AI", "enum": [ "ibm_watsonx.ai", "azure_openai", "rits", "openai", "vertex_ai", "google_ai_studio", "aws_bedrock", "custom", "portkey" ], "title": "ModelProviderType", "type": "string" }, "WxAICredentials": { "description": "Defines the WxAICredentials class to specify the watsonx.ai server details.\n\nExamples:\n 1. Create WxAICredentials with default parameters. By default Dallas region is used.\n .. code-block:: python\n\n wxai_credentials = WxAICredentials(api_key=\"...\")\n\n 2. Create WxAICredentials by specifying region url.\n .. code-block:: python\n\n wxai_credentials = WxAICredentials(api_key=\"...\",\n url=\"https://au-syd.ml.cloud.ibm.com\")\n\n 3. Create WxAICredentials by reading from environment variables.\n .. code-block:: python\n\n os.environ[\"WATSONX_APIKEY\"] = \"...\"\n # [Optional] Specify watsonx region specific url. Default is https://us-south.ml.cloud.ibm.com .\n os.environ[\"WATSONX_URL\"] = \"https://eu-gb.ml.cloud.ibm.com\"\n wxai_credentials = WxAICredentials.create_from_env()\n\n 4. Create WxAICredentials for on-prem.\n .. code-block:: python\n\n wxai_credentials = WxAICredentials(url=\"https://<hostname>\",\n username=\"...\"\n api_key=\"...\",\n version=\"5.2\")\n\n 5. Create WxAICredentials by reading from environment variables for on-prem.\n .. code-block:: python\n\n os.environ[\"WATSONX_URL\"] = \"https://<hostname>\"\n os.environ[\"WATSONX_VERSION\"] = \"5.2\"\n os.environ[\"WATSONX_USERNAME\"] = \"...\"\n os.environ[\"WATSONX_APIKEY\"] = \"...\"\n # Only one of api_key or password is needed\n #os.environ[\"WATSONX_PASSWORD\"] = \"...\"\n wxai_credentials = WxAICredentials.create_from_env()", "properties": { "url": { "default": "https://us-south.ml.cloud.ibm.com", "description": "The url for watsonx ai service", "examples": [ "https://us-south.ml.cloud.ibm.com", "https://eu-de.ml.cloud.ibm.com", "https://eu-gb.ml.cloud.ibm.com", "https://jp-tok.ml.cloud.ibm.com", "https://au-syd.ml.cloud.ibm.com" ], "title": "watsonx.ai url", "type": "string" }, "api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "The user api key. Required for using watsonx as a service and one of api_key or password is required for using watsonx on-prem software.", "strip_whitespace": true, "title": "Api Key" }, "version": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "The watsonx on-prem software version. Required for using watsonx on-prem software.", "title": "Version" }, "username": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "The user name. Required for using watsonx on-prem software.", "title": "User name" }, "password": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "The user password. One of api_key or password is required for using watsonx on-prem software.", "title": "Password" }, "instance_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": "openshift", "description": "The watsonx.ai instance id. Default value is openshift.", "title": "Instance id" } }, "title": "WxAICredentials", "type": "object" } } }
- Fields:
type (Annotated[ibm_watsonx_gov.entities.enums.ModelProviderType, FieldInfo(annotation=NoneType, required=False, default=
- Validators:
create_credentials_from_env
»all fields
- field credentials: Annotated[WxAICredentials | None, FieldInfo(annotation=NoneType, required=False, default=None, description='The credentials used to authenticate with watsonx.ai. If not provided, they will be loaded from environment variables.')] = None¶
The credentials used to authenticate with watsonx.ai. If not provided, they will be loaded from environment variables.
- Validated by:
- field type: ', frozen=True)] = ModelProviderType.IBM_WATSONX_AI¶
The type of model provider.
- Validated by:
- validator create_credentials_from_env » all fields¶