Skip to content

feat: support OpenAI 2 in Python client#806

Open
scale-ballen wants to merge 4 commits intomainfrom
codex/openai2-client-compat
Open

feat: support OpenAI 2 in Python client#806
scale-ballen wants to merge 4 commits intomainfrom
codex/openai2-client-compat

Conversation

@scale-ballen
Copy link
Copy Markdown
Contributor

@scale-ballen scale-ballen commented Apr 13, 2026

Summary

  • update the Python client to require Python 3.9+ and pin openai==2.8.0
  • regenerate the Poetry lockfile for the new dependency set
  • fix generated OpenAI Pydantic schemas so the client imports cleanly under the upgraded stack

What changed

  • clients/python/pyproject.toml
    • python: ^3.8 -> >=3.9,<4.0
    • openai: ^1.30.0 -> ==2.8.0
  • clients/python/setup.py
    • python_requires: >=3.8 -> >=3.9
  • clients/python/poetry.lock
    • relocked against openai 2.8.0
  • clients/python/llmengine/data_types/gen/openai.py
    • remove invalid min_items constraints from __root__ fields on Prompt1Item, Input2Item, QueryItem, and SearchQueryItem
    • remove the discriminator from InputItem's root union field

Why

egp-api-backend needs litellm==1.83.0, which in turn requires openai 2.x. The local blocker was this Python client package still constraining openai to 1.x. After widening the client dependency, the generated schema layer also needed cleanup before the package would import successfully.

Verification

  • PYENV_VERSION=3.11.14 poetry install
  • PYENV_VERSION=3.11.14 poetry run python -c "import llmengine; from llmengine import Completion, Model, FineTune; from llmengine.api_engine import APIEngine; print("ok")"
    • passed
  • import smoke confirmed Completion, Model, FineTune, and APIEngine import cleanly with the upgraded dependency set

Notes

  • This PR is intentionally limited to the Python client package.
  • I did not change the generated client surface beyond the schema fixes required to restore importability under the upgraded dependency stack.

Greptile Summary

This PR upgrades the Python client to require Python 3.9+ and widens the openai dependency to >=2.8.0,<3.0.0 (from ^1.30.0), then fixes the generated Pydantic schema layer so imports succeed under the new dependency set.

The openai constraint is now a proper range (addressing the prior exact-pin concern), version files are consistent, and the schema fixes are well-reasoned. The min_items removal on str-typed __root__ fields (QueryItem, SearchQueryItem) is correct since min_items never applied to non-list types; if non-empty string validation is desired, min_length=1 would be the right replacement.

Confidence Score: 5/5

Safe to merge; all P0/P1 concerns from prior review are resolved and the single remaining finding is a minor semantic gap on string validation.

The exact-version pin concern was addressed with a proper range constraint. The discriminator removal includes an explanatory comment. The min_items→validator migration is correct for list fields. The only remaining observation (missing min_length on str root fields) is a P2 improvement, not a blocking defect.

clients/python/llmengine/data_types/gen/openai.py — QueryItem and SearchQueryItem str fields had invalid min_items removed without a min_length replacement.

Important Files Changed

Filename Overview
clients/python/llmengine/data_types/gen/openai.py Adds validator import; moves min_items enforcement from Field() to @validator for Prompt1Item/Input2Item; removes invalid min_items from str root fields; removes broken discriminator from InputItem with explanatory comment
clients/python/pyproject.toml Python bumped to >=3.9, openai widened to >=2.8.0,<3.0.0 (range constraint, addressing prior review concern)
clients/python/setup.py python_requires bumped from >=3.8 to >=3.9 to match pyproject.toml
clients/python/poetry.lock Lockfile regenerated for openai 2.8.0 and Python >=3.9

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[openai.py import] --> B{PYDANTIC_V2?}
    B -- Yes --> C[from pydantic.v1 import BaseModel, Field, validator]
    B -- No --> D[from pydantic import BaseModel, Field, validator]
    C --> E[Schema models loaded]
    D --> E
    E --> F[Prompt1Item / Input2Item]
    F --> G["@validator('__root__')\ncheck len >= 1"]
    E --> H[QueryItem / SearchQueryItem]
    H --> I["__root__: str\n(min_items removed)"]
    E --> J[InputItem]
    J --> K["Union[EasyInputMessage, Item, ItemReferenceParam]\n(plain union, no discriminator)"]
Loading

Fix All in Cursor Fix All in Claude Code

Prompt To Fix All With AI
This is a comment left during a code review.
Path: clients/python/llmengine/data_types/gen/openai.py
Line: 6889-6890

Comment:
**`min_items` removal loses non-empty guarantee on `str` root fields**

`QueryItem.__root__` wraps a single `str`, so removing `min_items=1` is correct — it was always a no-op/invalid constraint on a non-list type. However, if the intent was to ensure a non-empty string, that guarantee is now fully absent. Consider adding `min_length=1` to preserve the semantic meaning:

```suggestion
    __root__: Annotated[str, Field(description="A list of queries to search for.", min_length=1)]
```

The same applies to `SearchQueryItem` at line 6952.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (4): Last reviewed commit: "Merge branch 'main' into codex/openai2-c..." | Re-trigger Greptile

Comment thread clients/python/pyproject.toml Outdated
Comment thread clients/python/llmengine/data_types/gen/openai.py
@socket-security
Copy link
Copy Markdown

socket-security bot commented Apr 13, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedopenai@​1.41.1 ⏵ 2.8.096100100100100
Updatedjiter@​0.5.0 ⏵ 0.14.0100 +1100100100100

View full report

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 this pull request may close these issues.

2 participants