gen_ai_hub.proxy package¶
- class gen_ai_hub.proxy.GenAIHubProxyClient(*, base_url: str | None = None, auth_url: str | None = None, client_id: str | None = None, client_secret: str | None = None, resource_group: str | None = None, ai_core_client: AICoreV2Client | None = None, **extra_data: Any)¶
Bases:
BaseProxyClientGenAIHubProxyClient is a proxy client for interacting with the GenAI Hub.
- AI_CLIENT_TYPE_VAL: ClassVar[str] = 'GenAI Hub SDK (Python)'¶
- classmethod add_foundation_model_scenario(scenario_id, config_names: List[str] | None = None, prediction_url_suffix: str | None = None, model_name_parameter: str = 'model_name')¶
Add a foundational model scenario to the client.
- Parameters:
scenario_id (str) – the scenario ID.
config_names (Optional[List[str]], optional) – list of configuration names, defaults to None
prediction_url_suffix (Optional[str], optional) – prediction URL suffix, defaults to None
model_name_parameter (str, optional) – model name parameter, defaults to ‘model_name’
- default_values: ClassVar[Dict[str, Any]] = {}¶
- property deployment_class: Type[Deployment]¶
- property deployments: List[Deployment]¶
- classmethod for_profile(profile: str = None)¶
Create a GenAIHubProxyClient instance for the given profile.
- Parameters:
profile (str, optional) – Profile name, defaults to None
- Returns:
GenAIHubProxyClient instance.
- Return type:
- foundational_model_scenarios: ClassVar[List[FoundationalModelScenario]] = [FoundationalModelScenario(scenario_id='foundation-models', config_names=['*'], model_name_parameter='model_name', prediction_url_suffix=None)]¶
- get_additional_headers() Dict[str, str]¶
Get only the additional headers (instance-level and request-level).
- Returns:
Additional headers.
- Return type:
Dict[str, str]
- get_ai_core_token()¶
Get the AI core token for authentication.
- Returns:
AI core token.
- Return type:
str
- get_deployments()¶
Get the list of deployments.
- Returns:
List of deployments.
- Return type:
List[Deployment]
- get_request_header()¶
Get the request headers for requests made by the client.
- Returns:
Request headers.
- Return type:
Dict[str, str]
- classmethod init_client(data: Any) Any¶
Initialize the client with the provided data.
- Parameters:
data (Any) – Input data for client initialization.
- Returns:
Initialized data.
- Return type:
Any
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'allow', 'protected_namespaces': ()}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context: Any, /) None¶
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
- on_invalid_deployments: ClassVar[InvalidDeploymentBehavior] = 'warn'¶
- property request_header: Dict[str, Any]¶
- select_deployment(raise_on_multiple: bool = False, **search_key_value)¶
- classmethod set_default_values(**kwargs)¶
Set default values for the client.
- set_headers_addition(headers: Dict[str, str])¶
Set additional headers for requests made by the client.
- Parameters:
headers (Dict[str, str]) – Headers to add.
- update_deployments()¶
Update the list of deployments from the GenAI Hub.
- Returns:
List of updated deployments.
- Return type:
List[Deployment]
- base_url: str | None¶
- auth_url: str | None¶
- client_id: str | None¶
- client_secret: str | None¶
- resource_group: str | None¶
- ai_core_client: AICoreV2Client | None¶
- gen_ai_hub.proxy.set_proxy_version(proxy_version: str, catalog: ProxyClients | None = None) None¶
Set the global proxy version.
- Parameters:
proxy_version (str) – The proxy version to set.
catalog (Optional[ProxyClients], optional) – The catalog for which the proxy version is to be set. If none is provided, the proxy version is set for the default proxy_clients catalog.
- Raises:
ValueError – If proxy_version is not a string.
- gen_ai_hub.proxy.get_proxy_version(catalog: ProxyClients | None = None) str¶
Get the current proxy version. The version is selected in the following order:
thread-local overwrite (set with proxy_version_context)
global overwrite (set with set_proxy_version)
environment variable (LLM_PROXY_VERSION)
first registered proxy version
- Parameters:
catalog (Optional[ProxyClients], optional) – The catalog from which to get the proxy version. If none is provided,
- Raises:
ValueError – If no proxy version is set.
- Returns:
The current proxy version.
- Return type:
str
- gen_ai_hub.proxy.get_proxy_client(proxy_version: str | None = None, catalog: ProxyClients | None = None, **kwargs) BaseProxyClient¶
Get a proxy client for the given proxy version.
- Parameters:
proxy_version (str | None, optional) – The version of the proxy client to retrieve. If not provided, the function will attempt to retrieve the version using the get_proxy_version function.
catalog (Optional[ProxyClients], optional) – The catalog from which to retrieve the proxy client. If not provided, the function will default to the proxy_clients catalog
kwargs (dict) – Arbitrary keyword arguments that will be passed to the constructor of the proxy client class.
- Returns:
An instance of the proxy client.
- Return type:
Subpackages¶
- gen_ai_hub.proxy.core package
- gen_ai_hub.proxy.gen_ai_hub_proxy package
GenAIHubProxyClientGenAIHubProxyClient.AI_CLIENT_TYPE_VALGenAIHubProxyClient.add_foundation_model_scenario()GenAIHubProxyClient.default_valuesGenAIHubProxyClient.deployment_classGenAIHubProxyClient.deploymentsGenAIHubProxyClient.for_profile()GenAIHubProxyClient.foundational_model_scenariosGenAIHubProxyClient.get_additional_headers()GenAIHubProxyClient.get_ai_core_token()GenAIHubProxyClient.get_deployments()GenAIHubProxyClient.get_request_header()GenAIHubProxyClient.init_client()GenAIHubProxyClient.model_configGenAIHubProxyClient.model_post_init()GenAIHubProxyClient.on_invalid_deploymentsGenAIHubProxyClient.request_headerGenAIHubProxyClient.select_deployment()GenAIHubProxyClient.set_default_values()GenAIHubProxyClient.set_headers_addition()GenAIHubProxyClient.update_deployments()GenAIHubProxyClient.base_urlGenAIHubProxyClient.auth_urlGenAIHubProxyClient.client_idGenAIHubProxyClient.client_secretGenAIHubProxyClient.resource_groupGenAIHubProxyClient.ai_core_client
temporary_headers_addition()- Submodules
- gen_ai_hub.proxy.langchain package
init_llm()init_embedding_model()OpenAIClientOpenAIEmbeddingsAsyncOpenAIClientChatOpenAIBedrockEmbeddingsAICoreBedrockBaseModelChatBedrockChatBedrockConverseChatGoogleGenerativeAIChatGoogleGenerativeAI.model_configChatGoogleGenerativeAI.clientChatGoogleGenerativeAI.default_metadataChatGoogleGenerativeAI.model_kwargsChatGoogleGenerativeAI.streamingChatGoogleGenerativeAI.convert_system_message_to_humanChatGoogleGenerativeAI.stopChatGoogleGenerativeAI.response_mime_typeChatGoogleGenerativeAI.response_schemaChatGoogleGenerativeAI.reasoning_effortChatGoogleGenerativeAI.thinking_configChatGoogleGenerativeAI.cached_content
GoogleGenerativeAIEmbeddingsOpenAI- Submodules
- gen_ai_hub.proxy.native package