Skip to content

feat: openapi refactor#1562

Merged
SAKURA-CAT merged 52 commits intomainfrom
feat/open-api-cli
Apr 28, 2026
Merged

feat: openapi refactor#1562
SAKURA-CAT merged 52 commits intomainfrom
feat/open-api-cli

Conversation

@Nexisato
Copy link
Copy Markdown
Contributor

Description

#1547 拆分

  • SwanLab OpenAPI 接入
  • 支持通过 swanlab api [project/run/..]SwanLab.Api() 双格式调用

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive API client layer and a corresponding CLI interface for SwanLab. It includes a base entity class for handling HTTP requests safely, a set of type definitions for various API resources (experiments, projects, users, etc.), and utility functions for data transformation. The CLI is expanded with an api command group to allow direct interaction with these resources. Feedback focuses on correcting typos in type definitions and file headers, ensuring all CLI subcommands are properly imported and registered, and removing redundant logic in the API response handling.

Comment thread swanlab/api/typings/user.py Outdated
Comment thread swanlab/api/typings/selfhosted.py
Comment thread swanlab/cli/api/__init__.py
Comment thread swanlab/cli/api/__init__.py
Comment thread swanlab/api/typings/common.py Outdated
@Nexisato Nexisato force-pushed the feat/open-api-cli branch from 95c68d7 to 4806400 Compare April 22, 2026 02:52
@Nexisato Nexisato self-assigned this Apr 22, 2026
@Nexisato Nexisato added the 💪 enhancement New feature or request label Apr 23, 2026
@Nexisato
Copy link
Copy Markdown
Contributor Author

Nexisato commented Apr 24, 2026

#1571

  • filter JSON DSL 对用户而言存在一定的上手门槛,此分支以外考虑加一个支持运算符重载的 pr (但是在 cli 模式下需要兼容两种查询语言,待定
    Usage::

        from swanlab.api import FilterOperation as FOP

        runs = project.runs(filters=[
            FOP.state == "FINISHED",
            FOP.createdAt >= "2025-03-25",
            FOP.createdAt <= datetime(2025, 3, 25, 23, 59, 59),
            FOP("lr", type="CONFIG") >= 0.1,
            FOP.state.in_("RUNNING", "FINISHED"),
        ])

    Attribute access (``F.state``) auto-detects STABLE keys.
    For CONFIG / SCALAR fields use call syntax: ``F("key", type="CONFIG")``.

或者按照原本的运算符扩展

@Nexisato Nexisato force-pushed the feat/open-api-cli branch from ca80b03 to d9c4472 Compare April 24, 2026 15:42
SAKURA-CAT
SAKURA-CAT previously approved these changes Apr 27, 2026
@Nexisato Nexisato changed the title feat: openapi cli feat: openapi refactor Apr 27, 2026
@Nexisato
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive Object-Oriented API layer and corresponding CLI subcommands for querying SwanLab entities such as projects, experiments, and metrics. The implementation includes robust validation logic, safe HTTP request handling, and extensive unit tests. Feedback focuses on optimizing performance by reducing redundant API calls in entity data loading and metric fetching, correcting a typo in a utility function name, and improving the library's logging and pagination behavior to ensure a better user experience.

Comment thread swanlab/api/column.py Outdated
Comment thread swanlab/api/utils.py Outdated
Comment thread swanlab/api/metric.py
Comment thread swanlab/api/metric.py
Comment thread swanlab/api/base.py
@Nexisato
Copy link
Copy Markdown
Contributor Author

/gemini review

1 similar comment
@Nexisato
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a new OOP-based public API package and corresponding CLI commands for SwanLab, enabling users to interact with workspaces, projects, experiments, and metrics. The architecture utilizes a base entity class to provide safe HTTP requests and lazy data loading. Key feedback includes addressing performance bottlenecks caused by hardcoded sleep intervals in pagination and sequential network requests for CSV exports. Additionally, the property extraction utility needs refinement to correctly handle nested containers and non-builtin types for reliable JSON serialization.

Comment thread swanlab/api/base.py
Comment thread swanlab/api/utils.py
Comment thread swanlab/api/metric.py
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive Object-Oriented API layer and corresponding CLI commands for querying SwanLab data, including workspaces, projects, experiments, columns, and metrics. The implementation features a base entity class with safe HTTP request handling, detailed type definitions, and unit tests. Review feedback identifies several logic and performance issues: the hardcoded sleep in the pagination logic should be made configurable to avoid efficiency bottlenecks, a logic error in the Column.metric method where the metric_type parameter is overwritten needs to be addressed, the sample parameter is currently not being included in the scalar metric request payloads, and the recursive property extraction utility requires enhancement to correctly handle container types and common non-builtin objects like datetimes.

Comment thread swanlab/api/base.py
Comment thread swanlab/api/column.py Outdated
Comment thread swanlab/api/metric.py Outdated
Comment thread swanlab/api/utils.py
@Nexisato
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive OOP-style public API and CLI for SwanLab, enabling programmatic access to workspaces, projects, experiments, and metrics. While the implementation provides a structured interface for data retrieval, the review identifies several critical areas for improvement regarding robustness and performance. Specifically, the pagination logic silently terminates on errors, hardcoded delays unnecessarily slow down large data fetches, and failed requests are permanently cached as empty data states. Additionally, the reviewer recommended using key-based mapping for metric data to avoid order-dependency and suggested a more robust serialization approach for complex nested properties.

Comment thread swanlab/api/base.py
Comment thread swanlab/api/base.py
Comment thread swanlab/api/experiment.py
Comment thread swanlab/api/metric.py
Comment thread swanlab/api/utils.py
@Nexisato Nexisato requested a review from SAKURA-CAT April 28, 2026 06:17
@SAKURA-CAT SAKURA-CAT merged commit a457f47 into main Apr 28, 2026
18 checks passed
@SAKURA-CAT SAKURA-CAT deleted the feat/open-api-cli branch April 28, 2026 06:30
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.

3 participants