Repository navigation
Conversation
Signed-off-by: domondi1 <91575411+domondi1@users.noreply.github.com>
|
No linked issues found. Please link an issue in your pull request description or title. Per our Contributing Guidelines, all PRs must:
You can also use cross-repo references like |
|
Your branch is 1 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 9 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
BichengWang
left a comment
There was a problem hiding this comment.
Reviewed head 24322b1c73fcee548fe660523e3deb8a5dba59d4.
[P2] Preserve the existing positional constructor arguments when adding default_headers (signature). Inserting it before openai_schema shifts every existing positional argument from the fifth onward. For example, this previously valid call now raises TypeError: 'OpenAISchema' object is not iterable at dict(default_headers), before client creation:
from unittest import mock
from langextract.providers.openai import OpenAILanguageModel
from langextract.providers.schemas.openai import OpenAISchema
schema = OpenAISchema({"type": "object", "properties": {}})
with mock.patch("openai.OpenAI"):
model = OpenAILanguageModel("gpt-4o-mini", "test-key", None, None, schema)
assert model.openai_schema is schemaPlease place the new argument after the existing max_workers parameter (optionally making only the new argument keyword-only), and add a regression test for the old positional signature. I checked both the fifth-position schema and the full eight-position constructor on the PR parent 62b933a2c757fd2bbb100498571b8d1692db4344; both pass there. Moving the new argument after max_workers in memory restores both at this head.
Validation at the exact PR head: Python 3.11.17, OpenAI SDK 3.31.0; 878 passed, 24 deselected with python -m pytest tests -m "not live_api and not requires_pip and not integration". Full source/test isort, Pyink, Pylint (using the separate source/test configs), and all three import contracts passed. Dependencies were installed from the local cache; dotenv loading was disabled and provider credentials removed for the suite. No live APIs, pip-install integration, other Python versions, or merge with current main were tested.
|
Your branch is 14 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
1 similar comment
|
Your branch is 14 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 17 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 27 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
1 similar comment
|
Your branch is 27 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
Description
OpenAILanguageModelbuilds itsopenai.OpenAIclient fromapi_key,base_urlandorganizationonly, and extra kwargs go to the Chat Completions call, so there's no way to send HTTP headers with every request (needed by many OpenAI-compatible proxies and gateways). This adds an optionaldefault_headersargument that is passed to the client, reachable vialanguage_model_params:Noneby default, so nothing changes for existing users. Headers go toopenai.OpenAI(default_headers=...), not into the request params.Fixes #549
Feature
How Has This Been Tested?
New tests in
tests/inference_test.py: headers reach the client and not the API params; unset by default. Also checked thatfactory.create_modelwithprovider_kwargs={"default_headers": ...}reaches the client.Note on CI:
lint-testscurrently reports W0223 (abstract-method) intests/schema_test.py, a file this PR doesn't touch; the same warnings appear onmainwith the current pylint/astroid, so it looks like a tool version change rather than this diff.Checklist:
Code of conduct.
Contributing
page, and I either signed the Google
Individual CLA
or am covered by my company's
Corporate CLA.
issue(s) and we have agreed upon the general approach.
issue(s) that documentation elsewhere needs updating.
Google's Python Style Guide
and ran
pylintover the affected code.Disclosure: I maintain Inferrail, an open-source OpenAI-compatible gateway that uses such headers for per-job cost limits; the change itself is generic.