openai / openai-python

The official Python library for the OpenAI API
https://pypi.org/project/openai/
Apache License 2.0
23.16k stars 3.27k forks source link

Limits argument can never get passed down? #1790

Open dmakhervaks opened 1 month ago

dmakhervaks commented 1 month ago

Confirm this is an issue with the Python library and not an underlying OpenAI API

Describe the bug

It seems as though when initializing an openAI client like so:

since you cannot pass in the limits argument as a parameter, it will always default to the DEFAULT value here:

https://github.com/openai/openai-python/blob/aa6818997468b753546d55365d8142e2bb1c6640/src/openai/_base_client.py#L1127

openai.AsyncClient(())

To Reproduce

  1. Initialize an openai client like so: openai.AsyncClient(())
  2. Try to pass in 'limits' argument or modify the 'http_client' to have custom Limits.
  3. This will not actually be propagated

Code snippets

openai.AsyncClient(())

OS

linux

Python version

3.9.12

Library version

1.50.0

RobertCraigie commented 3 weeks ago

modify the 'http_client' to have custom Limits.

I cannot reproduce this part, passing in a custom HTTP client with different limits does get propagated

import httpx
from openai import AsyncOpenAI

client = AsyncOpenAI(
    http_client=httpx.AsyncClient(
        limits=httpx.Limits(
            max_connections=1,
        )
    )
)
print(client._client._transport._pool._max_connections)

This prints 1 for me. Is it different for you?


Separately it is intentional that you can't pass limits directly to OpenAI(), the code you linked to is left-over from the original implementation and we haven't removed that yet.

The intended path for customizing limits is by passing your own HTTP client instance directly.