Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
d82870e
Add 'change_feed_mode' to 'query_items_change_feed' API
allenkim0129 Oct 25, 2024
ced92d3
remove unnecessary import
allenkim0129 Oct 25, 2024
06a8e2f
Fix lint
allenkim0129 Oct 28, 2024
c1bd9bb
Updated CHANGELOG.md
allenkim0129 Oct 28, 2024
b663998
Merge branch 'main' into users/allekim/feature/feedRangeAllVersionsAn…
allenkim0129 Oct 28, 2024
cf9e4b0
Removed _feed_range.py
allenkim0129 Oct 28, 2024
e0a1b18
Addressed comments
allenkim0129 Oct 29, 2024
357b4f8
Fixed lint
allenkim0129 Oct 29, 2024
3592bac
Add kwargs back to 'call'QueryItemsChangeFeed'
allenkim0129 Oct 29, 2024
e36392c
Fixed syntax error with f-string
allenkim0129 Oct 29, 2024
e57aef3
Removed StrEnum to support earlier Python versions
allenkim0129 Oct 29, 2024
0071042
Fixed f-string error
allenkim0129 Oct 31, 2024
6d65a5d
addressed comments
allenkim0129 Nov 1, 2024
c7d51af
Addressed comments
allenkim0129 Nov 5, 2024
c87ec71
Removed unnecessary tests
allenkim0129 Nov 5, 2024
cf6f518
Fix tests for emulator
allenkim0129 Nov 5, 2024
8f462ce
Generating SDK with model renames (#38108)
hamshavathimunibyraiah Oct 28, 2024
92d01cb
[Identity][Monitor] Update live test setup (#37943)
pvaneck Oct 28, 2024
c4bc225
Clean-up cosmos test pipeline (#38126)
weshaggard Oct 28, 2024
2e57e49
Multi modal eval fix (#38134)
w-javed Oct 28, 2024
e6f9bc1
azure-ai-evaluation release 1.0.0b5 2024-10-28 (#38138)
nagkumar91 Oct 29, 2024
c328607
open apiview for mgmt sdk (#38143)
msyyc Oct 29, 2024
bf4db51
[AutoRelease] t2-appplatform-2024-10-25-72111(can only be merged by S…
azure-sdk Oct 29, 2024
1e5f7e9
AzurePipelinesCredential | adding mlflow uri func (#36580)
kshitij-microsoft Oct 29, 2024
71aa1a3
Update changelog (#38133)
sanchez-alex Oct 29, 2024
faf53ba
Increment package version after release of azure-ai-evaluation (#38142)
azure-sdk Oct 29, 2024
984f89d
Remove psycopg2-binary from dev_requirements.txt (#38103)
lzchen Oct 29, 2024
80eb904
[Evaluation] Error improve for service-based evaluator/simulator (#38…
ninghu Oct 29, 2024
5741d7b
AzMon exporter: Serialize complex log bodies to json and set dependen…
Oct 29, 2024
cd55049
Experimental tags on ADV scenarios (#38166)
nagkumar91 Oct 29, 2024
1381ce3
Sync eng/common directory with azure-sdk-tools for PR 9259 (#38160)
azure-sdk Oct 29, 2024
bb075f5
Re-generated REST client after re-copying Swagger folder for `2024-10…
u9009 Oct 29, 2024
5ca4f33
[Evaluation] Change RougeType to Enum (#38131)
ninghu Oct 29, 2024
2063360
Auto-enable Azure AI Inference instrumentation in Azure Monitor, upda…
Oct 30, 2024
6c83494
[AutoRelease] t2-redhatopenshift-2024-10-30-81004(can only be merged …
azure-sdk Oct 30, 2024
69fc484
[AutoRelease] t2-resourcehealth-2024-10-30-72592(can only be merged b…
azure-sdk Oct 30, 2024
19ca69b
[AutoRelease] t2-appconfiguration-2024-10-30-38914(can only be merged…
azure-sdk Oct 30, 2024
c2cdda1
[AutoRelease] t2-databox-2024-10-30-61405(can only be merged by SDK o…
azure-sdk Oct 30, 2024
af19113
[AutoRelease] t2-edgeorder-2024-10-30-57522(can only be merged by SDK…
azure-sdk Oct 30, 2024
142a578
[AutoRelease] t2-extendedlocation-2024-10-30-79235(can only be merged…
azure-sdk Oct 30, 2024
b214335
[AutoRelease] t2-digitaltwins-2024-10-30-74766(can only be merged by …
azure-sdk Oct 30, 2024
e3852f6
Added get_arm_info (#38018)
xiangyan99 Oct 30, 2024
a3c3f4d
Update CHANGELOG.md (#38170)
changliu2 Oct 30, 2024
20a251f
Minor Readme fix (#38191)
nagkumar91 Oct 30, 2024
6603ca3
Minor fixes in vanilla OTel tracing sample (#38194)
Oct 30, 2024
1c3ffe2
Add test for get_arm_endpoints (#38196)
xiangyan99 Oct 30, 2024
0619608
Add overloads for __call__ methods that accept query/response and con…
needuv Oct 30, 2024
0c48225
[Monitor] Apply black formatting (#38129)
pvaneck Oct 30, 2024
9ec0264
[CI] Update autorest CI to use Python 3.9 (#38175)
pvaneck Oct 30, 2024
3f3ab5e
Eval qr json lines now has context from both turns and category if it…
nagkumar91 Oct 30, 2024
83dfe39
Fix doc issues (#38204)
Oct 30, 2024
2c3ad69
Evaluation: Remove `parallel` from composite evaluators (#38168)
ninghu Oct 30, 2024
052acb8
[Core] Allow operation-level tracing attributes (#38164)
pvaneck Oct 30, 2024
e44cb7c
Sync eng/common directory with azure-sdk-tools for PR 9281 (#38213)
azure-sdk Oct 30, 2024
070285e
Sync eng/common directory with azure-sdk-tools for PR 9290 (#38223)
azure-sdk Oct 31, 2024
7ab343b
update (#38220)
msyyc Oct 31, 2024
596b0f5
[AutoRelease] t2-containerservicefleet-2024-10-31-68497(can only be m…
azure-sdk Oct 31, 2024
090851a
[BatchAI] deprecate azure-mgmt-batchai (#38226)
swathipil Oct 31, 2024
a2dfe14
[ModelsRepository] deprecating azure-iot-modelrepository (#38225)
swathipil Oct 31, 2024
20e67ee
[ServerManager] deprecating azure-mgmt-servermanager (#38229)
swathipil Oct 31, 2024
2d4b381
[DocumentDB] deprecate azure-mgmt-documentdb (#38227)
swathipil Oct 31, 2024
499c99c
[EH/SB] ran black (#38210)
l0lawrence Oct 31, 2024
62ff0b7
Update randomization pattern for Adversarial simulation (#38211)
slister1001 Oct 31, 2024
e6c2c82
amqp msg (#38122)
l0lawrence Oct 31, 2024
25d4b5d
Implement live metrics filtering for charts (part 1) (#37998)
lzchen Oct 31, 2024
88ddb5d
Update CODEOWNERS for graphrbac owner (#38236)
swathipil Oct 31, 2024
75f9093
Multi modal docstring improvements (#38193)
w-javed Oct 31, 2024
23b5424
Increment package version after release of azure-core (#38240)
azure-sdk Oct 31, 2024
17ecb3c
kwarg type hints (#38214)
mrm9084 Oct 31, 2024
f9b29ee
[Evaluation] add environment variable for API token refresh rate (#38…
slister1001 Oct 31, 2024
e73ed33
[Evaluation] Default to non-randomized order of template parameters (…
slister1001 Oct 31, 2024
deaabd2
resolve issue with language-settings handling additional service chan…
scbedd Oct 31, 2024
20d8d9d
Reduce unnecessary delete calls to ARM for storage accounts (#38246)
azure-sdk Oct 31, 2024
9c380c9
clean up unused python script (#38128)
scbedd Oct 31, 2024
e3f68e1
Sync eng/common directory with azure-sdk-tools for PR 9288 (#38243)
azure-sdk Oct 31, 2024
127741d
[Scheduler] deprecate azure-mgmt-scheduler (#38228)
swathipil Oct 31, 2024
5f9f6f4
[ServiceManagement] deprecate azure-servicemanagement-legacy (#38230)
swathipil Oct 31, 2024
b678cd1
[GraphRBAC] deprecating package (#38224)
swathipil Oct 31, 2024
f1e8d6a
Enable py2docfx docs gen tool, remove the dockerimage docs validation…
JimSuplizio Oct 31, 2024
0655653
Sync eng/common directory with azure-sdk-tools for PR 9294 (#38251)
azure-sdk Oct 31, 2024
c9ef152
[core] add servicemanagement legacy to ci for release (#38253)
swathipil Oct 31, 2024
4fecbe3
Session Token Management APIs (#36971)
allenkim0129 Nov 5, 2024
e92a163
[AutoRelease] t2-network-2024-10-31-29845(can only be merged by SDK o…
azure-sdk Nov 1, 2024
7acf41b
[ServiceBus/EventHub] add service specific message annotations to rec…
swathipil Nov 1, 2024
9d2c7fc
Updating CODEOWNERS for Synapse (#38255)
swathipil Nov 1, 2024
d9ea7a8
Evaluation: Fix the `output_path` parameter of `evaluate` API doesn't…
ninghu Nov 1, 2024
0009679
[synapse] deprecate azure-synapse (#38262)
swathipil Nov 1, 2024
4c2ad17
[DocumentDB] update deprecation release date (#38265)
swathipil Nov 1, 2024
08107df
[CognitiveServices] deprecate vision packages (#38206)
swathipil Nov 1, 2024
677832b
RAI service input sanitization (#38247)
MilesHolland Nov 1, 2024
d9324d5
pass params from ci.yml to cosmos-sdk-client appropriately (#38272)
scbedd Nov 1, 2024
7d09bd3
Fix __call__ Overload Types (#38238)
needuv Nov 1, 2024
cc5c394
Update deprecation_process.md (#38270)
swathipil Nov 1, 2024
d49ac47
[DocumentDB] add changelog to manifest.ini (#38273)
swathipil Nov 1, 2024
e0dac67
[evaluation] Add support for using evaluate() with evaluators that ha…
diondrapeck Nov 2, 2024
d12aece
disabled black in pyproject.toml for all packages (#38271)
weirongw23-msft Nov 2, 2024
c1ef0e8
[AutoRelease] t2-postgresqlflexibleservers-2024-10-30-49242(can only …
azure-sdk Nov 4, 2024
b056604
[AutoRelease] t2-devtestlabs-2024-11-04-17468(can only be merged by S…
azure-sdk Nov 4, 2024
f1c1a0a
[AutoRelease] t2-sql-2024-10-03-42323(can only be merged by SDK owner…
azure-sdk Nov 4, 2024
a7d5ca0
[EventHub] add ssl_context kwarg to clients (#37702)
swathipil Nov 4, 2024
5eedf8b
Update CHANGELOG.md (#38301)
lzchen Nov 4, 2024
96ba2ea
download_file is fully annotated (#38284)
weirongw23-msft Nov 4, 2024
620fd8c
Release azure-monitor-opentelemetry-exporter (#38310)
lzchen Nov 4, 2024
d9d8ca8
Increment package version after release of azure-monitor-opentelemetr…
azure-sdk Nov 4, 2024
3560c15
Eval/bugfix/content safety parallel (#38307)
MilesHolland Nov 4, 2024
9a453d6
target newly released proxy version (#38282)
azure-sdk Nov 4, 2024
63dd783
[Storage] Added connection pool note to `max_concurrency` kwarg for u…
weirongw23-msft Nov 4, 2024
cab8727
Sync eng/common directory with azure-sdk-tools for PR 9308 (#38311)
azure-sdk Nov 4, 2024
4b85898
Version/location updates for stress script usage (#38281)
azure-sdk Nov 5, 2024
e6855c2
[AutoRelease] t2-loganalytics-2024-11-04-45063(can only be merged by …
azure-sdk Nov 5, 2024
e70e2b4
[AutoRelease] t2-automation-2024-11-04-74277(can only be merged by SD…
azure-sdk Nov 5, 2024
c3ce7dc
Broker on mac support (#38274)
xiangyan99 Nov 5, 2024
02c72b7
Add firewallsku as ManagedNetwork property (#37885)
Nethracs Nov 5, 2024
4f1a889
[AutoRelease] t2-managementgroups-2024-11-04-45946(can only be merged…
azure-sdk Nov 5, 2024
61228e6
[AutoRelease] t2-managedservices-2024-11-04-44075(can only be merged …
azure-sdk Nov 5, 2024
7c8af04
[AutoRelease] t2-marketplaceordering-2024-11-04-08673(can only be mer…
azure-sdk Nov 5, 2024
b5b8d8c
[AutoRelease] t2-servicebus-2024-11-04-58886(can only be merged by SD…
azure-sdk Nov 5, 2024
53b79b0
[Synapse] azure-synapse post deprecation (#38315)
swathipil Nov 5, 2024
3a539de
[Cognitive Services] vision post-deprecation (#38304)
swathipil Nov 5, 2024
5a3a914
[Cosmos] documentdb post deprecation (#38314)
swathipil Nov 5, 2024
a726059
[sdk generation pipeline] fix logic to extract swagger file (#38334)
msyyc Nov 5, 2024
c78ea56
Update deprecation_process.md for Verify Readmes failure (#38333)
swathipil Nov 5, 2024
5d20ca2
Increment package version after release of azure-identity-broker (#38…
azure-sdk Nov 5, 2024
f7926ae
Edit pass on Azure Identity Broker README (#38339)
scottaddie Nov 5, 2024
eca23e6
[Core] Deprecate OpenCensus tracing plugin (#37975)
pvaneck Nov 5, 2024
98822e2
[Core] servicemanagement-legacy post deprecation (#38319)
swathipil Nov 5, 2024
a0ea744
Prompt support for Inference SDK (#37917)
YusakuNo1 Nov 5, 2024
6077526
Remove a defunct variable from docindex.yml (#38342)
JimSuplizio Nov 5, 2024
c34c723
Merge branch 'main' into users/allekim/feature/feedRangeAllVersionsAn…
allenkim0129 Nov 5, 2024
b20c6dc
Fix errors from sphinx and mypy
allenkim0129 Nov 6, 2024
db24ede
Changed parameter to `mode`
allenkim0129 Nov 6, 2024
394d7b3
Fixed typo
allenkim0129 Nov 6, 2024
8e54e8f
Changed 'mode' to be string type
allenkim0129 Nov 6, 2024
cff439f
Reverted necessary type def
allenkim0129 Nov 7, 2024
e43b025
Addressed comments
allenkim0129 Nov 7, 2024
fcf4c04
Added samples for change_feed_mode
allenkim0129 Nov 8, 2024
e8b7fcd
Addressed comments
allenkim0129 Nov 11, 2024
f67326b
Merge branch 'main' into users/allekim/feature/feedRangeAllVersionsAn…
allenkim0129 Nov 11, 2024
a5f8e46
Removed unnecessary docstring
allenkim0129 Nov 13, 2024
b2c0a5e
Merge branch 'main' into users/allekim/feature/feedRangeAllVersionsAn…
allenkim0129 Nov 14, 2024
b3126fb
Merge branch 'main' into users/allekim/feature/feedRangeAllVersionsAn…
allenkim0129 Nov 15, 2024
5b49d0f
Remove mode if 'continuation' was in override definition
allenkim0129 Nov 15, 2024
8b29b72
add test samples tracking (#38502)
kristapratico Nov 15, 2024
ae91385
Add OpenTelemetry LoggingHandler conditionally (#38549)
lzchen Nov 15, 2024
faf6625
Add helpers to log a GitHub "notice" (#38574)
azure-sdk Nov 16, 2024
1fed8a5
[AutoRelease] t2-cosmosdb-2024-11-14-60943(can only be merged by SDK …
azure-sdk Nov 18, 2024
dfe0768
[AutoRelease] t2-mysqlflexibleservers-2024-11-05-47456(can only be me…
azure-sdk Nov 18, 2024
1154089
[AutoRelease] t2-netapp-2024-11-08-58381(can only be merged by SDK ow…
azure-sdk Nov 18, 2024
d3700a9
Shrike (#38560)
achauhan-scc Nov 18, 2024
808fd67
Datastore auth bug (#38586)
achauhan-scc Nov 18, 2024
839ee96
Increment package version after release of azure-search-documents (#3…
azure-sdk Nov 18, 2024
ea1c691
Merge App Config Provider Beta to Main (#38579)
mrm9084 Nov 18, 2024
e716f4b
batching adjustments for create-prjobmatrix (#38597)
azure-sdk Nov 18, 2024
228fbcd
[EG] resource notification event (#38100)
l0lawrence Nov 18, 2024
9549143
Merge branch 'main' into users/allekim/feature/feedRangeAllVersionsAn…
allenkim0129 Nov 18, 2024
c6e2f1b
Updated doc strings
allenkim0129 Nov 18, 2024
217dabc
Merged main
allenkim0129 Nov 21, 2024
4334dc1
Addressed comments
allenkim0129 Nov 21, 2024
19ebb4e
Revert "Merged main"
allenkim0129 Nov 22, 2024
4ffd502
Merge branch 'main' into users/allekim/feature/feedRangeAllVersionsAn…
allenkim0129 Nov 22, 2024
8a3d3dd
Added comment why it is safe to raise exception if mode was missing
allenkim0129 Nov 22, 2024
ba938f6
Added comment why it is safe to raise exception if mode was missing
allenkim0129 Nov 22, 2024
3674c6d
Merge remote-tracking branch 'origin/users/allekim/feature/feedRangeA…
allenkim0129 Nov 22, 2024
4231057
Moved the feature update log under unreleased features
allenkim0129 Nov 22, 2024
eb093a4
Add missing period in changelog
allenkim0129 Nov 22, 2024
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
Prev Previous commit
Next Next commit
Auto-enable Azure AI Inference instrumentation in Azure Monitor, upda…
…te docs (#38071)

* Auto-enable Azure AI Inference instrumentation in Azure Monitor, update docs
  • Loading branch information
Liudmila Molkova authored and allenkim0129 committed Nov 5, 2024
commit 2063360b6145d7dd2e401967945b09655f4e2892
2 changes: 2 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@
"onmicrosoft",
"openai",
"OPENAI",
"otlp",
"OTLP",
"owasp",
"ownerid",
"PBYTE",
Expand Down
59 changes: 40 additions & 19 deletions sdk/ai/azure-ai-inference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ The `EmbeddingsClient` has a method named `embedding`. The method makes a REST A

See simple text embedding example below. More can be found in the [samples](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/ai/azure-ai-inference/samples) folder.

<!--
<!--
### Image Embeddings

TODO: Add overview and link to explain image embeddings.
Expand All @@ -242,7 +242,7 @@ In the following sections you will find simple examples of:
* [Text Embeddings](#text-embeddings-example)
<!-- * [Image Embeddings](#image-embeddings-example) -->

The examples create a synchronous client assuming a Serverless API or Managed Compute endpoint. Modify client
The examples create a synchronous client assuming a Serverless API or Managed Compute endpoint. Modify client
construction code as descirbed in [Key concepts](#key-concepts) to have it work with GitHub Models endpoint or Azure OpenAI
endpoint. Only mandatory input settings are shown for simplicity.

Expand Down Expand Up @@ -275,7 +275,7 @@ print(response.choices[0].message.content)

The following types or messages are supported: `SystemMessage`,`UserMessage`, `AssistantMessage`, `ToolMessage`. See also samples:

* [sample_chat_completions_with_tools.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_tools.py) for usage of `ToolMessage`.
* [sample_chat_completions_with_tools.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_tools.py) for usage of `ToolMessage`.
* [sample_chat_completions_with_image_url.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_image_url.py) for usage of `UserMessage` that
includes sending an image URL.
* [sample_chat_completions_with_image_data.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-inference/samples/sample_chat_completions_with_image_data.py) for usage of `UserMessage` that
Expand Down Expand Up @@ -535,15 +535,44 @@ For more information, see [Configure logging in the Azure libraries for Python](

To report issues with the client library, or request additional features, please open a GitHub issue [here](https://github.com/Azure/azure-sdk-for-python/issues)

## Tracing
## Observability With OpenTelemetry

The Azure AI Inference client library provides experimental support for tracing with OpenTelemetry.

You can capture prompt and completion contents by setting `AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED` environment to `true` (case insensitive).
By default prompts, completions, function name, parameters or outputs are not recorded.

The Azure AI Inferencing API Tracing library provides tracing for Azure AI Inference client library for Python. Refer to Installation chapter above for installation instructions.
### Setup with Azure Monitor

### Setup
When using Azure AI Inference library with [Azure Monitor OpenTelemetry Distro](https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-enable?tabs=python),
distributed tracing for Azure AI Inference calls is enabled by default when using latest version of the distro.

The environment variable AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED controls whether the actual message contents will be recorded in the traces or not. By default, the message contents are not recorded as part of the trace. When message content recording is disabled any function call tool related function names, function parameter names and function parameter values are also not recorded in the trace. Set the value of the environment variable to "true" (case insensitive) for the message contents to be recorded as part of the trace. Any other value will cause the message contents not to be recorded.
### Setup with OpenTelemetry

You also need to configure the tracing implementation in your code by setting `AZURE_SDK_TRACING_IMPLEMENTATION` to `opentelemetry` or configuring it in the code with the following snippet:
Check out your observability vendor documentation on how to configure OpenTelemetry or refer to the [official OpenTelemetry documentation](https://opentelemetry.io/docs/languages/python/).

#### Installation

Make sure to install OpenTelemetry and the Azure SDK tracing plugin via

```bash
pip install opentelemetry
pip install azure-core-tracing-opentelemetry
```

You will also need an exporter to send telemetry to your observability backend. You can print traces to the console or use a local viewer such as [Aspire Dashboard](https://learn.microsoft.com/dotnet/aspire/fundamentals/dashboard/standalone?tabs=bash).

To connect to Aspire Dashboard or another OpenTelemetry compatible backend, install OTLP exporter:

```bash
pip install opentelemetry-exporter-otlp
```

#### Configuration

To enable Azure SDK tracing set `AZURE_SDK_TRACING_IMPLEMENTATION` environment variable to `opentelemetry`.

Or configure it in the code with the following snippet:

<!-- SNIPPET:sample_chat_completions_with_tracing.trace_setting -->

Expand All @@ -556,16 +585,7 @@ settings.tracing_implementation = "opentelemetry"

Please refer to [azure-core-tracing-documentation](https://learn.microsoft.com/python/api/overview/azure/core-tracing-opentelemetry-readme) for more information.

### Exporting Traces with OpenTelemetry

Azure AI Inference is instrumented with OpenTelemetry. In order to enable tracing you need to configure OpenTelemetry to export traces to your observability backend.
Refer to [Azure SDK tracing in Python](https://learn.microsoft.com/python/api/overview/azure/core-tracing-opentelemetry-readme?view=azure-python-preview) for more details.

Refer to [Azure Monitor OpenTelemetry documentation](https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-enable?tabs=python) for the details on how to send Azure AI Inference traces to Azure Monitor and create Azure Monitor resource.

### Instrumentation

Use the AIInferenceInstrumentor to instrument the Azure AI Inferencing API for LLM tracing, this will cause the LLM traces to be emitted from Azure AI Inferencing API.
The final step is to enable Azure AI Inference instrumentation with the following code snippet:

<!-- SNIPPET:sample_chat_completions_with_tracing.instrument_inferencing -->

Expand All @@ -589,7 +609,8 @@ AIInferenceInstrumentor().uninstrument()
<!-- END SNIPPET -->

### Tracing Your Own Functions
The @tracer.start_as_current_span decorator can be used to trace your own functions. This will trace the function parameters and their values. You can also add further attributes to the span in the function implementation as demonstrated below. Note that you will have to setup the tracer in your code before using the decorator. More information is available [here](https://opentelemetry.io/docs/languages/python/).

The `@tracer.start_as_current_span` decorator can be used to trace your own functions. This will trace the function parameters and their values. You can also add further attributes to the span in the function implementation as demonstrated below. Note that you will have to setup the tracer in your code before using the decorator. More information is available [here](https://opentelemetry.io/docs/languages/python/).

<!-- SNIPPET:sample_chat_completions_with_tracing.trace_function -->

Expand Down
1 change: 0 additions & 1 deletion sdk/ai/azure-ai-inference/azure/ai/inference/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ def __init__(

super().__init__(endpoint, credential, **kwargs)


@overload
def complete(
self,
Expand Down
1 change: 1 addition & 0 deletions sdk/ai/azure-ai-inference/dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-e ../../../tools/azure-sdk-tools
../../core/azure-core
../../core/azure-core-tracing-opentelemetry
../../monitor/azure-monitor-opentelemetry
aiohttp
opentelemetry-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ async def sample_chat_completions_from_input_json_async():
"role": "assistant",
"content": "The main construction of the International Space Station (ISS) was completed between 1998 and 2011. During this period, more than 30 flights by US space shuttles and 40 by Russian rockets were conducted to transport components and modules to the station.",
},
{
"role": "user",
"content": "And what was the estimated cost to build it?"
},
{"role": "user", "content": "And what was the estimated cost to build it?"},
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def sample_chat_completions_azure_openai():
endpoint=endpoint,
credential=DefaultAzureCredential(exclude_interactive_browser_credential=False),
credential_scopes=["https://cognitiveservices.azure.com/.default"],
api_version="2024-06-01", # Azure OpenAI api-version. See https://aka.ms/azsdk/azure-ai-inference/azure-openai-api-versions
api_version="2024-06-01", # Azure OpenAI api-version. See https://aka.ms/azsdk/azure-ai-inference/azure-openai-api-versions
)

response = client.complete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def sample_chat_completions_from_input_json():
"role": "assistant",
"content": "The main construction of the International Space Station (ISS) was completed between 1998 and 2011. During this period, more than 30 flights by US space shuttles and 40 by Russian rockets were conducted to transport components and modules to the station.",
},
{
"role": "user",
"content": "And what was the estimated cost to build it?"
},
{"role": "user", "content": "And what was the estimated cost to build it?"},
]
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def sample_chat_completions_from_input_json_with_image_url():
model_deployment = None

client = ChatCompletionsClient(
endpoint=endpoint,
credential=AzureKeyCredential(key),
headers={"azureml-model-deployment": model_deployment}
endpoint=endpoint, credential=AzureKeyCredential(key), headers={"azureml-model-deployment": model_deployment}
)

response = client.complete(
Expand All @@ -69,10 +67,7 @@ def sample_chat_completions_from_input_json_with_image_url():
{
"role": "user",
"content": [
{
"type": "text",
"text": "What's in this image?"
},
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

use_azure_openai_endpoint = True


def sample_chat_completions_streaming_with_tools():
import os
import json
Expand Down Expand Up @@ -79,11 +80,9 @@ def get_flight_info(origin_city: str, destination_city: str):
str: The airline name, fight number, date and time of the next flight between the cities, in JSON format.
"""
if origin_city == "Seattle" and destination_city == "Miami":
return json.dumps({
"airline": "Delta",
"flight_number": "DL123",
"flight_date": "May 7th, 2024",
"flight_time": "10:00AM"})
return json.dumps(
{"airline": "Delta", "flight_number": "DL123", "flight_date": "May 7th, 2024", "flight_time": "10:00AM"}
)
return json.dumps({"error": "No flights found between the cities"})

# Define a function 'tool' that the model can use to retrieves flight information
Expand Down Expand Up @@ -117,21 +116,15 @@ def get_flight_info(origin_city: str, destination_city: str):
)
else:
# Create a chat completions client for Serverless API endpoint or Managed Compute endpoint
client = ChatCompletionsClient(
endpoint=endpoint,
credential=AzureKeyCredential(key)
)
client = ChatCompletionsClient(endpoint=endpoint, credential=AzureKeyCredential(key))

# Make a streaming chat completions call asking for flight information, while providing a tool to handle the request
messages = [
SystemMessage(content="You an assistant that helps users find flight information."),
UserMessage(content="What is the next flights from Seattle to Miami?"),
]

response = client.complete(
messages=messages,
tools=[flight_info],
stream=True)
response = client.complete(messages=messages, tools=[flight_info], stream=True)

# Note that in the above call we did not specify `tool_choice`. The service defaults to a setting equivalent
# to specifying `tool_choice=ChatCompletionsToolChoicePreset.AUTO`. Other than ChatCompletionsToolChoicePreset
Expand All @@ -158,11 +151,7 @@ def get_flight_info(origin_city: str, destination_city: str):
AssistantMessage(
tool_calls=[
ChatCompletionsToolCall(
id=tool_call_id,
function=FunctionCall(
name=function_name,
arguments=function_args
)
id=tool_call_id, function=FunctionCall(name=function_name, arguments=function_args)
)
]
)
Expand All @@ -176,19 +165,10 @@ def get_flight_info(origin_city: str, destination_city: str):
print(f"Function response = {function_response}")

# Append the function response as a tool message to the chat history
messages.append(
ToolMessage(
tool_call_id=tool_call_id,
content=function_response
)
)
messages.append(ToolMessage(tool_call_id=tool_call_id, content=function_response))

# With the additional tools information on hand, get another streaming response from the model
response = client.complete(
messages=messages,
tools=[flight_info],
stream=True
)
response = client.complete(messages=messages, tools=[flight_info], stream=True)

print("Model response = ", end="")
for update in response:
Expand Down
Loading