Skip to content

Commit

Permalink
feat(model): add order_by field for list model endpoints (#346)
Browse files Browse the repository at this point in the history
Because

- Model hub page support `order_by` option
- Model banner needs to show latest model state

This commit

- add `order_by` input query string
- add watch latest model endpoints

resolves INS-4775

---------

Co-authored-by: droplet-bot <[email protected]>
  • Loading branch information
heiruwu and droplet-bot authored May 28, 2024
1 parent 85ef118 commit 6e9050e
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 38 deletions.
2 changes: 1 addition & 1 deletion artifact/artifact/v1alpha/artifact.proto
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ message DeleteKnowledgeBaseResponse {
string error_msg = 1;
// The status code.
int32 status_code = 2;
}
}
62 changes: 29 additions & 33 deletions artifact/artifact/v1alpha/artifact_public_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,33 @@ service ArtifactPublicService {
option (google.api.method_visibility).restriction = "INTERNAL";
}

// Create a knowledge base
rpc CreateKnowledgeBase(CreateKnowledgeBaseRequest) returns (CreateKnowledgeBaseResponse) {
option (google.api.http) = {
post: "/v1alpha/artifact/kb"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "KnowledgeBase"};
}

// Get all knowledge bases info
rpc GetKnowledgeBases(GetKnowledgeBasesRequest) returns (GetKnowledgeBasesResponse) {
option (google.api.http) = {
get: "/v1alpha/artifact/kb"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "KnowledgeBase"};
}

// Update a knowledge base info
rpc UpdateKnowledgeBase(UpdateKnowledgeBaseRequest) returns (UpdateKnowledgeBaseResponse) {
option (google.api.http) = {
put: "/v1alpha/artifact/kb"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "KnowledgeBase"};
}

// Delete a knowledge base
rpc DeleteKnowledgeBase(DeleteKnowledgeBaseRequest) returns (DeleteKnowledgeBaseResponse) {
option (google.api.http) = {
delete: "/v1alpha/artifact/kb/{id}"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "KnowledgeBase"};
}
// Create a knowledge base
rpc CreateKnowledgeBase(CreateKnowledgeBaseRequest) returns (CreateKnowledgeBaseResponse) {
option (google.api.http) = {
post: "/v1alpha/artifact/kb"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "KnowledgeBase"};
}

// Get all knowledge bases info
rpc GetKnowledgeBases(GetKnowledgeBasesRequest) returns (GetKnowledgeBasesResponse) {
option (google.api.http) = {get: "/v1alpha/artifact/kb"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "KnowledgeBase"};
}

// Update a knowledge base info
rpc UpdateKnowledgeBase(UpdateKnowledgeBaseRequest) returns (UpdateKnowledgeBaseResponse) {
option (google.api.http) = {
put: "/v1alpha/artifact/kb"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "KnowledgeBase"};
}

// Delete a knowledge base
rpc DeleteKnowledgeBase(DeleteKnowledgeBaseRequest) returns (DeleteKnowledgeBaseResponse) {
option (google.api.http) = {delete: "/v1alpha/artifact/kb/{id}"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "KnowledgeBase"};
}
}
59 changes: 59 additions & 0 deletions model/model/v1alpha/model.proto
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ message ListModelsRequest {
optional string filter = 5 [(google.api.field_behavior) = OPTIONAL];
// Limit results to pipelines with the specified visibility.
optional Model.Visibility visibility = 6 [(google.api.field_behavior) = OPTIONAL];
// Order by field, with options for ordering by `id`, `create_time` or `update_time`.
// Format: `order_by=id` or `order_by=create_time desc`, default is `asc`.
optional string order_by = 7 [(google.api.field_behavior) = OPTIONAL];
}

// ListModelsResponse contains a list of models.
Expand Down Expand Up @@ -331,6 +334,9 @@ message ListUserModelsRequest {
optional string filter = 6 [(google.api.field_behavior) = OPTIONAL];
// Limit results to pipelines with the specified visibility.
optional Model.Visibility visibility = 7 [(google.api.field_behavior) = OPTIONAL];
// Order by field, with options for ordering by `id`, `create_time` or `update_time`.
// Format: `order_by=id` or `order_by=create_time desc`, default is `asc`.
optional string order_by = 8 [(google.api.field_behavior) = OPTIONAL];
}

// ListUserModelsResponse contains a list of models.
Expand Down Expand Up @@ -513,6 +519,31 @@ message WatchUserModelResponse {
string message = 3;
}

// WatchUserLatestModelRequest represents a request to fetch current state of
// the latest model version.
message WatchUserLatestModelRequest {
// 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"}
}
];
}

// WatchUserLatestModelResponse contains the state of the latest model version.
message WatchUserLatestModelResponse {
// State.
State state = 1;
// Deprecated field `progress`
reserved 2;
// Detail description of the state
string message = 3;
}

// ListUserModelVersionsRequest represents a request to list all the versions
// of a model namespace of a user.
message ListUserModelVersionsRequest {
Expand Down Expand Up @@ -827,6 +858,9 @@ message ListOrganizationModelsRequest {
optional string filter = 6 [(google.api.field_behavior) = OPTIONAL];
// Limit results to pipelines with the specified visibility.
optional Model.Visibility visibility = 7 [(google.api.field_behavior) = OPTIONAL];
// Order by field, with options for ordering by `id`, `create_time` or `update_time`.
// Format: `order_by=id` or `order_by=create_time desc`, default is `asc`.
optional string order_by = 8 [(google.api.field_behavior) = OPTIONAL];
}

// ListOrganizationModelsResponse contains a list of models.
Expand Down Expand Up @@ -1009,6 +1043,31 @@ message WatchOrganizationModelResponse {
string message = 3;
}

// WatchOrganizationLatestModelRequest represents a request to fetch current state of
// the latest model version
message WatchOrganizationLatestModelRequest {
// 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"}
}
];
}

// WatchOrganizationLatestModelResponse contains the state of the latest model version.
message WatchOrganizationLatestModelResponse {
// State.
State state = 1;
// Deprecated field `progress`
reserved 2;
// Detail description of the state
string message = 3;
}

// ListOrganizationModelVersionsRequest represents a request to list all the versions
// of a model namespace of an organization.
message ListOrganizationModelVersionsRequest {
Expand Down
26 changes: 24 additions & 2 deletions model/model/v1alpha/model_public_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ service ModelPublicService {
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "Model"};
}

// Watch the state of a model
// Watch the state of a model version
//
// Returns the state of a model. The deploy / undeploy actions take some
// time, during which a model will be in an UNSPECIFIED state. This endpoint
Expand All @@ -207,6 +207,17 @@ service ModelPublicService {
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "Model"};
}

// Watch the state of the latest model version
//
// Returns the state of the latest model version. The deploy / undeploy actions take some
// time, during which a model will be in an UNSPECIFIED state. This endpoint
// allows clients to track the state and progress of the model.
rpc WatchUserLatestModel(WatchUserLatestModelRequest) returns (WatchUserLatestModelResponse) {
option (google.api.http) = {get: "/v1alpha/{name=users/*/models/*}/watch"};
option (google.api.method_signature) = "name";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "Model"};
}

// List user model versions
//
// Returns a paginated list of version of a model namespace that belong to the specified user.
Expand Down Expand Up @@ -391,7 +402,7 @@ service ModelPublicService {
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "Model"};
}

// Watch the state of a model
// Watch the state of a model version
//
// Returns the state of a model. The deploy / undeploy actions take some
// time, during which a model will be in an UNSPECIFIED state. This endpoint
Expand All @@ -402,6 +413,17 @@ service ModelPublicService {
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "Model"};
}

// Watch the state of the latest model version
//
// Returns the state of the latest model version. The deploy / undeploy actions take some
// time, during which a model will be in an UNSPECIFIED state. This endpoint
// allows clients to track the state and progress of the model.
rpc WatchOrganizationLatestModel(WatchOrganizationLatestModelRequest) returns (WatchOrganizationLatestModelResponse) {
option (google.api.http) = {get: "/v1alpha/{name=organizations/*/models/*}/watch"};
option (google.api.method_signature) = "name";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {tags: "Model"};
}

// List organization model versions
//
// Returns a paginated list of version of a model namespace that belong to the specified organization.
Expand Down
109 changes: 107 additions & 2 deletions openapiv2/model/service.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ paths:
enum:
- VISIBILITY_PRIVATE
- VISIBILITY_PUBLIC
- name: order_by
description: |-
Order by field, with options for ordering by `id`, `create_time` or `update_time`.
Format: `order_by=id` or `order_by=create_time desc`, default is `asc`.
in: query
required: false
type: string
tags:
- Model
/v1alpha/{permalink}/lookUp:
Expand Down Expand Up @@ -317,6 +324,13 @@ paths:
enum:
- VISIBILITY_PRIVATE
- VISIBILITY_PUBLIC
- name: order_by
description: |-
Order by field, with options for ordering by `id`, `create_time` or `update_time`.
Format: `order_by=id` or `order_by=create_time desc`, default is `asc`.
in: query
required: false
type: string
tags:
- Model
post:
Expand Down Expand Up @@ -711,7 +725,7 @@ paths:
- Model
/v1alpha/{user_model_name}/versions/{version}/watch:
get:
summary: Watch the state of a model
summary: Watch the state of a model version
description: |-
Returns the state of a model. The deploy / undeploy actions take some
time, during which a model will be in an UNSPECIFIED state. This endpoint
Expand Down Expand Up @@ -747,6 +761,38 @@ paths:
pattern: '[^/]+'
tags:
- Model
/v1alpha/{user_model_name}/watch:
get:
summary: Watch the state of the latest model version
description: |-
Returns the state of the latest model version. The deploy / undeploy actions take some
time, during which a model will be in an UNSPECIFIED state. This endpoint
allows clients to track the state and progress of the model.
operationId: ModelPublicService_WatchUserLatestModel
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1alphaWatchUserLatestModelResponse'
"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/[^/]+
tags:
- Model
/v1alpha/{user_model_name}/versions:
get:
summary: List user model versions
Expand Down Expand Up @@ -1030,6 +1076,13 @@ paths:
enum:
- VISIBILITY_PRIVATE
- VISIBILITY_PUBLIC
- name: order_by
description: |-
Order by field, with options for ordering by `id`, `create_time` or `update_time`.
Format: `order_by=id` or `order_by=create_time desc`, default is `asc`.
in: query
required: false
type: string
tags:
- Model
post:
Expand Down Expand Up @@ -1424,7 +1477,7 @@ paths:
- Model
/v1alpha/{organization_model_name}/versions/{version}/watch:
get:
summary: Watch the state of a model
summary: Watch the state of a model version
description: |-
Returns the state of a model. The deploy / undeploy actions take some
time, during which a model will be in an UNSPECIFIED state. This endpoint
Expand Down Expand Up @@ -1460,6 +1513,38 @@ paths:
pattern: '[^/]+'
tags:
- Model
/v1alpha/{organization_model_name}/watch:
get:
summary: Watch the state of the latest model version
description: |-
Returns the state of the latest model version. The deploy / undeploy actions take some
time, during which a model will be in an UNSPECIFIED state. This endpoint
allows clients to track the state and progress of the model.
operationId: ModelPublicService_WatchOrganizationLatestModel
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1alphaWatchOrganizationLatestModelResponse'
"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/[^/]+
tags:
- Model
/v1alpha/{user_model_name_1}/versions:
get:
summary: List organization model versions
Expand Down Expand Up @@ -3651,6 +3736,16 @@ definitions:
description: |-
VisualQuestionAnsweringOutput contains the result of a visual
question-answering task.
v1alphaWatchOrganizationLatestModelResponse:
type: object
properties:
state:
$ref: '#/definitions/modelv1alphaState'
description: State.
message:
type: string
title: Detail description of the state
description: WatchOrganizationLatestModelResponse contains the state of the latest model version.
v1alphaWatchOrganizationModelResponse:
type: object
properties:
Expand All @@ -3661,6 +3756,16 @@ definitions:
type: string
title: Detail description of the state
description: WatchOrganizationModelResponse contains the state of a model.
v1alphaWatchUserLatestModelResponse:
type: object
properties:
state:
$ref: '#/definitions/modelv1alphaState'
description: State.
message:
type: string
title: Detail description of the state
description: WatchUserLatestModelResponse contains the state of the latest model version.
v1alphaWatchUserModelResponse:
type: object
properties:
Expand Down

0 comments on commit 6e9050e

Please sign in to comment.