-
Notifications
You must be signed in to change notification settings - Fork 1
feat: configurable examples #132
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughA centralized examples system was introduced using new Pydantic models and a configuration-backed loader, enabling dynamic example data for both frontend and API documentation. The Changes
Sequence Diagram(s)sequenceDiagram
participant Frontend
participant Examples
participant API_Docs
Frontend->>Examples: Load example data (get_examples)
API_Docs->>Examples: Load example data (get_examples)
Examples-->>Frontend: Provide example inputs/outputs
Examples-->>API_Docs: Provide example inputs/outputs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
gliner_api/frontend.py (1)
127-131
: Consider simplifying the complex boolean mapping logic.The current logic for mapping boolean flags to option strings is complex and hard to read. Consider extracting this into a helper function.
+def get_checkbox_options(flat_ner: bool, multi_label: bool) -> list[str]: + """Convert boolean flags to checkbox option strings.""" + options = [] + if not flat_ner: + options.append("deep_ner") + if multi_label: + options.append("multi_label") + return options + gr.CheckboxGroup( label="Additional Options (Advanced)", choices=[ ("Enable deep NER mode", "deep_ner"), ("Enable multi-label classification", "multi_label"), ], - value=[ - value - for option, value in zip([not examples.invoke[0].flat_ner, examples.invoke[0].multi_label], ["deep_ner", "multi_label"]) - if option - ], + value=get_checkbox_options(examples.invoke[0].flat_ner, examples.invoke[0].multi_label),gliner_api/examples.py (1)
15-15
: Consider potential circular dependency issue.The examples module imports
get_config()
at module level, while config.py might reference examples in validation. This could create circular import issues.Consider lazy loading the config:
-config: Config = get_config() class InvokeExample(BaseSettings): text: str - threshold: float = Field(ge=0.0, le=1.0, default=config.default_threshold) - entity_types: list[str] = Field(default=config.default_entities) + threshold: float = Field(ge=0.0, le=1.0, default_factory=lambda: get_config().default_threshold) + entity_types: list[str] = Field(default_factory=lambda: get_config().default_entities)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
gliner_api/__init__.py
(1 hunks)gliner_api/backend.py
(1 hunks)gliner_api/datamodel.py
(2 hunks)gliner_api/examples.py
(1 hunks)gliner_api/frontend.py
(4 hunks)gliner_api/helpers.py
(0 hunks)
💤 Files with no reviewable changes (1)
- gliner_api/helpers.py
🧰 Additional context used
🧠 Learnings (2)
gliner_api/backend.py (1)
Learnt from: freinold
PR: freinold/GLiNER-API#86
File: gliner_api/frontend.py:13-13
Timestamp: 2025-07-07T10:44:27.531Z
Learning: In the GLiNER-API project, the frontend and backend are always run on the same machine, with the frontend bound to the same FastAPI backend in main.py. This architectural constraint makes hardcoded localhost connections appropriate and eliminates the need for host configurability in the frontend client.
gliner_api/frontend.py (1)
Learnt from: freinold
PR: freinold/GLiNER-API#86
File: gliner_api/frontend.py:13-13
Timestamp: 2025-07-07T10:44:27.531Z
Learning: In the GLiNER-API project, the frontend and backend are always run on the same machine, with the frontend bound to the same FastAPI backend in main.py. This architectural constraint makes hardcoded localhost connections appropriate and eliminates the need for host configurability in the frontend client.
🧬 Code Graph Analysis (3)
gliner_api/backend.py (1)
gliner_api/__init__.py (1)
Entity
(4-24)
gliner_api/frontend.py (3)
gliner_api/examples.py (2)
Examples
(18-83)get_examples
(105-107)gliner_api/config.py (2)
Config
(8-110)get_config
(114-116)gliner_api/backend.py (2)
invoke
(115-155)info
(215-225)
gliner_api/datamodel.py (3)
gliner_api/__init__.py (1)
Entity
(4-24)gliner_api/config.py (2)
Config
(8-110)get_config
(114-116)gliner_api/examples.py (2)
Examples
(18-83)get_examples
(105-107)
🔇 Additional comments (7)
gliner_api/__init__.py (1)
4-24
: LGTM! Well-structured Entity model with proper validation.The Entity model is well-designed with appropriate field constraints, clear descriptions, and flexible type/label aliasing. Moving it to
__init__.py
makes it easily accessible across the codebase.gliner_api/backend.py (1)
13-13
: LGTM! Import correctly updated for Entity model relocation.The import statement properly reflects the new location of the Entity model in
gliner_api/__init__.py
.gliner_api/frontend.py (1)
10-13
: LGTM! Good integration with the new examples system.The frontend properly integrates with the centralized examples system, making the UI dynamic and configurable.
gliner_api/examples.py (1)
1-16
: LGTM! Well-structured examples module with proper configuration support.The module provides a clean way to centralize and configure example data. The use of BaseSettings with file support is excellent for maintainability.
gliner_api/datamodel.py (3)
1-8
: LGTM! Clean refactoring to use centralized examples system.The import updates and dynamic examples usage properly integrate with the new examples module, eliminating hardcoded example data.
56-56
: LGTM! Good addition of validation constraint.Adding
min_length=1
toBatchRequest.texts
ensures that batch requests contain at least one text, which is a sensible validation.
126-127
: LGTM! Proper TypeAdapter syntax with keyword arguments.The update to use
type=
keyword arguments in TypeAdapter instantiation follows best practices and improves code clarity.
Entity(start=0, end=10, text="Steve Jobs", type="person", score=0.99), | ||
Entity(start=19, end=24, text="Apple", type="organization", score=0.98), | ||
Entity(start=28, end=37, text="Cupertino", type="location", score=0.98), | ||
Entity(start=39, end=49, text="California", type="location", score=0.99), | ||
Entity(start=53, end=66, text="April 1, 1976", type="date", score=0.68), |
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.
💡 Verification agent
🧩 Analysis chain
Verify entity start/end indices are accurate.
Please double-check that the entity boundaries are correct. For example:
- "Steve Jobs" (0-10): ✓ Correct
- "Apple" (19-24): ✓ Correct
- "Cupertino" (28-37): ✓ Correct
🏁 Script executed:
#!/bin/bash
# Verify entity indices in example text
text="Steve Jobs founded Apple Inc. in Cupertino, CA on April 1, 1976."
echo "Text: $text"
echo "Length: ${#text}"
echo ""
echo "Entity extractions:"
echo "0-10: '${text:0:10}'"
echo "19-24: '${text:19:5}'"
echo "28-37: '${text:28:9}'"
echo "39-49: '${text:39:10}'"
echo "53-66: '${text:53:13}'"
Length of output: 578
Update entity indices to match the actual example text
After verifying the string
Steve Jobs founded Apple Inc. in Cupertino, CA on April 1, 1976.
the spans for “Cupertino”, “CA”/“California” and the date are off. Please correct lines 24–28 in gliner_api/examples.py
:
- Cupertino is at indices 33–42, not 28–37
- The text contains “CA” at 44–46 (or change the example to “California” if you want that full name)
- “April 1, 1976” spans 50–63, not 53–66
- Entity(start=28, end=37, text="Cupertino", type="location", score=0.98),
- Entity(start=39, end=49, text="California", type="location", score=0.99),
- Entity(start=53, end=66, text="April 1, 1976", type="date", score=0.68),
+ Entity(start=33, end=42, text="Cupertino", type="location", score=0.98),
+ Entity(start=44, end=46, text="CA", type="location", score=0.99),
+ Entity(start=50, end=63, text="April 1, 1976", type="date", score=0.68),
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Entity(start=0, end=10, text="Steve Jobs", type="person", score=0.99), | |
Entity(start=19, end=24, text="Apple", type="organization", score=0.98), | |
Entity(start=28, end=37, text="Cupertino", type="location", score=0.98), | |
Entity(start=39, end=49, text="California", type="location", score=0.99), | |
Entity(start=53, end=66, text="April 1, 1976", type="date", score=0.68), | |
Entity(start=0, end=10, text="Steve Jobs", type="person", score=0.99), | |
Entity(start=19, end=24, text="Apple", type="organization", score=0.98), | |
Entity(start=33, end=42, text="Cupertino", type="location", score=0.98), | |
Entity(start=44, end=46, text="CA", type="location", score=0.99), | |
Entity(start=50, end=63, text="April 1, 1976", type="date", score=0.68), |
🤖 Prompt for AI Agents
In gliner_api/examples.py around lines 24 to 28, the entity span indices for
"Cupertino", "CA"/"California", and "April 1, 1976" do not match the actual
example text. Update the start and end indices for "Cupertino" to 33–42, add or
adjust the entity for "CA" at 44–46 (or replace with "California" if preferred),
and correct the date span to 50–63 to align with the string "Steve Jobs founded
Apple Inc. in Cupertino, CA on April 1, 1976."
Closes #122
Summary by CodeRabbit
New Features
Improvements
Removals