Skip to content

HTTP Connection is not reused in stream mode #95

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
andrewchernyh opened this issue May 19, 2022 · 0 comments · Fixed by #94
Closed

HTTP Connection is not reused in stream mode #95

andrewchernyh opened this issue May 19, 2022 · 0 comments · Fixed by #94

Comments

@andrewchernyh
Copy link
Contributor

Requesting api in stream mode is not reusing HTTP Connection

Logs:

...
DEBUG:urllib3.connectionpool:Resetting dropped connection: api.openai.com
...

wireshark screenshot
image

minimal code to reproduce:

import openai
from http.client import HTTPConnection
import logging


HTTPConnection.debuglevel = 10
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

def test():
    openai_response = openai.Completion.create(
        engine="text-davinci-002",
        prompt="Test prompt",
        temperature=1.0,
        max_tokens=120,
        top_p=1.0,
        stream=True,
    )

    for resp in openai_response:
        text = resp["choices"][0]["text"]

test()
test()

Why need to fix?
TCP and TLS handshake can be slow and it's better to reuse connections

GinoBacallao pushed a commit to GinoBacallao/openai-python that referenced this issue Jun 24, 2022
* Make embeddings_utils be importable (openai#104)

* Make embeddings_utils be importable

* Small tweaks to dicts for typing

* Remove default api_prefix and move v1 prefix to default api_base (openai#95)

* make construct_from key argument optional (openai#92)

* Split search.prepare_data into answers/classifications/search versions (openai#93)

* Break out prepare_data into answers, classifications, and search

* And cleaned up CLI

* Validate search files (openai#69)

* Add validators for search files

* Clean up fields

Co-authored-by: kennyhsu5 <[email protected]>
Co-authored-by: Madeleine Thompson <[email protected]>
cgayapr pushed a commit to cgayapr/openai-python that referenced this issue Dec 14, 2024
* Make embeddings_utils be importable (openai#104)

* Make embeddings_utils be importable

* Small tweaks to dicts for typing

* Remove default api_prefix and move v1 prefix to default api_base (openai#95)

* make construct_from key argument optional (openai#92)

* Split search.prepare_data into answers/classifications/search versions (openai#93)

* Break out prepare_data into answers, classifications, and search

* And cleaned up CLI

* Validate search files (openai#69)

* Add validators for search files

* Clean up fields

Co-authored-by: kennyhsu5 <[email protected]>
Co-authored-by: Madeleine Thompson <[email protected]>
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

Successfully merging a pull request may close this issue.

1 participant