AI 市场文档
Last updated
Last updated
架构概述
1.1 概述、
表 1. 描述 AI 服务架构中的组件
No.
Category
Component
Description
AI scope
Note
1
Client
Client
AI marketplace
N
2
Client callback
Client callback
Get results after a task has been completed
N
3
AI App API
AI App API
Receive request from client (marketplace) and process. Manage stages to solve a specific task.
Y
4
Storage
S3 storage
Store media data (Including request data from the client and AI result data). Services send media file metadata to each other
N
5
AI APP Database
Store user request information for statistics
Y
6
Redis
Store temporary results of tasks and requests: Will be deleted after a period of time
Y
7
Queue
RabbitMQ
Store pending tasks
Y
8
AI service 1
AI service 1 API
Receive requests to process tasks and push tasks into the queue
Y
9
AI service worker
Pull the task in the queue and process it
Y
10
AI service 2
AI service 2 API
Receive requests to process tasks and push tasks into the queue
Optional
Whether or not depends on the AI problem
11
AI service worker
Pull the task in the queue and process it
Optional
Whether or not depends on the AI problem
对于一个基本的AI问题:AI服务将需要至少6个组件(docker容器)。当AI问题复杂且需要分为多个阶段进行处理时,组件数量将会增加
简单AI问题的示例:人脸检测、人脸检测、人脸嵌入、人脸搜索……对于每个这样的问题,都需要开发和部署6个组件
对于人脸识别等更复杂的问题,需要经过许多步骤进行处理:人脸检测,然后是人脸嵌入,最后是搜索。这个问题最多有3个阶段,因此最多会有3个AI服务。因此,需要开发和部署的组件数量为10个(每增加一个服务增加2个组件)
Audio Craft是一种根据用户描述生成声音和音乐的AI服务。它分为2个彼此独立运行的子服务。 AudioGen 用于生成声音,例如:汽车喇叭声、猫叫声……而 MusicGen 则专门用于生成音乐(带有旋律)。AudioCraft 的系统设计如图 2 所示
表2. 源代码中的序列图和可执行代码描述
No.
Description
Executable code
Note
1.1
Client create a request to AI service
Module: app_api.app_api
Class:AudioCraftAppAPI
Function:call
Line number: 198
1.2
Service validation
Module: app_api.app_api
Class:AudioCraftAppAPI
Function:call
Line number: 205
1.3
Create workflow with workflow_id (task_id)
Module: app_api.app_api
Class:AudioCraftAppAPI
Function:call:
Line number: 223
1.4
Response to client status of request
Module: app_api.app_api
Class:AudioCraftAppAPI
Function:call:
Line number: 227
1.5
Sen request to AudioGen API
Module: app_api.app_api
Class:AudioCraftWorkFlow
Function:trigger_request_text2audio:
Line number: 132
1.6
Create a task and push to task queue
Module: audio_core_api.audio_core_api
Class:AudioGenerationAPI
Function:api_generate_audio
Line number: 66
1.7
AudioGen worker pull task and perform
Module: audio_core_api.audio_gen_worker
Class:AudioGenerationSerivce
Function:run
Line number: 28
1.8
Execute callback
Module: audio_core_api.audio_gen_worker
Class:AudioGenerationSerivceCallback
Function:run
Line number: 104
1.9
Store media file on S3 storage
Module: audio_core_api.audio_gen_worker
Class:AudioGenerationSerivce
Function:run
Line number: 54
1.10
Store temporary result on Redis
Module: audio_core_api.audio_gen_worker
Class:AudioGenerationSerivce
Function:run
Line number: 74
1.11
Aggregate final result
Module: app_api.app_api
Class:AudioCraftWorkFlow
Function:trigger_text2audio_callback
Line number: 145
1.12
Store final result on Redis
Module: app_api.app_api
Class:AudioCraftWorkFlow
Function:trigger_text2audio_callback
Line number: 147
1.13
Store request information in database
Module: app_api.app_api
Class:AudioCraftWorkFlow
Function:process_result
Line number: 103
1.14
Execute client callback
Module: app_api.app_api
Class:AudioCraftWorkFlow
Function:process_result
Line number: 94
Table 3. Description of sequence diagram and executable code in source code
No.
Description
Executable code
Note
2.1
Client create a request to to get result based on task_id
Module: app_api.app_api
Class:AudioCraftAppAPI
Function:result
Line number: 235
2.2
Service validation
Module: app_api.app_api
Class:AudioCraftAppAPI
Function:result
Line number: 238
2.3
Retrieve workflow based on task_id (workflow uuid)
Module: app_api.app_api
Class:AudioCraftAppAPI
Function:result
Line number: 258
2.4
Get URL in S3
Module: app_api.app_api
Class:AudioCraftAppAPI
Function:result
Line number: 266
2.5
Response result to client
Module: app_api.app_api
Class:AudioCraftAppAPI
Function:result
Line number: 288
Table 4. Description of sequence diagram and executable code in source code
No.
Description
Executable code
Note
3.1
Client create a request to to get statistical information
Module: aimarket_core_app_base.app
Class:BaseAppAPI
Function:stats
Line number: 112
3.2
Service validation
Module: aimarket_core_app_base.app
Class:BaseAppAPI
Function:stats
Line number: 112
3.3
Query data in database
Module: aimarket_core_app_base.app
Class:BaseAppAPI
Function:get_results_by_user_id
Line number: 117
3.4
Response result to client
Module: aimarket_core_app_base.app
Class:BaseAppAPI
Function:stats
Line number: 120
1
RabbitMQ
rabbitmq:3.8.14-management-alpine
Opensource
2
Redis
redis:6-alpine
3
AI APP database
postgres:12-alpine
4
AI APP API
your_registry_url/your_repo:version
Self-build
5
AudioGen API
6
AudioGen worker
7
MusicGen API
8
MusicGen worker
步骤1:克隆项目
第 2 步:更新子模块
如果提供的源代码是压缩文件,请跳过以上两个步骤
步骤 3:构建镜像
编辑脚本:./scripts/build_dockerfile.sh
更新 ./version.json 中的 ECR 和版本
Build image
If no errors occur, the terminal will show
Step 4: Push image to registry
Step 4.1: Login to registry
Install awscli
Configure AWS information
For the next time, there is no need to do the above 2 steps in step 4.1 section
Get the password
Login repository: Make sure repository has been created
Step 4.2: Push docker image
Push docker image
No.
Category
Item
Required
1
Hardware
CPU
2
CPU arch
x64
3
RAM
16G
4
NVIDIA GPU
12GB
5
Storage (root)
32GB
6
Software
OS
Ubuntu 20.04 or later
7
Docker
26.x.x or later
8
Docker-compose
1.29.x or later
Step 1: Pull docker image
Step 1.1 Login registry
Do the same as step 4.1 in the package section
Step 1.2 Pull image
Step 2: Deploy service
Make a deployment directory
Create a docker-compose.yml file
Create .env file
With the .env file, all environment variables highlighted in red need to be updated
No.
Group
Variable
Default value
Required update
1
AI Service
APP_API_PORT
8007
Y
2
AUDIO_GEN_PORT
8081
Optional
3
MUSIC_GEN_PORT
8082
Optional
4
MAX_DURATION
30
Optional
5
MAX_PROMPT_LEN
100
Optional
6
CACHE_MODEL_DIR
../model_hub
NO
7
TRANSFORMERS_CACHE
/model_hub
NO
8
AUDIOCRAFT_CACHE_DIR
/model_hub
NO
9
AUDIO_GEN_MODEL
facebook/audiogen-medium
Optional
10
MUSIC_GEN_MODEL
facebook/musicgen-small
Optional
11
API_VERSION
0.1.4
Optional
12
API_NAME
AudioCraft
Optional
13
Database
POSTGRES_USER
aimarketAdmin
Optional
14
POSTGRES_PASSWORD
aimarketPassword
Optional
15
POSTGRES_DB
aimarketDb
Optional
16
S3 storage
AWS_REGION_NAME
<<SECRET>>
Y
17
AWS_ACCESS_KEY
<<SECRET>>
Y
18
AWS_SECRET_KEY
<<SECRET>>
Y
19
RabbitMQ
RABBITMQ_HOST
aimarket_rabbitmq
Optional
20
RABBITMQ_VHOST
aiqrbroker
Optional
21
RABBITMQ_USER
aiqradmin
Optional
22
RABBITMQ_PASS
aiqrPassword
Optional
23
RABBITMQ_PORT
5672
Optional
24
RABBITMQ_UI_PORT
15672
Optional
25
Redis
REDIS_HOST
aimarket_redis
Optional
26
REDIS_PORT
6379
Optional
27
REDIS_DB_NAME
0
Optional
28
MarketPlace
MARKETPLACE_TOKEN
<<SECRET>>
Y
29
MARKETPLACE_CALLBACK
<<SECRET>>
Y
Run service
Check the terminal to determine if any errors occurred. If not, Ctrl + C to stop running service
Run service in detached mode