TASK:batch toProductImage;chatStream;

This commit is contained in:
shahaibo
2025-06-05 13:35:13 +08:00
parent f2c268683c
commit 12dbe90150
10 changed files with 210 additions and 173 deletions

View File

@@ -4271,7 +4271,7 @@ public class PythonService {
}
}
public Boolean toProductImageBatch(String url, String taskId, String prompt, BigDecimal imageStrength, String productType) {
public Boolean toProductImageBatch(String taskIdBatch, List<BatchParamDTO> paramList, String userId) {
// todo 限流校验
// AccessLimitUtils.validate("design",5);
OkHttpClient client = new OkHttpClient().newBuilder()
@@ -4283,12 +4283,9 @@ public class PythonService {
MediaType mediaType = MediaType.parse("application/json");
//关闭FastJson的引用检测 防止出现$ref 现象
Map<String, Object> map = new HashMap<>();
map.put("tasks_id", taskId);
map.put("image_url", url);
map.put("prompt", prompt);
map.put("image_strength", imageStrength);
map.put("product_type", productType);
map.put("batch_size", 1);
map.put("user_id", userId);
map.put("batch_data_list", paramList);
map.put("batch_tasks_id", taskIdBatch);
log.info("toProductImage请求python 参数:####{}", map);
String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty);
System.out.println(param);
@@ -4446,4 +4443,61 @@ public class PythonService {
log.error("PythonService##getProjectParam接口调用失败###{}", response);
throw new BusinessException("getProjectParam.interface.exception");
}
public List<String> getPrompt(String string, int num) {
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
MediaType mediaType = MediaType.parse("application/json");
Map<String, Object> content = Maps.newHashMap();
content.put("text", string);
content.put("num", num);
content.put("language", "english");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
log.info("batch_prompt_optimizer 请求地址: {}", accessPythonIp + ":" + accessPythonPort + "/api/batch_prompt_optimizer");
Request request = new Request.Builder()
.url(accessPythonIp + ":" + "10002" + "/api/batch_prompt_optimizer")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException ioException) {
log.error("PythonService##batch_prompt_optimizer异常###{}", ExceptionUtil.getThrowableList(ioException));
throw new BusinessException("batch_prompt_optimizer.interface.exception");
}
String responseBody;
if (response.isSuccessful() && response.body() != null) {
try {
responseBody = response.body().string();
JSONObject responseObject = JSON.parseObject(responseBody);
JSONObject dataObject = responseObject.getJSONObject("data");
if (dataObject != null) {
// 获取prompt_list数组
JSONArray promptArray = dataObject.getJSONArray("prompt_list");
if (promptArray != null) {
// 转换为List<String>
List<String> promptList = new ArrayList<>();
for (int i = 0; i < promptArray.size(); i++) {
promptList.add(promptArray.getString(i));
}
return promptList;
}
}
log.info("PythonService##responseObject###{}", responseObject);
return null;
} catch (IOException | JSONException e) {
log.error("PythonService##batch_prompt_optimizer异常###{}", e.getMessage());
throw new BusinessException("batch_prompt_optimizer.interface.exception");
}
}
log.error("PythonService##batch_prompt_optimizer接口调用失败###{}", response);
throw new BusinessException("batch_prompt_optimizer.interface.exception");
}
}