Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
lmp_server
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lmp
lmp_server
Commits
56c6e197
Commit
56c6e197
authored
May 09, 2024
by
pengxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
模型部署服务新增接口。
parent
68d7baf3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
2 deletions
+135
-2
ModelConstant.java
...in/java/com/yice/webadmin/app/constant/ModelConstant.java
+14
-0
ModelDeployController.java
...m/yice/webadmin/app/controller/ModelDeployController.java
+0
-1
ModelInstanceController.java
...yice/webadmin/app/controller/ModelInstanceController.java
+121
-1
No files found.
application-webadmin/src/main/java/com/yice/webadmin/app/constant/ModelConstant.java
View file @
56c6e197
...
...
@@ -10,4 +10,18 @@ public class ModelConstant {
*/
public
static
final
Integer
DEPLOY_STATUS
=
3
;
/**
* 部署状态:成功
*/
public
static
final
Integer
DEPLOY_STATUS_COMPLETE
=
1
;
/**
* 部署状态:部署中
*/
public
static
final
Integer
DEPLOY_STATUS_DEPLOYED
=
0
;
/**
* 部署状态:失败
*/
public
static
final
Integer
DEPLOY_STATUS_FAILURE
=
-
1
;
}
application-webadmin/src/main/java/com/yice/webadmin/app/controller/ModelDeployController.java
View file @
56c6e197
...
...
@@ -166,7 +166,6 @@ public class ModelDeployController {
ModelDeploy
modelDeploy
=
MyModelUtil
.
copyTo
(
modelDeployDto
,
ModelDeploy
.
class
);
ModelDeploy
originalModelDeploy
=
modelDeployService
.
getById
(
modelDeploy
.
getDeployId
());
if
(
originalModelDeploy
==
null
)
{
// NOTE: 修改下面方括号中的话述
errorMessage
=
"数据验证失败,当前 [数据] 并不存在,请刷新后重试!"
;
return
ResponseResult
.
error
(
ErrorCodeEnum
.
DATA_NOT_EXIST
,
errorMessage
);
}
...
...
application-webadmin/src/main/java/com/yice/webadmin/app/controller/ModelInstanceController.java
View file @
56c6e197
...
...
@@ -12,10 +12,15 @@ import com.yice.common.core.util.MyModelUtil;
import
com.yice.common.core.util.MyPageUtil
;
import
com.yice.common.log.annotation.OperationLog
;
import
com.yice.common.log.model.constant.SysOperationLogType
;
import
com.yice.webadmin.app.config.LlmModelConfig
;
import
com.yice.webadmin.app.config.OtherConfig
;
import
com.yice.webadmin.app.config.PythonConfig
;
import
com.yice.webadmin.app.constant.ModelConstant
;
import
com.yice.webadmin.app.dto.ModelInstanceDto
;
import
com.yice.webadmin.app.model.ModelInstance
;
import
com.yice.webadmin.app.model.ModelVersion
;
import
com.yice.webadmin.app.service.ModelInstanceService
;
import
com.yice.webadmin.app.service.ModelVersionService
;
import
com.yice.webadmin.app.service.ProxyPythonService
;
import
com.yice.webadmin.app.vo.ModelInstanceVo
;
import
io.swagger.annotations.Api
;
...
...
@@ -25,6 +30,7 @@ import org.springframework.web.bind.annotation.*;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 模型实例管理操作控制器类。
...
...
@@ -44,13 +50,20 @@ public class ModelInstanceController {
private
ProxyPythonService
proxyPythonService
;
@Autowired
private
OtherConfig
otherConfig
;
@Autowired
private
LlmModelConfig
llmModelConfig
;
@Autowired
private
PythonConfig
pythonConfig
;
@Autowired
private
ModelVersionService
modelVersionService
;
/**
* 新增知识图谱管理数据。
*
* @param modelInstanceDto 新增对象。
* @return 应答结果对象,包含新增对象主键Id。
*/
@ApiOperationSupport
(
ignoreParameters
=
{
"modelInstanceDto.
deploy
Id"
})
@ApiOperationSupport
(
ignoreParameters
=
{
"modelInstanceDto.
instance
Id"
})
@OperationLog
(
type
=
SysOperationLogType
.
ADD
)
@PostMapping
(
"/add"
)
public
ResponseResult
<
Long
>
add
(
@MyRequestBody
ModelInstanceDto
modelInstanceDto
)
{
...
...
@@ -73,6 +86,113 @@ public class ModelInstanceController {
return
ResponseResult
.
success
(
modelInstance
.
getInstanceId
());
}
/**
* 停止指定LLM模型。
*
* @return 应答结果对象,包含查询结果集。
*/
@PostMapping
(
"/stop"
)
public
ResponseResult
<
String
>
stop
(
@MyRequestBody
ModelInstanceDto
modelInstanceDto
)
{
ModelInstance
modelInstance
=
modelInstanceService
.
getById
(
modelInstanceDto
.
getInstanceId
());
ResponseResult
<
String
>
responseResult
=
this
.
doStop
(
modelInstance
);
if
(
responseResult
.
isSuccess
())
{
modelInstance
.
setDeployStatus
(
3
);
modelInstanceService
.
updateById
(
modelInstance
);
return
ResponseResult
.
success
(
responseResult
.
getData
());
}
return
responseResult
;
}
/**
* 部署指定LLM模型。
*
* @return 应答结果对象,包含查询结果集。
*/
@PostMapping
(
"/deploy"
)
public
ResponseResult
<
String
>
deploy
(
@MyRequestBody
ModelInstanceDto
modelInstanceDto
,
@MyRequestBody
String
type
)
{
ModelInstance
modelInstance
=
modelInstanceService
.
getById
(
modelInstanceDto
.
getInstanceId
());
modelInstance
.
setDeployStatus
(
ModelConstant
.
DEPLOY_STATUS_DEPLOYED
);
modelInstanceService
.
updateById
(
modelInstance
);
ResponseResult
<
String
>
responseResult
=
this
.
doReloadOrStart
(
modelInstance
,
type
);
if
(
responseResult
.
isSuccess
())
{
modelInstance
.
setDeployStatus
(
ModelConstant
.
DEPLOY_STATUS_COMPLETE
);
modelInstanceService
.
updateById
(
modelInstance
);
return
ResponseResult
.
success
(
responseResult
.
getData
());
}
modelInstance
.
setDeployStatus
(
ModelConstant
.
DEPLOY_STATUS_FAILURE
);
modelInstanceService
.
updateById
(
modelInstance
);
return
responseResult
;
}
/**
* 调用Python模型方法
* @param modelInstance 模型实例
* @param type 类型
* @return 消息
*/
private
ResponseResult
<
String
>
doReloadOrStart
(
ModelInstance
modelInstance
,
String
type
)
{
String
gps_ids
=
JSON
.
parseArray
(
modelInstance
.
getResourceInfo
()).
stream
()
.
map
(
obj
->
((
JSONObject
)
obj
).
getString
(
"gpu_id"
))
.
collect
(
Collectors
.
joining
(
","
));
ModelVersion
modelVersion
=
this
.
modelVersionService
.
getById
(
modelInstance
.
getVersionId
());
String
requestBody
=
"{\n"
+
" \"new_model_name\": \""
+
modelInstance
.
getVersionName
()
+
"\",\n"
+
" \"new_model_path\": \""
+
modelVersion
.
getModelUrl
()
+
"\",\n"
+
" \"startup_param\": {\n"
+
" \"gpu_ids\": \""
+
gps_ids
+
"\"\n"
+
" },\n"
+
" \"controller_address\": \""
+
pythonConfig
.
getControllerAddress
()
+
"\"\n"
+
"}"
;
try
{
String
apiName
=
type
.
equals
(
"start"
)
?
llmModelConfig
.
getStart
()
:
llmModelConfig
.
getReload
();
String
result
=
proxyPythonService
.
predictPost
(
llmModelConfig
.
getLlmModelInterface
()
+
apiName
,
requestBody
);
JSONObject
jo
=
JSON
.
parseObject
(
result
);
Integer
code
=
jo
.
getIntValue
(
"code"
);
String
msg
=
jo
.
getString
(
"msg"
);
String
data
=
jo
.
getString
(
"data"
);
if
(
code
!=
null
&&
code
==
200
)
{
return
ResponseResult
.
success
(
data
);
}
else
{
return
ResponseResult
.
create
(
ErrorCodeEnum
.
SERVER_INTERNAL_ERROR
,
msg
,
data
);
}
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
/**
* 模型停止,调用python接口
* @param modelInstance 模型实例
* @return 消息
*/
private
ResponseResult
<
String
>
doStop
(
ModelInstance
modelInstance
)
{
String
errorMessage
=
MyCommonUtil
.
getModelValidationError
(
modelInstance
,
true
);
if
(
errorMessage
!=
null
)
{
return
ResponseResult
.
error
(
ErrorCodeEnum
.
DATA_VALIDATED_FAILED
,
errorMessage
);
}
String
requestBody
=
"{\n"
+
" \"model_name\": \""
+
modelInstance
.
getVersionName
()
+
"\",\n"
+
" \"controller_address\": \""
+
pythonConfig
.
getControllerAddress
()
+
"\"\n"
+
"}"
;
try
{
String
result
=
proxyPythonService
.
predictPost
(
llmModelConfig
.
getLlmModelInterface
()
+
llmModelConfig
.
getStop
(),
requestBody
);
JSONObject
jo
=
JSON
.
parseObject
(
result
);
Integer
code
=
jo
.
getIntValue
(
"code"
);
String
msg
=
jo
.
getString
(
"msg"
);
String
data
=
jo
.
getString
(
"data"
);
if
(
code
!=
null
&&
code
==
200
)
{
return
ResponseResult
.
success
(
data
);
}
else
{
return
ResponseResult
.
create
(
ErrorCodeEnum
.
SERVER_INTERNAL_ERROR
,
msg
,
data
);
}
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
/**
* 获取GPU信息。
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment