Share via


AIProjectClient Class

AIProjectClient.

Constructor

AIProjectClient(endpoint: str, credential: TokenCredential, *, allow_preview: bool = False, **kwargs: Any)

Parameters

Name Description
endpoint
Required
str

Foundry Project endpoint in the form "https://{ai-services-account-name}.services.ai.azure.com/api/projects/{project-name}". If you only have one Project in your Foundry Hub, or to target the default Project in your Hub, use the form "https://{ai-services-account-name}.services.ai.azure.com/api/projects/_project". Required.

credential
Required

Credential used to authenticate requests to the service. Required.

allow_preview
Required

Whether to enable preview features. Optional, default is False. Set this to True to create a Hosted Agent (using HostedAgentDefinition) or a Workflow Agent (using WorkflowAgentDefinition). Set this to True to use human evaluation rule action (class HumanEvaluationPreviewRuleAction). Methods on the .beta sub-client (class BetaOperations) are all in preview, but do not require setting allow_preview=True since it's implied by the sub-client name. When preview features are enabled, the client libraries sends the HTTP request header Foundry-Features with the appropriate value in all relevant calls to the service.

Keyword-Only Parameters

Name Description
api_version
str

The API version to use for this operation. Known values are "v1". Default value is "v1". Note that overriding this default value may result in unsupported behavior.

allow_preview
Default value: False

Variables

Name Description
beta

BetaOperations operations

agents

AgentsOperations operations

evaluation_rules

EvaluationRulesOperations operations

connections

ConnectionsOperations operations

datasets

DatasetsOperations operations

deployments

DeploymentsOperations operations

indexes

IndexesOperations operations

Methods

close
get_openai_client

Get an authenticated OpenAI client from the openai package.

Keyword arguments are passed to the OpenAI client constructor.

The OpenAI client constructor is called with:

  • base_url set to the endpoint provided to the AIProjectClient constructor, with "/openai/v1" appended. If agent_name is provided (and allow_preview=True was set on the AIProjectClient), base_url is instead set to the Agent's endpoint {endpoint}/agents/{agent_name}/endpoint/protocols/openai. Can be overridden by passing base_url as a keyword argument.

  • api_key set to a get_bearer_token_provider() callable that uses the TokenCredential provided to the AIProjectClient constructor, with scope "https://ai.azure.com/.default". Can be overridden by passing api_key as a keyword argument.

send_request

Runs the network request through the client's chained policies.


>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

close

close() -> None

get_openai_client

Get an authenticated OpenAI client from the openai package.

Keyword arguments are passed to the OpenAI client constructor.

The OpenAI client constructor is called with:

  • base_url set to the endpoint provided to the AIProjectClient constructor, with "/openai/v1" appended. If agent_name is provided (and allow_preview=True was set on the AIProjectClient), base_url is instead set to the Agent's endpoint {endpoint}/agents/{agent_name}/endpoint/protocols/openai. Can be overridden by passing base_url as a keyword argument.

  • api_key set to a get_bearer_token_provider() callable that uses the TokenCredential provided to the AIProjectClient constructor, with scope "https://ai.azure.com/.default". Can be overridden by passing api_key as a keyword argument.

get_openai_client(*, agent_name: str | None = None, **kwargs: Any) -> OpenAI

Keyword-Only Parameters

Name Description
agent_name
str or None

Optional name of an Agent. When provided, the OpenAI client's base_url is pointed at the Agent's endpoint. Requires allow_preview=True to have been set on the AIProjectClient constructor; otherwise a ValueError is raised.

Default value: None

Returns

Type Description
<xref:openai.OpenAI>

An authenticated OpenAI client

Exceptions

Type Description

If agent_name is provided but allow_preview=True was not set on the client.

send_request

Runs the network request through the client's chained policies.


>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

send_request(request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse

Parameters

Name Description
request
Required

The network request you want to make. Required.

Keyword-Only Parameters

Name Description
stream

Whether the response payload will be streamed. Defaults to False.

Default value: False

Returns

Type Description

The response of your network call. Does not do error handling on your response.