Skip to content

export 'Usage' class as apart of openai.types #1135

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

Closed
1 task done
lilyydu opened this issue Feb 7, 2024 · 2 comments
Closed
1 task done

export 'Usage' class as apart of openai.types #1135

lilyydu opened this issue Feb 7, 2024 · 2 comments

Comments

@lilyydu
Copy link

lilyydu commented Feb 7, 2024

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • This is a feature request for the Python library

Describe the feature or improvement you're requesting

Hi there,

I'm using the library and writing tests to mock CreateEmbeddingResponse. To mock the class, I'm configuring the properties, including the usage parameter. I'd like to instantiate a 'Usage' object for this. Hence, requesting it to be exported with openai.types. Thanks!

Additional context

No response

aacebo added a commit to microsoft/teams-ai that referenced this issue Feb 8, 2024
## Linked issues

closes: #1070 

## Details

Implemented the logic and tests for embeddings for Python, based on JS.

1. Client API calls and types are using the [OpenAI Python API
library](https://github.com/openai/openai-python/tree/main)
2. I restructured the interfaces and classes for AzureOpenAI and OpenAI
into its own classes. Two reasons- (a) some logic is different, and (b)
this allows for better maintainability + response to bugs since they
depend on different clients and configurations from the API library.
3. To replicate `setTimeout` in retries, I've used `asyncio.sleep` but
open to better preferences/suggestions if any
4. Logging follows C# implementation (no colorization)
5. Had to disable 2 _pylint_ and _mypy_ type/argument checker
(`unused-argument` because mock.patch requires the same method
signature, and `arg-type` because openai.types doesn't yet export the
Usage class- [filed a request
here](openai/openai-python#1135))

## Attestation Checklist

- [x] My code follows the style guidelines of this project

- I have checked for/fixed spelling, linting, and other errors
- I have commented my code for clarity
- I have made corresponding changes to the documentation (updating the
doc strings in the code is sufficient)
- My changes generate no new warnings
- I have added tests that validates my changes, and provides sufficient
test coverage. I have tested with:
  - Local testing
  - E2E testing in Teams
- New and existing unit tests pass locally with my changes

---------

Co-authored-by: Alex Acebo <[email protected]>
@rattrayalex
Copy link
Collaborator

cc @RobertCraigie can you share how to access this?

@RobertCraigie
Copy link
Collaborator

Hi @lilyydu, there are two ways you can access the Usage type today:

from openai.types.create_embedding_response import Usage

or

from openai.types import create_embedding_response

create_embedding_response.Usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants