Python: Support for cases where "logprobs" does not exist#4924
Python: Support for cases where "logprobs" does not exist#4924moonbox3 merged 4 commits intomicrosoft:mainfrom yuichiromukaiyama:main
Conversation
moonbox3
left a comment
There was a problem hiding this comment.
Hi @yuichiromukaiyama, thank you for your work on this. I agree that it seems like useful to have this type of error handling as it appears the logprobs attribute may not always be present (depending upon what underlying model you're using). I see on the following page that it mentions that logprobs is not available with gpt-35-turbo. Otherwise, in the swagger spec links you provided, for both 2023-05-15-previous and 2023-12-01-preview, they both contain the logprobs properties.
|
@yuichiromukaiyama note that our GitHub actions |
eavanvalkenburg
left a comment
There was a problem hiding this comment.
Thanks for adding this @yuichiromukaiyama
|
Thank you so much! |
|
@yuichiromukaiyama your change went in just in time for the latest release. Thank you for your contribution! |
|
I am still getting error..I am using "0.5.1.dev0", I see latest code ,but not sure issues is resolved completely def _get_metadata_from_chat_choice(self, choice: Union[Choice, ChunkChoice]) -> Dict[str, Any]: |
|
@veeruhai ↓ |
|
@yuichiromukaiyama , |
|
I investigated the issue and I believe it is the same as the one I described in the "Discussion". Both use PromptTemplate, and the error seems to be occurring in a class that I have not modified. The problem can be solved by changing the PromptTemplate used in this class to ChatPromptTemplate. I believe that the sequential planner also performs the following process: To solve the root cause, I plan to issue a PR to make the following changes: ↓ In the following section, kernel.register_semantic_function is called in _init_flow_function of SequentialPlanner. Since the use of PromptTemplate is enforced in Planner, TextCompletionClientBase is used in the following section: There is TextCompletionClientBase, which is inherited by OpenAITextCompletionBase. OpenAITextCompletionBase also has the corresponding logprobs code. This will be rewritten as optional in the same way. |
…4924) ### Motivation and Context 1. Why is this change required? An error has occurred. microsoft#4923 2. What problem does it solve? Non-existent property lobprobs is referenced when using Azure OpenAI Chat Completion. [Swagger 2023-12-01-preview](https://github.com/Azure/azure-rest-api-specs/tree/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-12-01-preview) [Swagger 2023-05-15](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/stable/2023-05-15/inference.json) 3. What scenario does it contribute to? When using Azure OpenAI ChatCompletion 4. If it fixes an open issue, please link to the issue here. microsoft#4923 ### Description Azure OpenAI ChatCompletion does not return logprobs. Thus, the following code would be "AttributeError: 'Choice' object has no attribute 'logprobs'". ```python def _get_metadata_from_chat_choice(self, choice: Union[Choice, ChunkChoice]) -> Dict[str, Any]: """Get metadata from a chat choice.""" return { "logprobs": choice.logprobs, } ``` do the following ```python def _get_metadata_from_chat_choice(self, choice: Union[Choice, ChunkChoice]) -> Dict[str, Any]: """Get metadata from a chat choice.""" return { "logprobs": getattr(choice, "logprobs", None), } ``` ### Contribution Checklist - [- ] The code builds clean without any errors or warnings - [- ] 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 - [-] All unit tests pass, and I have added new tests where possible - [- ] I didn't break anyone 😄 Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>


Motivation and Context
Why is this change required?
An error has occurred.
Python: AttributeError: 'Choice' object has no attribute 'logprobs' #4923
What problem does it solve?
Non-existent property lobprobs is referenced when using Azure OpenAI Chat Completion.
Swagger 2023-12-01-preview
Swagger 2023-05-15
What scenario does it contribute to?
When using Azure OpenAI ChatCompletion
If it fixes an open issue, please link to the issue here.
Python: AttributeError: 'Choice' object has no attribute 'logprobs' #4923
Description
Azure OpenAI ChatCompletion does not return logprobs.
Thus, the following code would be "AttributeError: 'Choice' object has no attribute 'logprobs'".
do the following
Contribution Checklist