fix(server): make openai an optional server-only dependency#1623
Merged
fix(server): make openai an optional server-only dependency#1623
Conversation
Contributor
Greptile OverviewGreptile SummaryThis PR makes
This improves the user experience by allowing users to install a lighter version of the package when they don't need server functionality, while providing clear guidance when the server dependencies are missing.
|
| Filename | Overview |
|---|---|
| pyproject.toml | Correctly marks openai as optional dependency, already included in server extras group |
| poetry.lock | Transitive dependencies (distro, jiter) of openai automatically marked optional, content hash updated |
| nemoguardrails/cli/init.py | Added proper ImportError handling with helpful error message when openai is missing |
| .github/workflows/test-and-build-wheel.yml | Updated CI to install wheel with [server] extra since test starts a server |
Sequence Diagram
sequenceDiagram
participant User
participant CLI as nemoguardrails CLI
participant PyProject as pyproject.toml
participant Server as nemoguardrails.server.api
participant OpenAI as openai package
Note over User,OpenAI: Without [server] extra installed
User->>CLI: nemoguardrails server
CLI->>Server: try: from nemoguardrails.server import api
Server->>OpenAI: import openai
OpenAI-->>Server: ImportError (not installed)
Server-->>CLI: ImportError
CLI->>User: Error: "openai package required. Install with: pip install nemoguardrails[server]"
CLI->>User: Exit(1)
Note over User,OpenAI: With [server] extra installed
User->>CLI: pip install nemoguardrails[server]
CLI->>PyProject: Read extras dependencies
PyProject->>CLI: Install: aiofiles, openai
User->>CLI: nemoguardrails server
CLI->>Server: try: from nemoguardrails.server import api
Server->>OpenAI: import openai
OpenAI-->>Server: Success
Server-->>CLI: Success
CLI->>User: Server starts successfully
60939e2 to
d1522de
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Prevents test collection errors when openai is not installed by adding pytest.importorskip guards to server test files and including openai in the dev dependency group
36ccaa3 to
8366e91
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Resolves some minor issues due to #1340 that causes a job failure.
openaias an optional dependency inpyproject.toml(already included in theserverextras group)[server]extra in the CI test-wheel job since it starts a serveropenaiis missingopenaito dev dependencies so server tests pass locally (consistent withyara-python,opentelemetry-api, etc.)pytest.importorskip("openai")guards to all server test files as a defensive measure