reorganize the model resolver and add openai compatible route for oth… - #143
reorganize the model resolver and add openai compatible route for oth…#143weilixu wants to merge 3 commits into
Conversation
…er LLM providers.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c1632a938
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| api_version: str | None = None | ||
| max_retries: int | None = None | ||
| model_kwargs: dict[str, Any] | None = None | ||
| default_headers: dict[str, str] | None = None |
There was a problem hiding this comment.
Resolve Authorization placeholders in default_headers
When a YAML spec supplies an OpenAI-compatible token as default_headers.Authorization: Bearer ${PROVIDER_TOKEN}, this new field is accepted but _resolve_env_placeholders() only resolves values whose final key is secret-like, so Authorization remains literal; _extract_bearer_token() then treats ${PROVIDER_TOKEN} as a real key and the request is sent with the placeholder instead of failing fast or using the environment value. Please include Authorization/default_headers in the secret-placeholder resolution path or document that only api_key supports env placeholders.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR reorganizes chat model resolution into a dedicated automa_ai.models module and adds an openai-compatible model provider option (including YAML spec + docs + tests) to support OpenAI chat-completions–compatible endpoints.
Changes:
- Introduces
automa_ai/models/chat.pyand routesAgentFactorythrough it for chat model resolution. - Adds
GenericLLM.OPENAI_COMPATIBLEplus YAML spec fields formodel_kwargs,default_headers, andextra_body. - Extends documentation and tests to cover OpenAI-compatible provider mapping and behavior.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Bumps the project version in the lockfile. |
| automa_ai/agents/init.py | Adds GenericLLM.OPENAI_COMPATIBLE enum value. |
| automa_ai/agents/agent_factory.py | Removes inline resolver and delegates model resolution to automa_ai.models.chat.resolve_chat_model; threads new model options through the factory. |
| automa_ai/models/chat.py | New centralized chat-model resolver, including OpenAI-compatible routing and lazy provider imports. |
| automa_ai/models/init.py | Exposes resolve_chat_model from the new models package. |
| automa_ai/config/agent_spec.py | Extends YAML model spec surface with model_kwargs, default_headers, and extra_body and maps them into factory kwargs. |
| docs/yaml_agent_spec.md | Documents openai-compatible provider plus additional model configuration fields. |
| tests/test_yaml_agent_spec.py | Adds coverage for YAML mapping of OpenAI-compatible model options. |
| tests/test_agent_factory_openai_env.py | Updates tests to target the new resolver module and adds OpenAI-compatible resolver behavior tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Backward compatibility for older calls shaped as: | ||
| # resolve_chat_model(backend, model_name, base_url) | ||
| if isinstance(agent_type, str) and base_url is None: | ||
| base_url = agent_type | ||
| agent_type = None | ||
|
|
| if backend == GenericLLM.OPENAI: | ||
| return _resolve_openai_chat_model( | ||
| model_name=model_name, | ||
| agent_type=agent_type, | ||
| base_url=base_url, | ||
| api_key=api_key, | ||
| api_version=api_version, | ||
| default_headers=default_headers, | ||
| ) |
| assert resolved_api_key, ( | ||
| "You must provide an API key (api_key), an Authorization bearer token, " | ||
| "or OPENAI_API_KEY in the environment to access OpenAI GPT models" | ||
| ) |
| assert resolved_api_key, ( | ||
| "You must provide an API key to access OpenAI-compatible models. " | ||
| "Checked explicit api_key, Authorization bearer token, plus env vars: " | ||
| f"{', '.join(OPENAI_COMPATIBLE_API_KEY_ENV_VARS)}" | ||
| ) |
| ) | ||
| if backend == GenericLLM.CLAUDE: | ||
| ChatAnthropic = _load_anthropic_chat_model() | ||
| assert api_key, "You must provide an API key to access Anthropic Claude model" |
| assert os.getenv( | ||
| "GOOGLE_API_KEY" | ||
| ), "You must add GOOGLE_API_KEY in the system environment." |
reorganize the model resolver and add openai compatible route for other LLM providers.