Model Provider

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",
            "custom"
         ],
         "title": "ModelProviderType",
         "type": "string"
      }
   }
}

Fields:
Validators:
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

  1. Create a custom model provider:
    provider = CustomModelProvider()
    
  2. 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:

ModelProviderType

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",
            "custom"
         ],
         "title": "ModelProviderType",
         "type": "string"
      }
   }
}

Fields:
field type: ')] = ModelProviderType.CUSTOM

The type of model provider.

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",
            "custom"
         ],
         "title": "ModelProviderType",
         "type": "string"
      }
   },
   "required": [
      "type"
   ]
}

Fields:
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",
            "custom"
         ],
         "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:
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.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",
            "custom"
         ],
         "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:
Validators:
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.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

  1. Create provider using credentials object:
    credentials = WxAICredentials(
        url="https://us-south.ml.cloud.ibm.com",
        api_key="your-api-key"
    )
    provider = WxAIModelProvider(credentials=credentials)
    
  2. 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",
            "custom"
         ],
         "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:
Validators:
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