Skip to content

Commit

Permalink
feat(agent): add chat and chat message apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Yougigun committed Nov 25, 2024
1 parent b85ba0e commit 3ad2ed3
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 23 deletions.
76 changes: 76 additions & 0 deletions app/app/v1alpha/app_public_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,68 @@ service AppPublicService {
};
}

// Create a chat
//
// Creates a chat.
rpc CreateChat(CreateChatRequest) returns (CreateChatResponse) {
option (google.api.http) = {
post: "/v1alpha/namespaces/{namespace_id}/chats"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "🍎 App"
extensions: {
key: "x-stage"
value: {string_value: "alpha"}
}
};
}

// List chats
//
// Returns a paginated list of conversations.
rpc ListChats(ListChatsRequest) returns (ListChatsResponse) {
option (google.api.http) = {get: "/v1alpha/namespaces/{namespace_id}/chats"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "🍎 App"
extensions: {
key: "x-stage"
value: {string_value: "alpha"}
}
};
}

// Update a chat
//
// Updates a chat.
rpc UpdateChat(UpdateChatRequest) returns (UpdateChatResponse) {
option (google.api.http) = {
put: "/v1alpha/namespaces/{namespace_id}/chats/{chat_uid}"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "🍎 App"
extensions: {
key: "x-stage"
value: {string_value: "alpha"}
}
};
}

// Delete a chat
//
// Deletes a chat.
rpc DeleteChat(DeleteChatRequest) returns (DeleteChatResponse) {
option (google.api.http) = {delete: "/v1alpha/namespaces/{namespace_id}/chats/{chat_uid}"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "🍎 App"
extensions: {
key: "x-stage"
value: {string_value: "alpha"}
}
};
}

// Create a message
//
// Creates a message.
Expand Down Expand Up @@ -240,6 +302,20 @@ service AppPublicService {
};
}

// List chat messages
//
// Returns a paginated list of messages.
rpc ListChatMessages(ListChatMessagesRequest) returns (ListChatMessagesResponse) {
option (google.api.http) = {get: "/v1alpha/namespaces/{namespace_id}/chats/{chat_uid}/messages"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "🍎 App"
extensions: {
key: "x-stage"
value: {string_value: "alpha"}
}
};
}

// Restart Playground Conversation
//
// Creates a new conversation and uses the auth user UID as creator UID and
Expand Down
146 changes: 123 additions & 23 deletions app/app/v1alpha/conversation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,40 @@ message Conversation {
google.protobuf.Timestamp create_time = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
// update time of the conversation
google.protobuf.Timestamp update_time = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Chat represents a chat
message Chat {
// unique identifier of the conversation created by the system
string uid = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
// namespace id
string namespace_id = 2 [(google.api.field_behavior) = REQUIRED];
// last used catalog uid
optional string last_used_catalog_uid = 4 [(google.api.field_behavior) = OPTIONAL];
// last used top k
optional uint32 last_used_top_k = 5 [(google.api.field_behavior) = OPTIONAL];
// creation time of the chat
google.protobuf.Timestamp create_time = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
// update time of the chat
google.protobuf.Timestamp update_time = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
// agent metadata
AIAgentAppMetadata ai_agent_app = 9 [(google.api.field_behavior) = OUTPUT_ONLY];
AIAgentAppMetadata ai_agent_app = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
// temp catalog id automatically created for ai agent app
optional string temp_catalog_id = 10 [(google.api.field_behavior) = OPTIONAL];
// chat with
ChatWith chat_with = 11 [(google.api.field_behavior) = OUTPUT_ONLY];
optional string temp_catalog_id = 9 [(google.api.field_behavior) = OPTIONAL];
// conversation display name
string conversation_display_name = 12 [(google.api.field_behavior) = OPTIONAL];
string chat_display_name = 10 [(google.api.field_behavior) = OPTIONAL];
}

// ChatWith enum
// enum ChatWith {
// // unspecified
// CHAT_WITH_UNSPECIFIED = 0;
// // chat with ai assistant(default)
// CHAT_WITH_AI_ASSISTANT = 1;
// // chat with ai agent
// CHAT_WITH_AI_AGENT = 2;
// }

// Message represents a single message in a conversation
message Message {
// message type
Expand Down Expand Up @@ -81,12 +105,6 @@ message CreateConversationRequest {
string app_id = 2 [(google.api.field_behavior) = REQUIRED];
// conversation id. only allow kebab case
string conversation_id = 3 [(google.api.field_behavior) = REQUIRED];
// chat with(optional) default is CHAT_WITH_AI_ASSISTANT
ChatWith chat_with = 4 [(google.api.field_behavior) = OPTIONAL];
// conversation display name
string conversation_display_name = 5 [(google.api.field_behavior) = OPTIONAL];
// agent metadata
AIAgentAppMetadata ai_agent_app = 6 [(google.api.field_behavior) = OPTIONAL];
}

// CreateConversationResponse returns the created conversation
Expand All @@ -95,6 +113,22 @@ message CreateConversationResponse {
Conversation conversation = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// CreateChatRequest is used to create a new chat
message CreateChatRequest {
// namespace id
string namespace_id = 1 [(google.api.field_behavior) = REQUIRED];
// chat display name
string chat_display_name = 2 [(google.api.field_behavior) = OPTIONAL];
// agent metadata
AIAgentAppMetadata ai_agent_app = 3 [(google.api.field_behavior) = OPTIONAL];
}

// CreateChatResponse returns the created chat
message CreateChatResponse {
// chat
Chat chat = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// ListConversationsRequest is used to list conversations
message ListConversationsRequest {
// namespace id
Expand All @@ -112,18 +146,6 @@ message ListConversationsRequest {
string conversation_id = 6 [(google.api.field_behavior) = OPTIONAL];
// If true, all conversations will be returned. This has higher priority over conversation_id, page_size, and page_token.
bool if_all = 7 [(google.api.field_behavior) = OPTIONAL];
// chat with
ChatWith chat_with = 8 [(google.api.field_behavior) = OPTIONAL];
}

// ChatWith enum
enum ChatWith {
// unspecified
CHAT_WITH_UNSPECIFIED = 0;
// chat with ai assistant(default)
CHAT_WITH_AI_ASSISTANT = 1;
// chat with ai agent
CHAT_WITH_AI_AGENT = 2;
}

// ListConversationsResponse returns a list of conversations
Expand All @@ -136,6 +158,31 @@ message ListConversationsResponse {
int32 total_size = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// ListChatsRequest is used to list chats
message ListChatsRequest {
// namespace id
string namespace_id = 1 [(google.api.field_behavior) = REQUIRED];
// page size
int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];
// page token
string page_token = 3 [(google.api.field_behavior) = OPTIONAL];
// if true, all chats will be returned. This has higher priority over page_size and page_token.
bool if_all = 4 [(google.api.field_behavior) = OPTIONAL];
// chat_uid this is optional, if provided, only the chat with the given chat_uid will be returned
// first check chat_uid then check if_all
string chat_uid = 5 [(google.api.field_behavior) = OPTIONAL];
}

// ListChatsResponse returns a list of chats
message ListChatsResponse {
// chats
repeated Chat chats = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
// next page token
string next_page_token = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
// total size
int32 total_size = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// UpdateConversationRequest is used to update a conversation
message UpdateConversationRequest {
// namespace id
Expand All @@ -162,6 +209,24 @@ message UpdateConversationResponse {
Conversation conversation = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// UpdateChatRequest is used to update a chat
message UpdateChatRequest {
// namespace id
string namespace_id = 1;
// chat uid
string chat_uid = 2 [(google.api.field_behavior) = REQUIRED];
// chat display name
string chat_display_name = 3 [(google.api.field_behavior) = OPTIONAL];
// ai agent app metadata
AIAgentAppMetadata ai_agent_app = 4 [(google.api.field_behavior) = OPTIONAL];
}

// UpdateChatResponse returns the updated chat
message UpdateChatResponse {
// chat
Chat chat = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// DeleteConversationRequest is used to delete a conversation
message DeleteConversationRequest {
// namespace id
Expand All @@ -175,6 +240,17 @@ message DeleteConversationRequest {
// DeleteConversationResponse is empty as no content needs to be returned
message DeleteConversationResponse {}

// DeleteChatRequest is used to delete a chat
message DeleteChatRequest {
// namespace id
string namespace_id = 1 [(google.api.field_behavior) = REQUIRED];
// chat uid
string chat_uid = 2 [(google.api.field_behavior) = REQUIRED];
}

// DeleteChatResponse is empty as no content needs to be returned
message DeleteChatResponse {}

// CreateMessageRequest is used to create a new message
message CreateMessageRequest {
// namespace id
Expand Down Expand Up @@ -279,6 +355,30 @@ message DeleteMessageRequest {
// DeleteMessageResponse is empty as no content needs to be returned
message DeleteMessageResponse {}

// ListChatMessagesRequest is used to list messages in a chat
message ListChatMessagesRequest {
// namespace id
string namespace_id = 1 [(google.api.field_behavior) = REQUIRED];
// chat uid
string chat_uid = 2 [(google.api.field_behavior) = REQUIRED];
// page size
int32 page_size = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
// page token
string page_token = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
// If true, all messages will be returned. This has higher priority over page_size and page_token.
bool if_all = 5 [(google.api.field_behavior) = OPTIONAL];
}

// ListChatMessagesResponse returns a list of messages
message ListChatMessagesResponse {
// messages
repeated Message messages = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
// next page token
string next_page_token = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
// total size
int32 total_size = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// ChatRequest represents a request to send a message
// to a chatbot synchronously and streams back the results.
message ChatRequest {
Expand Down

0 comments on commit 3ad2ed3

Please sign in to comment.