Skip to content

Python: Bug report && fix: KernelFunction.invoke_stream: Error(" 'ChatCompletionChunk' object has no attribute 'usage' ") #5114

@fisherOu

Description

@fisherOu

Fix Advise
Error source in line: https://github.com/microsoft/semantic-kernel/blob/main/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_completion_base.py#L109
Fix advise: change _get_metadata_from_text_response to _get_metadata_from_streaming_text_response.

Describe the bug
When using semantic-kernel==0.5.1.dev0, an error will be occured using KernelFunction.invoke_stream

To Reproduce
Steps to reproduce the behavior:

  1. func = kernel.create_semantic_function(prompt)
  2. async for response in kernel.run_stream(func, input_vars=variables)
  3. See error

Expected behavior
get stream response.

Platform

  • OS: Ubuntu22.04
  • IDE: VS Code
  • Language: Python
  • Source: pip package version 0.5.1.dev0

Additional context
Error source in line: https://github.com/microsoft/semantic-kernel/blob/main/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_completion_base.py#L109
Fix advise: change _get_metadata_from_text_response to _get_metadata_from_streaming_text_response.

Metadata

Metadata

Assignees

Labels

pythonPull requests for the Python Semantic Kernel

Type

No type

Projects

Status

Sprint: Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions