Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,11 @@ def get_chat_completions_client(self, **kwargs: Any) -> "ChatCompletionsClient":
) from e

endpoint = self._get_inference_url(self._outer_instance._config.endpoint) # pylint: disable=protected-access
# Older Inference SDK versions use ml.azure.com as the scope. Make sure to set the correct value here. This
# is only relevant of course if EntraID auth is used.
credential_scopes = ["https://ai.azure.com/.default"]

client = ChatCompletionsClient(
endpoint=endpoint,
credential=self._outer_instance._config.credential, # pylint: disable=protected-access
credential_scopes=credential_scopes,
credential_scopes=self._outer_instance._config.credential_scopes, # pylint: disable=protected-access,
user_agent=kwargs.pop(
"user_agent", self._outer_instance._patched_user_agent # pylint: disable=protected-access
),
Expand Down Expand Up @@ -131,14 +128,11 @@ def get_embeddings_client(self, **kwargs: Any) -> "EmbeddingsClient": # type: i
) from e

endpoint = self._get_inference_url(self._outer_instance._config.endpoint) # pylint: disable=protected-access
# Older Inference SDK versions use ml.azure.com as the scope. Make sure to set the correct value here. This
# is only relevant of course if EntraID auth is used.
credential_scopes = ["https://ai.azure.com/.default"]

client = EmbeddingsClient(
endpoint=endpoint,
credential=self._outer_instance._config.credential, # pylint: disable=protected-access
credential_scopes=credential_scopes,
credential_scopes=self._outer_instance._config.credential_scopes, # pylint: disable=protected-access,
user_agent=kwargs.pop(
"user_agent", self._outer_instance._patched_user_agent # pylint: disable=protected-access
),
Expand Down Expand Up @@ -173,14 +167,11 @@ def get_image_embeddings_client(self, **kwargs: Any) -> "ImageEmbeddingsClient":
) from e

endpoint = self._get_inference_url(self._outer_instance._config.endpoint) # pylint: disable=protected-access
# Older Inference SDK versions use ml.azure.com as the scope. Make sure to set the correct value here. This
# is only relevant of course if EntraID auth is used.
credential_scopes = ["https://ai.azure.com/.default"]

client = ImageEmbeddingsClient(
endpoint=endpoint,
credential=self._outer_instance._config.credential, # pylint: disable=protected-access
credential_scopes=credential_scopes,
credential_scopes=self._outer_instance._config.credential_scopes, # pylint: disable=protected-access,
user_agent=kwargs.pop(
"user_agent", self._outer_instance._patched_user_agent # pylint: disable=protected-access
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,11 @@ def get_chat_completions_client(self, **kwargs: Any) -> "ChatCompletionsClient":
) from e

endpoint = self._get_inference_url(self._outer_instance._config.endpoint) # pylint: disable=protected-access
# TODO: Remove this before //build?
# Older Inference SDK versions use ml.azure.com as the scope. Make sure to set the correct value here. This
# is only relevant of course if EntraID auth is used.
credential_scopes = ["https://ai.azure.com/.default"]

client = ChatCompletionsClient(
endpoint=endpoint,
credential=self._outer_instance._config.credential, # pylint: disable=protected-access
credential_scopes=credential_scopes,
credential_scopes=self._outer_instance._config.credential_scopes, # pylint: disable=protected-access
user_agent=kwargs.pop(
"user_agent", self._outer_instance._patched_user_agent # pylint: disable=protected-access
),
Expand Down Expand Up @@ -125,14 +121,11 @@ def get_embeddings_client(self, **kwargs: Any) -> "EmbeddingsClient": # type: i
) from e

endpoint = self._get_inference_url(self._outer_instance._config.endpoint) # pylint: disable=protected-access
# Older Inference SDK versions use ml.azure.com as the scope. Make sure to set the correct value here. This
# is only relevant of course if EntraID auth is used.
credential_scopes = ["https://ai.azure.com/.default"]

client = EmbeddingsClient(
endpoint=endpoint,
credential=self._outer_instance._config.credential, # pylint: disable=protected-access
credential_scopes=credential_scopes,
credential_scopes=self._outer_instance._config.credential_scopes, # pylint: disable=protected-access,
user_agent=kwargs.pop(
"user_agent", self._outer_instance._patched_user_agent # pylint: disable=protected-access
),
Expand Down Expand Up @@ -167,14 +160,11 @@ def get_image_embeddings_client(self, **kwargs: Any) -> "ImageEmbeddingsClient":
) from e

endpoint = self._get_inference_url(self._outer_instance._config.endpoint) # pylint: disable=protected-access
# Older Inference SDK versions use ml.azure.com as the scope. Make sure to set the correct value here. This
# is only relevant of course if EntraID auth is used.
credential_scopes = ["https://ai.azure.com/.default"]

client = ImageEmbeddingsClient(
endpoint=endpoint,
credential=self._outer_instance._config.credential, # pylint: disable=protected-access
credential_scopes=credential_scopes,
credential_scopes=self._outer_instance._config.credential_scopes, # pylint: disable=protected-access,
user_agent=kwargs.pop(
"user_agent", self._outer_instance._patched_user_agent # pylint: disable=protected-access
),
Expand Down
2 changes: 0 additions & 2 deletions sdk/ai/azure-ai-projects/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
../../core/azure-core
../../identity/azure-identity
aiohttp
azure.storage.blob
azure.ai.inference
azure.ai.agents
openai
prompty
3 changes: 3 additions & 0 deletions sdk/ai/azure-ai-projects/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ warn_unused_configs = true
ignore_missing_imports = true
follow_imports_for_stubs = false

[tool.azure-sdk-build]
verifytypes = false

[tool.isort]
profile = "black"
line_length = 120
Expand Down
2 changes: 0 additions & 2 deletions sdk/ai/azure-ai-projects/pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"reportMissingImports": false,
"pythonVersion": "3.11",
"exclude": [
"**/_client.py",
"**/_operations.py"
],
"extraPaths": [
"./../../core/azure-core",
Expand Down
21 changes: 13 additions & 8 deletions sdk/ai/azure-ai-projects/samples/evaluation/sample_evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
# DatasetVersion,
)

endpoint = os.environ["PROJECT_ENDPOINT"] # Sample : https://<account_name>.services.ai.azure.com/api/projects/<project_name>
model_endpoint = os.environ["MODEL_ENDPOINT"] # Sample : https://<account_name>.services.ai.azure.com
model_api_key= os.environ["MODEL_API_KEY"]
model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"] # Sample : gpt-4o-mini
endpoint = os.environ[
"PROJECT_ENDPOINT"
] # Sample : https://<account_name>.services.ai.azure.com/api/projects/<project_name>
model_endpoint = os.environ["MODEL_ENDPOINT"] # Sample : https://<account_name>.services.ai.azure.com
model_api_key = os.environ["MODEL_API_KEY"]
model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"] # Sample : gpt-4o-mini

with DefaultAzureCredential(exclude_interactive_browser_credential=False) as credential:

Expand Down Expand Up @@ -85,10 +87,13 @@
},
)

evaluation_response: Evaluation = project_client.evaluations.create(evaluation, headers={
"model-endpoint": model_endpoint,
"api-key": model_api_key,
})
evaluation_response: Evaluation = project_client.evaluations.create(
evaluation,
headers={
"model-endpoint": model_endpoint,
"api-key": model_api_key,
},
)
print(evaluation_response)

print("Get evaluation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@

load_dotenv()

endpoint = os.environ["PROJECT_ENDPOINT"] # Sample : https://<account_name>.services.ai.azure.com/api/projects/<project_name>
model_endpoint = os.environ["MODEL_ENDPOINT"] # Sample : https://<account_name>.services.ai.azure.com
model_api_key= os.environ["MODEL_API_KEY"]
model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"] # Sample : gpt-4o-mini
endpoint = os.environ[
"PROJECT_ENDPOINT"
] # Sample : https://<account_name>.services.ai.azure.com/api/projects/<project_name>
model_endpoint = os.environ["MODEL_ENDPOINT"] # Sample : https://<account_name>.services.ai.azure.com
model_api_key = os.environ["MODEL_API_KEY"]
model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"] # Sample : gpt-4o-mini

with DefaultAzureCredential(exclude_interactive_browser_credential=False) as credential:

Expand Down Expand Up @@ -89,8 +91,8 @@
"string_check": EvaluatorConfiguration(
id=EvaluatorIds.STRING_CHECK_GRADER.value,
init_params={
"input" :"{{item.query}}",
"name":"starts with what is",
"input": "{{item.query}}",
"name": "starts with what is",
"operation": "like",
"reference": "What is",
"deployment_name": model_deployment_name,
Expand All @@ -113,8 +115,8 @@
"evaluation_metric": "fuzzy_match",
"input": "{{item.query}}",
"name": "similarity",
"pass_threshold" :1,
"reference":"{{item.query}}",
"pass_threshold": 1,
"reference": "{{item.query}}",
"deployment_name": model_deployment_name,
},
),
Expand All @@ -134,10 +136,13 @@
},
)

evaluation_response: Evaluation = project_client.evaluations.create(evaluation, headers={
"model-endpoint": model_endpoint,
"api-key": model_api_key,
})
evaluation_response: Evaluation = project_client.evaluations.create(
evaluation,
headers={
"model-endpoint": model_endpoint,
"api-key": model_api_key,
},
)
print(evaluation_response)

print("Get evaluation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
# DatasetVersion,
)


async def main() -> None:
endpoint = os.environ["PROJECT_ENDPOINT"] # Sample : https://<account_name>.services.ai.azure.com/api/projects/<project_name>
endpoint = os.environ[
"PROJECT_ENDPOINT"
] # Sample : https://<account_name>.services.ai.azure.com/api/projects/<project_name>
model_endpoint = os.environ["MODEL_ENDPOINT"] # Sample : https://<account_name>.services.ai.azure.com
model_api_key = os.environ["MODEL_API_KEY"]
model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"] # Sample : gpt-4o-mini
Expand Down Expand Up @@ -85,10 +88,13 @@ async def main() -> None:
},
)

evaluation_response: Evaluation = await project_client.evaluations.create(evaluation, headers={
"model-endpoint": model_endpoint,
"api-key": model_api_key,
})
evaluation_response: Evaluation = await project_client.evaluations.create(
evaluation,
headers={
"model-endpoint": model_endpoint,
"api-key": model_api_key,
},
)
print(evaluation_response)

print("Get evaluation")
Expand Down
7 changes: 4 additions & 3 deletions sdk/ai/azure-ai-projects/tests/samples/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class TestSamples:
* 'cd' to the folder '/sdk/ai/azure-ai-projects' in your azure-sdk-for-python repo.
* set PROJECT_ENDPOINT=<your-project-endpoint> - Define your Azure AI Foundry project endpoint used by the test.
* set ENABLE_AZURE_AI_PROJECTS_CONSOLE_LOGGING=false - to make sure logging is not enabled in the test, to reduce console spew.
* Uncomment the two lines that start with "@pytest.mark.skip" below.
* Run: pytest tests/samples/test_samples.py::TestSamples
* Load the resulting report in Excel: tests\samples\samples_report.csv
* Load the resulting report in Excel: tests/samples/samples_report.csv
"""

@classmethod
Expand Down Expand Up @@ -190,7 +191,7 @@ async def _run_sample_async(cls, sample_name: str) -> None:
),
(
"samples\\inference\\sample_image_embeddings_with_azure_ai_inference_client.py",
"to-do-add-model",
"Cohere-embed-v3-english",
"",
"samples\\inference",
),
Expand Down Expand Up @@ -249,7 +250,7 @@ def test_samples(
),
(
"samples\\inference\\async_samples\\sample_image_embeddings_with_azure_ai_inference_client_async.py",
"to-do-add-model",
"Cohere-embed-v3-english",
"",
"samples\\inference\\async_samples",
),
Expand Down
1 change: 1 addition & 0 deletions shared_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
msrest
anyio
azure-ai-agents
azure-ai-ml
azure-ai-resources
azure-common
Expand Down