Skip to content

Python: Support for cases where "logprobs" does not exist(OpenAITextCompletionBase)#5071

Merged
moonbox3 merged 1 commit intomicrosoft:mainfrom
ymuichiro:main
Feb 20, 2024
Merged

Python: Support for cases where "logprobs" does not exist(OpenAITextCompletionBase)#5071
moonbox3 merged 1 commit intomicrosoft:mainfrom
ymuichiro:main

Conversation

@ymuichiro
Copy link
Contributor

@ymuichiro ymuichiro commented Feb 19, 2024

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.

#4923

  1. What problem does it solve?

Non-existent property lobprobs is referenced when using Azure OpenAI Text Completion.

  1. What scenario does it contribute to?

When using Azure OpenAI TextCompletion

  1. If it fixes an open issue, please link to the issue here.

#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

    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

    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

@ymuichiro ymuichiro requested a review from a team as a code owner February 19, 2024 08:17
@shawncal shawncal added the python Pull requests for the Python Semantic Kernel label Feb 19, 2024
Copy link
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

@moonbox3 moonbox3 added this pull request to the merge queue Feb 20, 2024
Merged via the queue into microsoft:main with commit 8a01240 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 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants