Skip to content

Conversation

Kaikaikaifang
Copy link
Member

@Kaikaikaifang Kaikaikaifang commented May 8, 2025

Description

通过 OpenAPI 开放获取实验信息接口。

  1. 该方法所需用户指定的参数有项目名称与实验唯一 cuid (目前 cuid 只能从前端的 url 中拿到)
  2. 该方法输出包含如下参数:
"""
Args:
    project (str): 项目名
    exp_cuid (str): 实验id
    username (Optional[str]): 工作空间名, 默认为用户个人空间

Returns:
dict: 实验信息的字典, 包含以下字段:

    - cuid (str): 实验的唯一标识符
    - name (str): 实验名称
    - description (str): 实验描述
    - state (str): 实验状态, 为 'FINISHED' 或 'RUNNING'
    - createdAt (str): 实验创建时间, 格式如 '2024-11-23T12:28:04.286Z'
    - finishedAt (str): 实验完成时间(若有), 格式如 '2024-11-23T12:28:04.286Z'
    - profile (dict): 实验配置文件, 包含以下字段:

        - config (dict): 实验的配置参数
        - metadata (dict): 实验的元数据
        - requirements (str): 实验的依赖项
        - conda (str): 实验的 Conda 环境信息

若请求失败, 将返回包含以下字段的字典:

    - code (int): HTTP 错误代码
    - message (str): 错误信息
"""

@Kaikaikaifang Kaikaikaifang requested review from kites262 and Copilot May 8, 2025 05:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces the ability to retrieve detailed experiment information via the OpenAPI interface while enhancing the test coverage for workspaces and experiments.

  • Adds a new endpoint (get_experiment) and corresponding tests in both the main API and experiment module.
  • Adjusts type checks for optional values in tests and updates parameter type annotations.
  • Updates the Group API and base API implementations for better response handling and API consistency.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/unit/api/openapi/test_group.py Updated type validation for workspace names
test/unit/api/openapi/test_experiment.py Added tests for fetching experiment details
swanlab/api/openapi/main.py Introduced get_experiment method and adjusted username assignment
swanlab/api/openapi/group.py Refactored list_workspaces to check response type
swanlab/api/openapi/experiment.py Added get_experiment method to extract required fields
swanlab/api/openapi/base.py Modified post method signature

@kites262 kites262 merged commit 4f12c4f into feature/openapis May 8, 2025
5 checks passed
@kites262 kites262 deleted the feature/get-experiment branch May 8, 2025 07:41
SAKURA-CAT added a commit that referenced this pull request May 12, 2025
* feat(openapi): list workspaces (#961)

* feat(openapi): list workspaces

* refa(openapi): login logic

* docs(openapi): revise

* fix(test): no cloud

* feat(openapi): auto catch ApiError

* Add `get_exp_state` for OpenAPI

Add `get_exp_state` for OpenAPI (#963)

---------

Co-authored-by: kites262 <kites262@qq.com>

* feat(openapi): get experiment (#964)

* feature: get experiment
* fix some

* feat(openapi): get project exps

* feat(openapi): types

* fix: py<3.8

* refa(openapi): types for ide

* feat(openapi): list projects (#966)

* feat(openapi): list project

* refactor(openapi): list projects with apiresponse type

* refactor(openapi): rewrite list comprehension

* fix: typo

* refa(openapi): general fetch paginated api

* fix(openapi): test & default value

---------

Co-authored-by: kites262 <kites262@qq.com>

* chore: fix desc & comment

---------

Co-authored-by: hyYY-1024 <75209465+hyYY-1024@users.noreply.github.com>
Co-authored-by: Kaikai <98205900+Kaikaikaifang@users.noreply.github.com>
Co-authored-by: CaddiesNew <50736785+Nexisato@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants