Skip to content

Python: Don't store AzureAIInferenceChatCompletion response inner_content inside of item's text content #10747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

moonbox3
Copy link
Contributor

@moonbox3 moonbox3 commented Mar 3, 2025

Motivation and Context

The AzureAIInferenceChatCompletion class, during _create_chat_message_content creation, is storing the response which is a non-hashable object. In other connectors, like the AzureChatCompletion we do not store the response in the CMC's TextContent item. The response is available as part of the main ChatMessageContent that is returned, so we don't need to store this twice, especially since as part of agent group chat, we need to be able to get the inner item's hash for message comparison.

Description

Remove the call to store the response as the item's inner_content here:

items.append(
    TextContent(
        text=choice.message.content,
        # inner_content=response, <--- removed
        metadata=metadata,
    )
)

Contribution Checklist

@moonbox3 moonbox3 requested a review from a team as a code owner March 3, 2025 02:22
@moonbox3 moonbox3 changed the title Python: Don't store AzureAIInferenceChatCompletion response inner_content inside of item Python: Don't store AzureAIInferenceChatCompletion response inner_content inside of item's text content Mar 3, 2025
@markwallace-microsoft markwallace-microsoft added the python Pull requests for the Python Semantic Kernel label Mar 3, 2025
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel/connectors/ai/azure_ai_inference/services
   azure_ai_inference_chat_completion.py110695%120–123, 132, 156, 182
TOTAL19018238087% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3199 5 💤 1 ❌ 0 🔥 1m 32s ⏱️

@moonbox3 moonbox3 added this pull request to the merge queue Mar 3, 2025
Merged via the queue into microsoft:main with commit c140db3 Mar 3, 2025
32 checks passed
@moonbox3 moonbox3 deleted the agent-group-chat-fix branch March 3, 2025 10:23
@github-project-automation github-project-automation bot moved this to Sprint: Done in Semantic Kernel Mar 3, 2025
musale pushed a commit to musale/semantic-kernel that referenced this pull request Mar 10, 2025
…tent inside of item's text content (microsoft#10747)

### Motivation and Context

The `AzureAIInferenceChatCompletion` class, during
`_create_chat_message_content` creation, is storing the `response` which
is a non-hashable object. In other connectors, like the
`AzureChatCompletion` we do not store the `response` in the CMC's
TextContent item. The `response` is available as part of the main
`ChatMessageContent` that is returned, so we don't need to store this
twice, especially since as part of agent group chat, we need to be able
to get the inner item's hash for message comparison.

<!-- 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.
-->

### Description

Remove the call to store the response as the item's inner_content here:

```python
items.append(
    TextContent(
        text=choice.message.content,
        # inner_content=response, <--- removed
        metadata=metadata,
    )
)
```

- Closes microsoft#10722

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### 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
- [X] I didn't break anyone 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai connector Anything related to AI connectors python Pull requests for the Python Semantic Kernel
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Python: Bug: TypeError: unhashable type: 'ChatCompletions' when using AgentGroupChat with AzureAIInferenceChatCompletion service.
3 participants