-
Couldn't load subscription status.
- Fork 18
RHOAIENG-28843: Package huggingface detector #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RHOAIENG-28843: Package huggingface detector #41
Conversation
Reviewer's GuideThis PR restructures the repository into a standardized Python package under src/guardrails_detectors, configures packaging with pyproject.toml and hatchling, updates CI workflows for Docker and PyPI publishing, and adjusts imports, documentation, and tests to the new module layout. Class diagram for updated detector registry structureclassDiagram
class BaseDetectorRegistry {
+__init__()
<<abstract>>
}
class RegexDetectorRegistry {
+__init__()
}
class FileTypeDetectorRegistry {
+__init__()
}
BaseDetectorRegistry <|-- RegexDetectorRegistry
BaseDetectorRegistry <|-- FileTypeDetectorRegistry
Class diagram for updated FastAPI app structure in built_inclassDiagram
class FastAPI {
}
class Instrumentator {
}
class ContentAnalysisHttpRequest {
}
class ContentsAnalysisResponse {
}
class BaseDetectorRegistry {
}
class RegexDetectorRegistry {
}
class FileTypeDetectorRegistry {
}
FastAPI --> Instrumentator
FastAPI --> BaseDetectorRegistry
FastAPI --> RegexDetectorRegistry
FastAPI --> FileTypeDetectorRegistry
FastAPI --> ContentAnalysisHttpRequest
FastAPI --> ContentsAnalysisResponse
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @AmberJBlue - I've reviewed your changes - here's some feedback:
- In tests/conftest.py you reference an undefined
src_pathwhen setting up module paths—make sure to definesrc_path(e.g. asos.path.join(project_root, 'src')) or correct the path variable so imports resolve properly. - Update the Docker build context in build-and-push.yaml to match the new package layout (e.g. use
src/guardrails_detectorsas the build context instead of the olddetectorsfolder) to prevent broken builds. - Double-check the package name in your publish-package.yaml (URL and PyPI name) to ensure it matches the hyphenated project name (
guardrails-detectors) defined in pyproject.toml.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In tests/conftest.py you reference an undefined `src_path` when setting up module paths—make sure to define `src_path` (e.g. as `os.path.join(project_root, 'src')`) or correct the path variable so imports resolve properly.
- Update the Docker build context in build-and-push.yaml to match the new package layout (e.g. use `src/guardrails_detectors` as the build context instead of the old `detectors` folder) to prevent broken builds.
- Double-check the package name in your publish-package.yaml (URL and PyPI name) to ensure it matches the hyphenated project name (`guardrails-detectors`) defined in pyproject.toml.
## Individual Comments
### Comment 1
<location> `.github/workflows/build-and-push.yaml:86` </location>
<code_context>
+ echo 'LABEL quay.expires-after=7d#' >> src/guardrails_detectors/Dockerfile.builtIn
- name: Build image
- run: docker build -t ${{ env.IMAGE_NAME }}:$TAG -f detectors/Dockerfile.hf detectors
+ run: docker build -t ${{ env.IMAGE_NAME }}:$TAG -f src/guardrails_detectors/Dockerfile.hf detectors
- name: Log in to Quay
run: docker login -u ${{ secrets.QUAY_ROBOT_USERNAME }} -p ${{ secrets.QUAY_ROBOT_SECRET }} quay.io
</code_context>
<issue_to_address>
Docker build context may be incorrect after directory move.
Update the build context to 'src/guardrails_detectors' to ensure all necessary files are included in the Docker build.
</issue_to_address>
### Comment 2
<location> `.github/workflows/build-and-push.yaml:92` </location>
<code_context>
run: docker push ${{ env.IMAGE_NAME }}:$TAG
- name: Build built-in detector image
- run: docker build -t ${{ env.BUILTIN_IMAGE_NAME }}:$TAG -f detectors/Dockerfile.builtIn detectors
+ run: docker build -t ${{ env.BUILTIN_IMAGE_NAME }}:$TAG -f src/guardrails_detectors/Dockerfile.builtIn detectors
- name: Push to Quay CI repo
run: docker push ${{ env.BUILTIN_IMAGE_NAME }}:$TAG
</code_context>
<issue_to_address>
Potential mismatch between Dockerfile location and build context.
If required files are now in 'src/guardrails_detectors', using 'detectors' as the build context may cause build failures or incomplete images.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| echo 'LABEL quay.expires-after=7d#' >> src/guardrails_detectors/Dockerfile.builtIn | ||
| - name: Build image | ||
| run: docker build -t ${{ env.IMAGE_NAME }}:$TAG -f detectors/Dockerfile.hf detectors | ||
| run: docker build -t ${{ env.IMAGE_NAME }}:$TAG -f src/guardrails_detectors/Dockerfile.hf detectors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Docker build context may be incorrect after directory move.
Update the build context to 'src/guardrails_detectors' to ensure all necessary files are included in the Docker build.
| run: docker push ${{ env.IMAGE_NAME }}:$TAG | ||
| - name: Build built-in detector image | ||
| run: docker build -t ${{ env.BUILTIN_IMAGE_NAME }}:$TAG -f detectors/Dockerfile.builtIn detectors | ||
| run: docker build -t ${{ env.BUILTIN_IMAGE_NAME }}:$TAG -f src/guardrails_detectors/Dockerfile.builtIn detectors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential mismatch between Dockerfile location and build context.
If required files are now in 'src/guardrails_detectors', using 'detectors' as the build context may cause build failures or incomplete images.
Restructure code to follow Red Hat AI Python Packaging Best Practices to make the HuggingFace detector package compliant and prepare for publishing guardrails-detectors
Summary by Sourcery
Restructure the detectors project into a compliant Python package layout, adjust import paths, and add packaging metadata and workflows for publishing to PyPI and building container images.
Enhancements:
Build:
CI:
Documentation:
Tests: