Skip to content

fix(BA-1380): Update Service.create() to comply with validation schema #4449

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

Merged
merged 8 commits into from
May 23, 2025

Conversation

rapsealk
Copy link
Member

resolves #4417 (BA-1380)

This pull request updates the client SDK to align method signatures with the NewServiceRequestModel schema and introduces non-optional parameters for resource and configuration details in service-related methods. These changes ensure stricter compliance with expected input requirements and improve the clarity and reliability of the SDK.

SDK Method Signature Updates:

  • changes/.fix.md: Updated documentation to reflect that the Service.create() method signature now complies with the NewServiceRequestModel schema.

Parameter Adjustments in Service Methods:

  • src/ai/backend/client/func/service.py:
    • create: Made resources, resource_opts, domain_name, group_name, and scaling_group required positional parameters. Changed expose_to_public from an implicit boolean to an explicitly typed bool. [1] [2]
    • try_start: Applied the same parameter changes as in create, ensuring consistency across service-related methods.

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)

@rapsealk rapsealk added this to the 25.6 milestone May 21, 2025
@github-actions github-actions bot added size:S 10~30 LoC comp:client Related to Client component labels May 21, 2025
.fix.md -> 4449.fix.md

Co-authored-by: octodog <mu001@lablup.com>
Copy link
Contributor

@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 aligns the Service.create() and Service.try_start() client SDK methods with the NewServiceRequestModel schema by making key resource and configuration parameters required and enforcing explicit typing.

  • Adjusted method signatures for create and try_start to require resources, resource_opts, domain_name, group_name, scaling_group as positional-only, and changed expose_to_public to be explicitly bool.
  • Added a changelog entry for the Service.create() signature change.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/ai/backend/client/func/service.py Updated create and try_start signatures to match the new request model parameters
changes/.fix.md Added entry noting the Service.create() signature update
Comments suppressed due to low confidence (4)

src/ai/backend/client/func/service.py:118

  • The docstring for create doesn't list the newly added parameters (resources, resource_opts, domain_name, group_name, scaling_group, and updated expose_to_public). Please update it to reflect the signature change.
"""

src/ai/backend/client/func/service.py:244

  • The docstring for try_start is missing descriptions for the new required parameters; please add entries for each to match the updated signature.
Tries to start an inference session and terminates immediately.

src/ai/backend/client/func/service.py:93

  • New required parameters (resources, resource_opts, etc.) lack test coverage. Please add or update tests in ai.backend.test to validate these parameters for both create and try_start.
resources: Mapping[str, str | int],

src/ai/backend/client/func/service.py:92

  • [nitpick] These five parameters are enforced as positional-only, which may decrease readability for SDK consumers. Consider making them keyword-only to improve clarity.
/,

changes/.fix.md Outdated
@@ -0,0 +1 @@
Fixed client SDK method `Service.create()` signature to comply with `NewServiceRequestModel` schema
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

Update this changelog entry to also mention the try_start signature changes for full coverage.

Suggested change
Fixed client SDK method `Service.create()` signature to comply with `NewServiceRequestModel` schema
Fixed client SDK method `Service.create()` signature to comply with `NewServiceRequestModel` schema.
Updated `try_start` method signature to align with the latest `TryStartRequestModel` schema.

Copilot uses AI. Check for mistakes.

@rapsealk rapsealk changed the title fix(BA-1380): Update Service.create() signature in client SDK to comply with NewServiceRequestModel schema fix(BA-1380): Update Service.create() to comply with validation schema May 21, 2025
Comment on lines 92 to 97
/,
resources: Mapping[str, str | int],
resource_opts: Mapping[str, str | int],
domain_name: str,
group_name: str,
scaling_group: str,
Copy link
Collaborator

Choose a reason for hiding this comment

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

/ is required?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not mandatory.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then we just change the position and take it as a keyword argument as before.

Comment on lines -102 to -115
resources: Optional[Mapping[str, str | int]] = None,
resource_opts: Optional[Mapping[str, str | int]] = None,
cluster_size: int = 1,
cluster_mode: Literal["single-node", "multi-node"] = "single-node",
domain_name: Optional[str] = None,
group_name: Optional[str] = None,
bootstrap_script: Optional[str] = None,
tag: Optional[str] = None,
architecture: Optional[str] = DEFAULT_IMAGE_ARCH,
scaling_group: Optional[str] = None,
owner_access_key: Optional[str] = None,
model_definition_path: Optional[str] = None,
expose_to_public=False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it guaranteed that the arguments will come from the part?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would have never worked and raised exceptions without explicit setting arguments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked. the arguments are being passed using dictionary.
that part seems fine. 👍

@rapsealk rapsealk requested a review from Copilot May 22, 2025 07:27
Copy link
Contributor

@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

Aligns the client SDK’s Service.create() and Service.try_start() methods with the NewServiceRequestModel schema by making several parameters required and explicitly typing a boolean flag.

  • Made resources, resource_opts, domain_name, group_name, and scaling_group required positional parameters
  • Changed expose_to_public to an explicitly typed bool
  • Added a change log entry reflecting the updated Service.create() signature

Reviewed Changes

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

File Description
src/ai/backend/client/func/service.py Updated create and try_start signatures to enforce required parameters and typed boolean flag
changes/4449.fix.md Added note about Service.create() signature fix
Comments suppressed due to low confidence (4)

src/ai/backend/client/func/service.py:116

  • The docstring for create() doesn’t list the newly required parameters (resources, resource_opts, domain_name, group_name, scaling_group). Please update it to describe each parameter and its type.
"""

src/ai/backend/client/func/service.py:102

  • The signature now enforces resources and other parameters as required; please add or update tests in ai.backend.test to cover valid calls and error cases when these parameters are omitted.
resources: Mapping[str, str | int],

src/ai/backend/client/func/service.py:99

  • Making parameters previously optional now required is a breaking change. Consider documenting this in the release notes and bumping the major version to signal the API change.
async def create(

changes/4449.fix.md:1

+Fixed client SDK method `Service.create()` signature to comply with `NewServiceRequestModel` schema

Comment on lines 102 to 111
resources: Mapping[str, str | int],
resource_opts: Mapping[str, str | int],
cluster_size: int = 1,
cluster_mode: Literal["single-node", "multi-node"] = "single-node",
domain_name: Optional[str] = None,
group_name: Optional[str] = None,
domain_name: str,
group_name: str,
bootstrap_script: Optional[str] = None,
tag: Optional[str] = None,
architecture: Optional[str] = DEFAULT_IMAGE_ARCH,
scaling_group: Optional[str] = None,
scaling_group: str,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn’t it the case that once a parameter is given a default value, all following parameters must also have default values? @rapsealk

Copy link
Member Author

Choose a reason for hiding this comment

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

Any parameter defined after * must be specified using its name (i.e., as a keyword argument). The order of these keyword-only arguments in a function call doesn't matter, since they can't be passed positionally.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn’t it be better to place keyword-only arguments without default values first for better readability and clarity. @rapsealk

@rapsealk rapsealk requested a review from HyeockJinKim May 23, 2025 04:12
@HyeockJinKim HyeockJinKim added this pull request to the merge queue May 23, 2025
Merged via the queue into main with commit 5e28341 May 23, 2025
26 checks passed
@HyeockJinKim HyeockJinKim deleted the fix/BA-1380-client-sdk-service-create-params branch May 23, 2025 06:51
lablup-octodog added a commit that referenced this pull request May 23, 2025
…ema (#4449)

Co-authored-by: octodog <mu001@lablup.com>
Backported-from: main (25.8)
Backported-to: 25.6
Backport-of: 4449
github-merge-queue bot pushed a commit that referenced this pull request May 23, 2025
…ema (#4449) (#4484)

Co-authored-by: Jeongseok Kang <jskang@lablup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:client Related to Client component size:S 10~30 LoC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent handling of nullable value for group_name in service creation API
2 participants