Skip to content

Conversation

@freinold
Copy link
Owner

@freinold freinold commented Jul 20, 2025

Closes #122

Summary by CodeRabbit

  • New Features

    • Centralized and expanded example data for API documentation and frontend, with dynamic loading and structured validation.
    • Introduced a standardized entity data structure for consistent representation of extracted entities.
  • Improvements

    • Example values in API requests, responses, and frontend UI are now dynamically sourced from a centralized example set, ensuring consistency and easier updates.
    • Input constraints improved for batch requests.
  • Removals

    • Removed hardcoded example values and the helper function for merging overlapping entities.

@freinold freinold added this to the v0.3 milestone Jul 20, 2025
@freinold freinold self-assigned this Jul 20, 2025
@freinold freinold added the enhancement New feature or request label Jul 20, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 20, 2025

Walkthrough

A 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 Entity data model was refactored and moved, imports were updated accordingly, and hardcoded example data was replaced with dynamic sources. A legacy helper function was removed.

Changes

File(s) Change Summary
gliner_api/__init__.py Added new Entity Pydantic model with fields for entity extraction results.
gliner_api/datamodel.py Removed local Entity class, imported from gliner_api; switched all example data to use new dynamic Examples class; added min_length constraint to batch texts; updated TypeAdapter usage.
gliner_api/examples.py Introduced new module with Examples, InvokeExample, BatchExample classes, and a function to load and cache example data from config files.
gliner_api/frontend.py Updated to use dynamic examples for UI defaults and example sets, replacing hardcoded literals; added helper to convert boolean flags to checkbox options.
gliner_api/backend.py Updated import of Entity to new location in gliner_api.
gliner_api/helpers.py Deleted file; removed the merge_overlapping_entities function.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

documentation

Poem

A bunny with code on its mind,
Hopped to make examples aligned.
From hardcoded to dynamic,
The docs look less frantic—
Now frontend and docs are entwined!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 268983b and d65ad12.

📒 Files selected for processing (1)
  • gliner_api/frontend.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • gliner_api/frontend.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-configurable-examples

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 97b2f28 and 0b235d9.

📒 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 to BatchRequest.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.

@freinold freinold merged commit e8e3442 into main Jul 25, 2025
7 checks passed
@freinold freinold deleted the feat-configurable-examples branch July 25, 2025 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make frontend and API doc examples configurable

2 participants