Skip to content

Commit

Permalink
feat(model): add model async trigger (#293)
Browse files Browse the repository at this point in the history
Because

- we are going to support asynchronous call for model trigger

This commit

- add model trigger async methods

---------

Co-authored-by: droplet-bot <[email protected]>
  • Loading branch information
heiruwu and droplet-bot authored Apr 2, 2024
1 parent 3c32980 commit 3dcf05f
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 0 deletions.
52 changes: 52 additions & 0 deletions model/model/v1alpha/model.proto
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,32 @@ message TriggerUserModelResponse {
repeated TaskOutput task_outputs = 2;
}

// TriggerAsyncUserModelRequest represents a request to trigger a model inference
// asynchronously.
message TriggerAsyncUserModelRequest {
// The resource name of the model , which allows its access by parent user
// and ID.
// - Format: `users/{user.id}/models/{model.id}`.
string name = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference).type = "api.instill.tech/Model",
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
field_configuration: {path_param_name: "user_model_name"}
}
];
// Inference input parameters.
repeated TaskInput task_inputs = 2 [(google.api.field_behavior) = REQUIRED];
// Model version tag
string version = 3 [(google.api.field_behavior) = REQUIRED];
}

// TriggerAsyncUserModelResponse contains the information to access the
// status of an asynchronous model inference.
message TriggerAsyncUserModelResponse {
// Long-running operation information.
google.longrunning.Operation operation = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// TriggerUserModelBinaryFileUploadRequest represents a request trigger a model
// inference by uploading a binary file as the input.
message TriggerUserModelBinaryFileUploadRequest {
Expand Down Expand Up @@ -849,6 +875,32 @@ message TriggerOrganizationModelResponse {
repeated TaskOutput task_outputs = 2;
}

// TriggerAsyncOrganizationModelRequest represents a request to trigger a model inference
// asynchronously
message TriggerAsyncOrganizationModelRequest {
// The resource name of the model , which allows its access by parent organization
// and ID.
// - Format: `organizations/{organization.id}/models/{model.id}`.
string name = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference).type = "api.instill.tech/Model",
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
field_configuration: {path_param_name: "organization_model_name"}
}
];
// Inference input parameters.
repeated TaskInput task_inputs = 2 [(google.api.field_behavior) = REQUIRED];
// Model version tag
string version = 3 [(google.api.field_behavior) = REQUIRED];
}

// TriggerAsyncOrganizationModelResponse contains the information to access the
// status of an asynchronous model inference.
message TriggerAsyncOrganizationModelResponse {
// Long-running operation information.
google.longrunning.Operation operation = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// TriggerOrganizationModelBinaryFileUploadRequest represents a request trigger a model
// inference by uploading a binary file as the input.
message TriggerOrganizationModelBinaryFileUploadRequest {
Expand Down
24 changes: 24 additions & 0 deletions model/model/v1alpha/model_public_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ service ModelPublicService {
option (google.api.method_signature) = "name,inputs";
}

// Trigger model inference asynchronously
//
// Triggers a deployed model to infer the result of a set of task or
// questions.
rpc TriggerAsyncUserModel(TriggerAsyncUserModelRequest) returns (TriggerAsyncUserModelResponse) {
option (google.api.http) = {
post: "/v1alpha/{name=users/*/models/*}/{version=*}/triggerAsync"
body: "*"
};
option (google.api.method_signature) = "name,inputs";
}

// Trigger model inference with a binary input
//
// Triggers a deployed model to infer the result of a task or question,
Expand Down Expand Up @@ -333,6 +345,18 @@ service ModelPublicService {
option (google.api.method_signature) = "name,inputs";
}

// Trigger model inference asynchronously
//
// Triggers a deployed model to infer the result of a set of task or
// questions.
rpc TriggerAsyncOrganizationModel(TriggerAsyncOrganizationModelRequest) returns (TriggerAsyncOrganizationModelResponse) {
option (google.api.http) = {
post: "/v1alpha/{name=organizations/*/models/*}/{version=*}/triggerAsync"
body: "*"
};
option (google.api.method_signature) = "name,inputs";
}

// Trigger model inference with a binary input
//
// Triggers a deployed model to infer the result of a task or question,
Expand Down
132 changes: 132 additions & 0 deletions openapiv2/model/service.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,48 @@ paths:
$ref: '#/definitions/ModelPublicServiceTriggerUserModelBody'
tags:
- ModelPublicService
/v1alpha/{user_model_name}/{version}/triggerAsync:
post:
summary: Trigger model inference asynchronously
description: |-
Triggers a deployed model to infer the result of a set of task or
questions.
operationId: ModelPublicService_TriggerAsyncUserModel
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1alphaTriggerAsyncUserModelResponse'
"401":
description: Returned when the client credentials are not valid.
schema: {}
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: user_model_name
description: |-
The resource name of the model , which allows its access by parent user
and ID.
- Format: `users/{user.id}/models/{model.id}`.
in: path
required: true
type: string
pattern: users/[^/]+/models/[^/]+
- name: version
description: Model version tag
in: path
required: true
type: string
pattern: '[^/]+'
- name: body
in: body
required: true
schema:
$ref: '#/definitions/ModelPublicServiceTriggerAsyncUserModelBody'
tags:
- ModelPublicService
/v1alpha/{organization_name}/models:
get:
summary: List organization models
Expand Down Expand Up @@ -1212,6 +1254,48 @@ paths:
$ref: '#/definitions/ModelPublicServiceTriggerOrganizationModelBody'
tags:
- ModelPublicService
/v1alpha/{organization_model_name}/{version}/triggerAsync:
post:
summary: Trigger model inference asynchronously
description: |-
Triggers a deployed model to infer the result of a set of task or
questions.
operationId: ModelPublicService_TriggerAsyncOrganizationModel
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1alphaTriggerAsyncOrganizationModelResponse'
"401":
description: Returned when the client credentials are not valid.
schema: {}
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: organization_model_name
description: |-
The resource name of the model , which allows its access by parent organization
and ID.
- Format: `organizations/{organization.id}/models/{model.id}`.
in: path
required: true
type: string
pattern: organizations/[^/]+/models/[^/]+
- name: version
description: Model version tag
in: path
required: true
type: string
pattern: '[^/]+'
- name: body
in: body
required: true
schema:
$ref: '#/definitions/ModelPublicServiceTriggerAsyncOrganizationModelBody'
tags:
- ModelPublicService
/v1alpha/{name}:
get:
summary: Get the details of a long-running operation
Expand Down Expand Up @@ -1283,6 +1367,34 @@ definitions:
title: RenameUserModelRequest represents a request to rename a model
required:
- new_model_id
ModelPublicServiceTriggerAsyncOrganizationModelBody:
type: object
properties:
task_inputs:
type: array
items:
type: object
$ref: '#/definitions/v1alphaTaskInput'
description: Inference input parameters.
title: |-
TriggerAsyncOrganizationModelRequest represents a request to trigger a model inference
asynchronously
required:
- task_inputs
ModelPublicServiceTriggerAsyncUserModelBody:
type: object
properties:
task_inputs:
type: array
items:
type: object
$ref: '#/definitions/v1alphaTaskInput'
description: Inference input parameters.
description: |-
TriggerAsyncUserModelRequest represents a request to trigger a model inference
asynchronously.
required:
- task_inputs
ModelPublicServiceTriggerOrganizationModelBody:
type: object
properties:
Expand Down Expand Up @@ -2740,6 +2852,26 @@ definitions:
description: A list of generated images, encoded in base64.
readOnly: true
description: TextToImageOutput contains the result of a text-to-image task.
v1alphaTriggerAsyncOrganizationModelResponse:
type: object
properties:
operation:
$ref: '#/definitions/googlelongrunningOperation'
description: Long-running operation information.
readOnly: true
description: |-
TriggerAsyncOrganizationModelResponse contains the information to access the
status of an asynchronous model inference.
v1alphaTriggerAsyncUserModelResponse:
type: object
properties:
operation:
$ref: '#/definitions/googlelongrunningOperation'
description: Long-running operation information.
readOnly: true
description: |-
TriggerAsyncUserModelResponse contains the information to access the
status of an asynchronous model inference.
v1alphaTriggerOrganizationModelBinaryFileUploadResponse:
type: object
properties:
Expand Down

0 comments on commit 3dcf05f

Please sign in to comment.