Python: Support for cases where "logprobs" does not exist(OpenAITextCompletionBase)#5071
Merged
moonbox3 merged 1 commit intomicrosoft:mainfrom Feb 20, 2024
ymuichiro:main
Merged
Python: Support for cases where "logprobs" does not exist(OpenAITextCompletionBase)#5071moonbox3 merged 1 commit intomicrosoft:mainfrom ymuichiro:main
moonbox3 merged 1 commit intomicrosoft:mainfrom
ymuichiro:main
Conversation
eavanvalkenburg
approved these changes
Feb 19, 2024
Member
eavanvalkenburg
left a comment
There was a problem hiding this comment.
Thanks for adding this!
juliomenendez
approved these changes
Feb 20, 2024
LudoCorporateShark
pushed a commit
to LudoCorporateShark/semantic-kernel
that referenced
this pull request
Aug 25, 2024
…ompletionBase) (microsoft#5071) ### Motivation and Context 1. Why is this change required? An error has occurred. This is the same issue as the following: Azure OpenAI API may not include logprobs. The recent change only modified OpenAIChatCompletionBase. However, it turns out that this issue also occurs with OpenAITextCompletionBase. Therefore, I propose to make a similar fix. microsoft#4923 2. What problem does it solve? Non-existent property lobprobs is referenced when using Azure OpenAI Text Completion. 3. What scenario does it contribute to? When using Azure OpenAI TextCompletion 4. If it fixes an open issue, please link to the issue here. microsoft#5070 ### Description Azure OpenAI ChatCompletion does not return logprobs.(It seems that there are cases where it is returned, but I have not encountered that case yet.) Thus, the following code would be "AttributeError: 'Choice' object has no attribute 'logprobs'". `class OpenAITextCompletionBase` ```python def _get_metadata_from_text_choice(self, choice: CompletionChoice) -> Dict[str, Any]: """Get metadata from a completion choice.""" return { "logprobs": choice.logprobs, } ``` do the following ```python def _get_metadata_from_text_choice(self, choice: CompletionChoice) -> Dict[str, Any]: """Get metadata from a completion 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 😄
Bryan-Roe
pushed a commit
to Bryan-Roe-ai/semantic-kernel
that referenced
this pull request
Oct 6, 2024
…ompletionBase) (microsoft#5071) ### Motivation and Context 1. Why is this change required? An error has occurred. This is the same issue as the following: Azure OpenAI API may not include logprobs. The recent change only modified OpenAIChatCompletionBase. However, it turns out that this issue also occurs with OpenAITextCompletionBase. Therefore, I propose to make a similar fix. microsoft#4923 2. What problem does it solve? Non-existent property lobprobs is referenced when using Azure OpenAI Text Completion. 3. What scenario does it contribute to? When using Azure OpenAI TextCompletion 4. If it fixes an open issue, please link to the issue here. microsoft#5070 ### Description Azure OpenAI ChatCompletion does not return logprobs.(It seems that there are cases where it is returned, but I have not encountered that case yet.) Thus, the following code would be "AttributeError: 'Choice' object has no attribute 'logprobs'". `class OpenAITextCompletionBase` ```python def _get_metadata_from_text_choice(self, choice: CompletionChoice) -> Dict[str, Any]: """Get metadata from a completion choice.""" return { "logprobs": choice.logprobs, } ``` do the following ```python def _get_metadata_from_text_choice(self, choice: CompletionChoice) -> Dict[str, Any]: """Get metadata from a completion 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 😄
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
An error has occurred. This is the same issue as the following: Azure OpenAI API may not include logprobs.
The recent change only modified OpenAIChatCompletionBase. However, it turns out that this issue also occurs with OpenAITextCompletionBase. Therefore, I propose to make a similar fix.
#4923
Non-existent property lobprobs is referenced when using Azure OpenAI Text Completion.
When using Azure OpenAI TextCompletion
#5070
Description
Azure OpenAI ChatCompletion does not return logprobs.(It seems that there are cases where it is returned, but I have not encountered that case yet.)
Thus, the following code would be "AttributeError: 'Choice' object has no attribute 'logprobs'".
class OpenAITextCompletionBasedo the following
Contribution Checklist