Skip to content

Commit 40c81bd

Browse files
Pin openai<1.40 (jiter dependency fails on PyPy), handle max_tokens compat
openai>=1.40 requires jiter which needs Rust compilation and fails on PyPy. Keep openai<1.40 and handle max_completion_tokens vs max_tokens by trying the new parameter first, falling back to old if the library doesn't support it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1a87f32 commit 40c81bd

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

queries/util/openai_gpt.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,20 @@ class Completion:
8181
def _create(cls, *args: Any, **kwargs: Any) -> ChatCompletion:
8282
"""
8383
Creates a new completion while handling formatting and parsing.
84+
Newer OpenAI models require max_completion_tokens instead of
85+
max_tokens; try the new parameter first and fall back to the old.
8486
"""
85-
# Newer OpenAI models use max_completion_tokens instead of max_tokens
8687
if "max_tokens" in kwargs:
87-
kwargs["max_completion_tokens"] = kwargs.pop("max_tokens")
88+
max_val = kwargs.pop("max_tokens")
89+
try:
90+
return client.chat.completions.create(
91+
*args, model=MODEL, max_completion_tokens=max_val, **kwargs
92+
)
93+
except TypeError:
94+
# Older openai library doesn't support max_completion_tokens
95+
return client.chat.completions.create(
96+
*args, model=MODEL, max_tokens=max_val, **kwargs
97+
)
8898
return client.chat.completions.create(*args, model=MODEL, **kwargs)
8999

90100
@classmethod

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ rjsmin>=1.2.4
2727
python-youtube==0.9.1
2828
country-list>=1.1.0
2929
# For OpenAI GPT support
30-
openai>=1.40.0,<2.0
30+
openai>=1.14.3,<1.40
3131
httpx>=0.27.2
3232
# Ours
3333
reynir>=3.5.7

0 commit comments

Comments
 (0)