|
@@ -3,6 +3,8 @@ package com.qmth.ops.biz.ai.client.aliyun.llm;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.qmth.boot.core.ai.model.llm.ChatRequest;
|
|
|
import com.qmth.boot.core.ai.model.llm.ChatResult;
|
|
|
+import com.qmth.boot.core.ai.model.llm.ChatRole;
|
|
|
+import com.qmth.boot.core.ai.model.llm.LlmAppType;
|
|
|
import com.qmth.boot.core.exception.ReentrantException;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.ops.biz.ai.client.ChatApiClient;
|
|
@@ -24,14 +26,23 @@ public class AliyunChatClient extends ChatApiClient {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected Headers buildHeader(Headers.Builder headerBuilder) {
|
|
|
- return headerBuilder.add(AUTH_HEADER_NAME, AUTH_HEADER_VALUE + getConfig().getSecret())
|
|
|
- .add("X-DashScope-DataInspection", "{\"input\":\"disable\", \"output\":\"disable\"}").build();
|
|
|
+ protected Headers buildHeader(Headers.Builder headerBuilder, LlmAppType appType) {
|
|
|
+ headerBuilder.add(AUTH_HEADER_NAME, AUTH_HEADER_VALUE + getConfig().getSecret());
|
|
|
+ if (appType == LlmAppType.AUTO_SCORE) {
|
|
|
+ headerBuilder.add("X-DashScope-DataInspection", "{\"input\":\"disable\", \"output\":\"disable\"}");
|
|
|
+ }
|
|
|
+ return headerBuilder.build();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected Object buildRequest(ChatRequest request) {
|
|
|
- return new AliyunChatRequest(request, getConfig().getModel());
|
|
|
+ protected Object buildRequest(ChatRequest request, LlmAppType appType) {
|
|
|
+ AliyunChatRequest chatRequest = new AliyunChatRequest(request, getConfig().getModel());
|
|
|
+ if (appType == LlmAppType.AUTO_SCORE) {
|
|
|
+ chatRequest.getParameters().put("top_p", 0.1);
|
|
|
+ } else if (appType == LlmAppType.AUTO_GENERATE_QUESTION) {
|
|
|
+ chatRequest.getParameters().put("top_p", 0.9);
|
|
|
+ }
|
|
|
+ return chatRequest;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -58,4 +69,20 @@ public class AliyunChatClient extends ChatApiClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+ ChatApiConfig config = new ChatApiConfig();
|
|
|
+ config.setSupplier("aliyun");
|
|
|
+ config.setUrl("https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation");
|
|
|
+ config.setSecret("");
|
|
|
+ config.setModel("qwen-turbo");
|
|
|
+ config.setQpm(0);
|
|
|
+ AliyunChatClient client = new AliyunChatClient(config);
|
|
|
+ ChatRequest request = new ChatRequest();
|
|
|
+ request.addMessage(ChatRole.user,
|
|
|
+ "作为高等数学科目的命题老师,请按照下列要求出1道单选试题\n" + "试题题干前用单独一行'【题干】'作为内容\n" + "试题答案前用单独一行'【答案】'作为内容\n"
|
|
|
+ + "试题答案解析前用单独一行'【解析】'作为内容\n" + "试题包含4个选项,选项内容前用单独一行'【选项】'作为内容,且每个选项前用大写英文字母开头\n"
|
|
|
+ + "请按照上述要求出1道高等数学的单选试题");
|
|
|
+ System.out.println(
|
|
|
+ new ObjectMapper().writeValueAsString(client.call(request, LlmAppType.AUTO_GENERATE_QUESTION)));
|
|
|
+ }
|
|
|
}
|