Commit c24eb727 authored by linpeiqin's avatar linpeiqin

增加python请求代理接口

parent 35842abb
......@@ -23,4 +23,12 @@ public class PythonConfig {
*/
private String datasetInfo;
/**
* 数据集配置目录
*/
private String datasetFileMenu;
/**
* python平台通用接口地址
*/
private String factoryInterface;
}
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();
}
}
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;
}
}
......@@ -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());
}
......
......@@ -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:
......
......@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment