|
@@ -3,7 +3,9 @@ package com.tzld.piaoquan.content.understanding.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.tzld.piaoquan.content.understanding.common.base.CommonResponse;
|
|
import com.tzld.piaoquan.content.understanding.common.base.CommonResponse;
|
|
import com.tzld.piaoquan.content.understanding.common.enums.ContentTypeEnum;
|
|
import com.tzld.piaoquan.content.understanding.common.enums.ContentTypeEnum;
|
|
|
|
+import com.tzld.piaoquan.content.understanding.common.enums.ResponseFormatTypeEnum;
|
|
import com.tzld.piaoquan.content.understanding.model.param.ActionParam;
|
|
import com.tzld.piaoquan.content.understanding.model.param.ActionParam;
|
|
|
|
+import com.tzld.piaoquan.content.understanding.model.param.DeepSeekParam;
|
|
import com.tzld.piaoquan.content.understanding.model.param.GeminiParam;
|
|
import com.tzld.piaoquan.content.understanding.model.param.GeminiParam;
|
|
import com.tzld.piaoquan.content.understanding.service.Action;
|
|
import com.tzld.piaoquan.content.understanding.service.Action;
|
|
import com.tzld.piaoquan.content.understanding.util.HttpClientUtil;
|
|
import com.tzld.piaoquan.content.understanding.util.HttpClientUtil;
|
|
@@ -22,16 +24,17 @@ import java.util.concurrent.ThreadLocalRandom;
|
|
@Service(value = "deepSeekGenerateContentAction")
|
|
@Service(value = "deepSeekGenerateContentAction")
|
|
public class DeepSeekGenerateContentAction implements Action {
|
|
public class DeepSeekGenerateContentAction implements Action {
|
|
|
|
|
|
- @Value("${ai.deepSeekApi.url:http://ai-api-internal.piaoquantv.com/aigc-server/deepseek/native/chat/completions}")
|
|
|
|
|
|
+ @Value("${ai.deepSeekApi.url:http://ai-api-internal.piaoquantv.com/aigc-server/deepseek/generateContent}")
|
|
private String deepSeekApiUrl;
|
|
private String deepSeekApiUrl;
|
|
|
|
|
|
- @Value("#{'${deepseek.apikey.list}'.split(',')}")
|
|
|
|
|
|
+ @Value("#{'${deepseek.apikey.list:[]}'.split(',')}")
|
|
private List<String> apiKeyList;
|
|
private List<String> apiKeyList;
|
|
|
|
|
|
private static final HttpPoolClient httpPoolClient = HttpClientUtil.create(3000, 900000, 50, 200, 0, 3000);
|
|
private static final HttpPoolClient httpPoolClient = HttpClientUtil.create(3000, 900000, 50, 200, 0, 3000);
|
|
|
|
|
|
- private static final String MODEL = "gemini-2.0-flash";
|
|
|
|
- private static final Double TEMPERATURE = 1.0;
|
|
|
|
|
|
+ public static final String MODEL_CHAT = "deepseek-chat";
|
|
|
|
+ public static final String MODEL_REASONER = "deepseek-reasoner";
|
|
|
|
+ public static final Double TEMPERATURE = 1.0;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public String execute(ActionParam param) {
|
|
public String execute(ActionParam param) {
|
|
@@ -44,13 +47,15 @@ public class DeepSeekGenerateContentAction implements Action {
|
|
ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
int index = random.nextInt(apiKeyList.size());
|
|
int index = random.nextInt(apiKeyList.size());
|
|
String apiKey = apiKeyList.get(index);
|
|
String apiKey = apiKeyList.get(index);
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
|
- headers.put("Content-Type", "application/json");
|
|
|
|
- Map<String, Object> paramMap = new HashMap<>();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- log.info("deepSeekGenerateContentAction paramMap = {}", JSON.toJSONString(paramMap));
|
|
|
|
- Optional<String> optionalS = httpPoolClient.postJson(deepSeekApiUrl, JSON.toJSONString(paramMap), headers);
|
|
|
|
|
|
+ DeepSeekParam deepSeekParam = new DeepSeekParam();
|
|
|
|
+ deepSeekParam.setApiKey(apiKey);
|
|
|
|
+ deepSeekParam.setPrompt(param.getPrompt());
|
|
|
|
+ deepSeekParam.setModel(MODEL_REASONER);
|
|
|
|
+ deepSeekParam.setTemperature(TEMPERATURE);
|
|
|
|
+ //reasonser模型不支持 json format
|
|
|
|
+// deepSeekParam.setResponseFormat(ResponseFormatTypeEnum.JSON.getValue());
|
|
|
|
+ log.info("deepSeekGenerateContentAction deepSeekParam = {}", JSON.toJSONString(deepSeekParam));
|
|
|
|
+ Optional<String> optionalS = httpPoolClient.postJson(deepSeekApiUrl, JSON.toJSONString(deepSeekParam));
|
|
log.info("deepSeekGenerateContentAction optionalS = {}", optionalS);
|
|
log.info("deepSeekGenerateContentAction optionalS = {}", optionalS);
|
|
if (optionalS.isPresent()) {
|
|
if (optionalS.isPresent()) {
|
|
CommonResponse<Map<String, Object>> commonResponse = JSON.parseObject(optionalS.get(), CommonResponse.class);
|
|
CommonResponse<Map<String, Object>> commonResponse = JSON.parseObject(optionalS.get(), CommonResponse.class);
|