Skip to content

Commit

Permalink
Merge pull request #791 from bjwswang/main
Browse files Browse the repository at this point in the history
refactor(file): files upload and processing during agent chat
  • Loading branch information
bjwswang authored Mar 7, 2024
2 parents 52351f7 + 0876aa5 commit f969216
Show file tree
Hide file tree
Showing 26 changed files with 438 additions and 728 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ resources:
kind: Application
path: github.com/kubeagi/arcadia/api/base/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kubeagi.k8s.com.cn
group: arcadia
kind: DocumentLoader
path: github.com/kubeagi/arcadia/api/app-node/documentloader/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
controller: true
Expand Down
6 changes: 6 additions & 0 deletions api/app-node/chain/v1alpha1/llmchain_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ type LLMChainSpec struct {

type CommonChainConfig struct {
Tools []agent.Tool `json:"tools,omitempty"`

// MaxNumberOfConcurrent represents the max number of concurrent calls done simultaneously to
// the llm chain.Only 1 by default
// +kubebuilder:default=1
MaxNumberOfConccurent int `json:"maxNumberOfConccurent,omitempty"`

// for memory
Memory Memory `json:"memory,omitempty"`

Expand Down
7 changes: 7 additions & 0 deletions api/base/v1alpha1/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.

package v1alpha1

import "fmt"

const (
InputNode = "Input"
OutputNode = "Output"
Expand All @@ -26,3 +28,8 @@ const (
// AppPublicLabelKey will add to app which is public
AppPublicLabelKey = Group + "/app-is-public"
)

// ConversationFilePath is the path in system storage for file within a conversation
func ConversationFilePath(appName string, conversationID string, fileName string) string {
return fmt.Sprintf("application/%s/conversation/%s/%s", appName, conversationID, fileName)
}
114 changes: 15 additions & 99 deletions apiserver/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,9 @@ const docTemplate = `{
}
}
},
"/chat/conversations/docs": {
"/chat/conversations/file": {
"post": {
"description": "receive and process uploaded documents(pdf, docx) for one conversation",
"description": "receive conversational files for one conversation",
"consumes": [
"multipart/form-data"
],
Expand All @@ -894,7 +894,7 @@ const docTemplate = `{
"tags": [
"application"
],
"summary": "receive and process uploaded documents(pdf, docx) for one conversation",
"summary": "receive conversational files for one conversation",
"parameters": [
{
"type": "string",
Expand All @@ -912,49 +912,23 @@ const docTemplate = `{
},
{
"type": "string",
"description": "The query to this document",
"name": "query",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "The conversation id for this document",
"description": "The conversation id for this file",
"name": "conversation_id",
"in": "formData"
},
{
"type": "string",
"description": "The response mode to this conversation",
"name": "response_mode",
"in": "formData",
"required": true
},
{
"type": "file",
"description": "This is the docs for the conversation",
"name": "docs",
"description": "This is the file for the conversation",
"name": "file",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "The chunk size when load and split the document",
"name": "chunk_size",
"in": "formData"
},
{
"type": "integer",
"description": "The chunk overlap when load and split the document",
"name": "chunk_overlap",
"in": "formData"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/chat.ConversationDocsRespBody"
"$ref": "#/definitions/chat.ChatRespBody"
}
},
"400": {
Expand Down Expand Up @@ -1399,66 +1373,11 @@ const docTemplate = `{
"chat.ChatRespBody": {
"type": "object",
"properties": {
"conversation_id": {
"type": "string",
"example": "5a41f3ca-763b-41ec-91c3-4bbbb00736d0"
},
"created_at": {
"description": "CreatedAt is the time when the message is created",
"type": "string",
"example": "2023-12-21T10:21:06.389359092+08:00"
},
"latency": {
"description": "Latency(ms) is how much time the server cost to process a certain request.",
"type": "integer",
"example": 1000
},
"message": {
"description": "Message is what AI say",
"type": "string",
"example": "旷工最小计算单位为0.5天。"
},
"message_id": {
"action": {
"description": "Action indicates what is this chat for",
"type": "string",
"example": "4f3546dd-5404-4bf8-a3bc-4fa3f9a7ba24"
},
"references": {
"description": "References is the list of references",
"type": "array",
"items": {
"$ref": "#/definitions/retriever.Reference"
}
}
}
},
"chat.ConversatioSingleDocRespBody": {
"type": "object",
"properties": {
"file_name": {
"type": "string"
},
"number_of_documents": {
"type": "integer"
},
"summary": {
"description": "Summary info",
"type": "string"
},
"timecost_for_embedding": {
"description": "Embedding info",
"type": "number"
},
"timecost_for_summarization": {
"type": "number"
"example": "CHAT"
},
"total_time_cost": {
"type": "number"
}
}
},
"chat.ConversationDocsRespBody": {
"type": "object",
"properties": {
"conversation_id": {
"type": "string",
"example": "5a41f3ca-763b-41ec-91c3-4bbbb00736d0"
Expand All @@ -1468,14 +1387,6 @@ const docTemplate = `{
"type": "string",
"example": "2023-12-21T10:21:06.389359092+08:00"
},
"doc": {
"description": "Docs are the responbody for each document",
"allOf": [
{
"$ref": "#/definitions/chat.ConversatioSingleDocRespBody"
}
]
},
"latency": {
"description": "Latency(ms) is how much time the server cost to process a certain request.",
"type": "integer",
Expand Down Expand Up @@ -1991,6 +1902,11 @@ const docTemplate = `{
"storage.Message": {
"type": "object",
"properties": {
"action": {
"description": "Action indicates what is this message for\nChat(by default),UPLOAD,etc...",
"type": "string",
"example": "UPLOAD"
},
"answer": {
"type": "string",
"example": "旷工最小计算单位为0.5天。"
Expand Down
114 changes: 15 additions & 99 deletions apiserver/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,9 @@
}
}
},
"/chat/conversations/docs": {
"/chat/conversations/file": {
"post": {
"description": "receive and process uploaded documents(pdf, docx) for one conversation",
"description": "receive conversational files for one conversation",
"consumes": [
"multipart/form-data"
],
Expand All @@ -888,7 +888,7 @@
"tags": [
"application"
],
"summary": "receive and process uploaded documents(pdf, docx) for one conversation",
"summary": "receive conversational files for one conversation",
"parameters": [
{
"type": "string",
Expand All @@ -906,49 +906,23 @@
},
{
"type": "string",
"description": "The query to this document",
"name": "query",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "The conversation id for this document",
"description": "The conversation id for this file",
"name": "conversation_id",
"in": "formData"
},
{
"type": "string",
"description": "The response mode to this conversation",
"name": "response_mode",
"in": "formData",
"required": true
},
{
"type": "file",
"description": "This is the docs for the conversation",
"name": "docs",
"description": "This is the file for the conversation",
"name": "file",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "The chunk size when load and split the document",
"name": "chunk_size",
"in": "formData"
},
{
"type": "integer",
"description": "The chunk overlap when load and split the document",
"name": "chunk_overlap",
"in": "formData"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/chat.ConversationDocsRespBody"
"$ref": "#/definitions/chat.ChatRespBody"
}
},
"400": {
Expand Down Expand Up @@ -1393,66 +1367,11 @@
"chat.ChatRespBody": {
"type": "object",
"properties": {
"conversation_id": {
"type": "string",
"example": "5a41f3ca-763b-41ec-91c3-4bbbb00736d0"
},
"created_at": {
"description": "CreatedAt is the time when the message is created",
"type": "string",
"example": "2023-12-21T10:21:06.389359092+08:00"
},
"latency": {
"description": "Latency(ms) is how much time the server cost to process a certain request.",
"type": "integer",
"example": 1000
},
"message": {
"description": "Message is what AI say",
"type": "string",
"example": "旷工最小计算单位为0.5天。"
},
"message_id": {
"action": {
"description": "Action indicates what is this chat for",
"type": "string",
"example": "4f3546dd-5404-4bf8-a3bc-4fa3f9a7ba24"
},
"references": {
"description": "References is the list of references",
"type": "array",
"items": {
"$ref": "#/definitions/retriever.Reference"
}
}
}
},
"chat.ConversatioSingleDocRespBody": {
"type": "object",
"properties": {
"file_name": {
"type": "string"
},
"number_of_documents": {
"type": "integer"
},
"summary": {
"description": "Summary info",
"type": "string"
},
"timecost_for_embedding": {
"description": "Embedding info",
"type": "number"
},
"timecost_for_summarization": {
"type": "number"
"example": "CHAT"
},
"total_time_cost": {
"type": "number"
}
}
},
"chat.ConversationDocsRespBody": {
"type": "object",
"properties": {
"conversation_id": {
"type": "string",
"example": "5a41f3ca-763b-41ec-91c3-4bbbb00736d0"
Expand All @@ -1462,14 +1381,6 @@
"type": "string",
"example": "2023-12-21T10:21:06.389359092+08:00"
},
"doc": {
"description": "Docs are the responbody for each document",
"allOf": [
{
"$ref": "#/definitions/chat.ConversatioSingleDocRespBody"
}
]
},
"latency": {
"description": "Latency(ms) is how much time the server cost to process a certain request.",
"type": "integer",
Expand Down Expand Up @@ -1985,6 +1896,11 @@
"storage.Message": {
"type": "object",
"properties": {
"action": {
"description": "Action indicates what is this message for\nChat(by default),UPLOAD,etc...",
"type": "string",
"example": "UPLOAD"
},
"answer": {
"type": "string",
"example": "旷工最小计算单位为0.5天。"
Expand Down
Loading

0 comments on commit f969216

Please sign in to comment.