-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: Update gen_ai traces and logs (#10173)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> The gen_ai semantic convention has gone through some updates since we started generating telemetry for gen_ai operations. We would like to align with the latest conventions, and most importantly allow our users to visualize the gen_ai traces on the Azure AI Foundry Tracing UI, which relies on the gen_ai conventions. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> 1. Updates the gen_ai telemetry module to align with the latest gen_ai convention so that all AI connectors generate telemetry data that can be visualized on Azure AI Foundry. 2. Unit tests for the update. > Note that this is a breaking change as this feature is still experimental. Anyone who is relying on the previous gen_ai conventions should also update. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
- Loading branch information
1 parent
bc3e294
commit bf45719
Showing
6 changed files
with
271 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 29 additions & 13 deletions
42
python/semantic_kernel/utils/telemetry/model_diagnostics/gen_ai_attributes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
from semantic_kernel.contents.utils.author_role import AuthorRole | ||
|
||
# Constants for tracing activities with semantic conventions. | ||
# Ideally, we should use the attributes from the semcov package. | ||
# However, many of the attributes are not yet available in the package, | ||
# so we define them here for now. | ||
|
||
# Activity tags | ||
SYSTEM = "gen_ai.system" | ||
OPERATION = "gen_ai.operation.name" | ||
SYSTEM = "gen_ai.system" | ||
ERROR_TYPE = "error.type" | ||
MODEL = "gen_ai.request.model" | ||
MAX_TOKENS = "gen_ai.request.max_tokens" # nosec | ||
SEED = "gen_ai.request.seed" | ||
PORT = "server.port" | ||
ENCODING_FORMATS = "gen_ai.request.encoding_formats" | ||
FREQUENCY_PENALTY = "gen_ai.request.frequency_penalty" | ||
MAX_TOKENS = "gen_ai.request.max_tokens" | ||
STOP_SEQUENCES = "gen_ai.request.stop_sequences" | ||
TEMPERATURE = "gen_ai.request.temperature" | ||
TOP_K = "gen_ai.request.top_k" | ||
TOP_P = "gen_ai.request.top_p" | ||
RESPONSE_ID = "gen_ai.response.id" | ||
FINISH_REASON = "gen_ai.response.finish_reason" | ||
PROMPT_TOKENS = "gen_ai.response.prompt_tokens" # nosec | ||
COMPLETION_TOKENS = "gen_ai.response.completion_tokens" # nosec | ||
RESPONSE_ID = "gen_ai.response.id" | ||
INPUT_TOKENS = "gen_ai.usage.input_tokens" | ||
OUTPUT_TOKENS = "gen_ai.usage.output_tokens" | ||
ADDRESS = "server.address" | ||
PORT = "server.port" | ||
ERROR_TYPE = "error.type" | ||
|
||
# Activity events | ||
PROMPT_EVENT = "gen_ai.content.prompt" | ||
COMPLETION_EVENT = "gen_ai.content.completion" | ||
|
||
# Activity event attributes | ||
PROMPT_EVENT_PROMPT = "gen_ai.prompt" | ||
COMPLETION_EVENT_COMPLETION = "gen_ai.completion" | ||
EVENT_NAME = "event.name" | ||
SYSTEM_MESSAGE = "gen_ai.system.message" | ||
USER_MESSAGE = "gen_ai.user.message" | ||
ASSISTANT_MESSAGE = "gen_ai.assistant.message" | ||
TOOL_MESSAGE = "gen_ai.tool.message" | ||
CHOICE = "gen_ai.choice" | ||
PROMPT = "gen_ai.prompt" | ||
|
||
# Kernel specific attributes | ||
AVAILABLE_FUNCTIONS = "sk.available_functions" | ||
|
||
|
||
ROLE_EVENT_MAP = { | ||
AuthorRole.SYSTEM: SYSTEM_MESSAGE, | ||
AuthorRole.USER: USER_MESSAGE, | ||
AuthorRole.ASSISTANT: ASSISTANT_MESSAGE, | ||
AuthorRole.TOOL: TOOL_MESSAGE, | ||
} |
Oops, something went wrong.