Skip to content

Commit 8d35ba8

Browse files
stainless-botRobertCraigie
authored andcommitted
feat(cli): use http/2 if h2 is available
1 parent 86841a0 commit 8d35ba8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/openai/cli/_cli.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from . import _tools
1313
from .. import OpenAI, __version__
1414
from ._api import register_commands
15-
from ._utils import set_client
15+
from ._utils import set_client, can_use_http2
1616
from .._types import ProxiesDict
1717
from ._errors import CLIError, display_error
1818
from .._compat import PYDANTIC_V2, ConfigDict, model_parse
@@ -149,6 +149,7 @@ def _main() -> None:
149149

150150
http_client = httpx.Client(
151151
proxies=proxies or None,
152+
http2=can_use_http2(),
152153
)
153154

154155
try:
@@ -178,14 +179,12 @@ def _main() -> None:
178179
)
179180
else:
180181
parsed.func()
181-
except Exception:
182+
finally:
182183
try:
183184
http_client.close()
184185
except Exception:
185186
pass
186187

187-
raise
188-
189188

190189
if __name__ == "__main__":
191190
sys.exit(main())

src/openai/cli/_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ def organization_info() -> str:
4646

4747
def print_model(model: BaseModel) -> None:
4848
sys.stdout.write(model_json(model, indent=2) + "\n")
49+
50+
51+
def can_use_http2() -> bool:
52+
try:
53+
import h2 # type: ignore # noqa
54+
except ImportError:
55+
return False
56+
57+
return True

0 commit comments

Comments
 (0)