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
c24eb727
Commit
c24eb727
authored
Dec 01, 2023
by
linpeiqin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加python请求代理接口
parent
35842abb
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
115 additions
and
5 deletions
+115
-5
PythonConfig.java
.../main/java/com/yice/webadmin/app/config/PythonConfig.java
+8
-0
WebClientConfig.java
...in/java/com/yice/webadmin/app/config/WebClientConfig.java
+12
-0
ProxyController.java
...ava/com/yice/webadmin/app/controller/ProxyController.java
+81
-0
TuningRunController.java
...com/yice/webadmin/app/controller/TuningRunController.java
+6
-5
application-dev.yml
application-webadmin/src/main/resources/application-dev.yml
+4
-0
pom.xml
pom.xml
+4
-0
No files found.
application-webadmin/src/main/java/com/yice/webadmin/app/config/PythonConfig.java
View file @
c24eb727
...
...
@@ -23,4 +23,12 @@ public class PythonConfig {
*/
private
String
datasetInfo
;
/**
* 数据集配置目录
*/
private
String
datasetFileMenu
;
/**
* python平台通用接口地址
*/
private
String
factoryInterface
;
}
application-webadmin/src/main/java/com/yice/webadmin/app/config/WebClientConfig.java
0 → 100644
View file @
c24eb727
package
com
.
yice
.
webadmin
.
app
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.reactive.function.client.WebClient
;
@Configuration
public
class
WebClientConfig
{
@Bean
public
WebClient
webClient
()
{
return
WebClient
.
create
();
}
}
application-webadmin/src/main/java/com/yice/webadmin/app/controller/ProxyController.java
0 → 100644
View file @
c24eb727
package
com
.
yice
.
webadmin
.
app
.
controller
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.yice.common.core.object.ResponseResult
;
import
com.yice.common.log.annotation.OperationLog
;
import
com.yice.common.log.model.constant.SysOperationLogType
;
import
com.yice.webadmin.app.config.PythonConfig
;
import
io.swagger.annotations.Api
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.ClientProtocolException
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.reactive.function.client.WebClient
;
import
reactor.core.publisher.Mono
;
import
java.io.IOException
;
@Api
(
tags
=
"python代理接口"
)
@Slf4j
@RestController
@RequestMapping
(
"/admin/app/python"
)
public
class
ProxyController
{
@Autowired
private
PythonConfig
pythonConfig
;
private
final
WebClient
webClient
;
public
ProxyController
(
WebClient
webClient
)
{
this
.
webClient
=
webClient
;
}
@OperationLog
(
type
=
SysOperationLogType
.
OTHER
)
@PostMapping
(
"/originalPredict"
)
public
Mono
<
String
>
originalPredict
(
@RequestBody
String
requestBody
)
throws
JsonProcessingException
{
return
webClient
.
post
()
.
uri
(
this
.
pythonConfig
.
getFactoryInterface
())
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
bodyValue
(
new
ObjectMapper
().
readTree
(
requestBody
))
.
retrieve
()
.
bodyToMono
(
String
.
class
);
}
@OperationLog
(
type
=
SysOperationLogType
.
OTHER
)
@PostMapping
(
"/predict"
)
public
ResponseResult
<
String
>
predict
(
@RequestBody
String
requestBody
)
throws
IOException
{
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
try
{
HttpPost
httpPost
=
new
HttpPost
(
this
.
pythonConfig
.
getFactoryInterface
());
httpPost
.
setHeader
(
"Content-Type"
,
"application/json"
);
httpPost
.
setEntity
(
new
StringEntity
(
requestBody
,
"UTF-8"
));
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpPost
);
try
{
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
String
result
=
EntityUtils
.
toString
(
entity
);
return
ResponseResult
.
success
(
result
);
}
}
finally
{
response
.
close
();
}
}
catch
(
ClientProtocolException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
httpClient
.
close
();
}
return
null
;
}
}
application-webadmin/src/main/java/com/yice/webadmin/app/controller/TuningRunController.java
View file @
c24eb727
...
...
@@ -13,6 +13,7 @@ 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.PythonConfig
;
import
com.yice.webadmin.app.dto.RunPublishDto
;
import
com.yice.webadmin.app.dto.TuningRunDto
;
import
com.yice.webadmin.app.model.*
;
...
...
@@ -23,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.net.URI
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -51,6 +53,8 @@ public class TuningRunController {
private
DatasetVersionService
datasetVersionService
;
@Autowired
private
DatasetManageService
datasetManageService
;
@Autowired
private
PythonConfig
pythonConfig
;
/**
* 新增精调任务运行数据。
...
...
@@ -128,7 +132,7 @@ public class TuningRunController {
array
.
add
(
false
);
array
.
add
(
"none"
);
array
.
add
(
"Supervised Fine-Tuning"
);
array
.
add
(
"lmp_data"
);
array
.
add
(
pythonConfig
.
getDatasetFileMenu
()
);
array
.
add
(
datasetVersionNames
);
array
.
add
(
jsonObject
.
get
(
"truncationLength"
));
array
.
add
(
jsonObject
.
get
(
"learningRate"
));
...
...
@@ -154,10 +158,7 @@ public class TuningRunController {
array
.
add
(
jsonObject
.
get
(
"dpoBetaData"
));
array
.
add
(
new
JSONArray
());
array
.
add
(
sdf
.
format
(
new
Date
()));
JSONObject
jsonObject1
=
new
JSONObject
();
jsonObject1
.
put
(
"data"
,
array
);
System
.
out
.
println
(
jsonObject1
.
toJSONString
());
// String test2 = "[\"zh\",\"ChatGLM3-6B-Chat\",\"/home/linking/llms/models/chatglm3-6b\",\"lora\",[\"2023-11-30-17-10-39\"],\"none\",\"chatglm3\",\"11111\",false,false,\"none\",\"Supervised Fine-Tuning\",\"data\",[\"alpaca_zh\"],1024,\"5e-5\",\"3.0\",\"100000\",\"fp16\",4,4,\"cosine\",\"1.0\",0,5,100,0,0,false,false,8,0.1,\"\",\"\",true,0.1,[],\"2023-11-30-18-46-42\"]";
System
.
out
.
println
(
array
.
toJSONString
());
return
ResponseResult
.
success
(
array
.
toJSONString
());
}
...
...
application-webadmin/src/main/resources/application-dev.yml
View file @
c24eb727
...
...
@@ -65,6 +65,10 @@ python:
datasetFileBaseDir
:
/home/linking/llms/code/LLaMA-Factory-0.3.2/lmp_data/
#数据集配置信息
datasetInfo
:
dataset_info.json
#数据集配置目录
datasetFileMenu
:
lmp_data
#python平台通用接口地址
factoryInterface
:
http://192.168.0.36:7860/run/predict
# 这里仅仅是一个第三方配置的示例,如果没有接入斯三方系统,
# 这里的配置项也不会影响到系统的行为,如果觉得多余,也可以手动删除。
third-party
:
...
...
pom.xml
View file @
c24eb727
...
...
@@ -55,6 +55,10 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-webflux
</artifactId>
</dependency>
<!-- freemarker 模板引擎模块 -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
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