|
|
|
|
package Tools.TestUnit;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.lang.System;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.alibaba.dashscope.aigc.generation.Generation;
|
|
|
|
|
import com.alibaba.dashscope.aigc.generation.GenerationParam;
|
|
|
|
|
import com.alibaba.dashscope.aigc.generation.GenerationResult;
|
|
|
|
|
import com.alibaba.dashscope.common.Message;
|
|
|
|
|
import com.alibaba.dashscope.common.Role;
|
|
|
|
|
import com.alibaba.dashscope.exception.ApiException;
|
|
|
|
|
import com.alibaba.dashscope.exception.InputRequiredException;
|
|
|
|
|
import com.alibaba.dashscope.exception.NoApiKeyException;
|
|
|
|
|
|
|
|
|
|
public class TestDeepSeek {
|
|
|
|
|
//两个版本
|
|
|
|
|
public static final String R1 = "deepseek-r1";
|
|
|
|
|
public static final String V3 = "deepseek-v3";
|
|
|
|
|
//接入的API KEY
|
|
|
|
|
public static final String APIKEY = "sk-01d13a39e09844038322108ecdbd1bbc";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取系统提示语
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String getSystemPrompt() {
|
|
|
|
|
String md = "D:\\dsWork\\QingLong\\PptGenerator\\md-file\\readme\\default.md";
|
|
|
|
|
return FileUtil.readUtf8String(md);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
|
|
|
|
|
Generation gen = new Generation();
|
|
|
|
|
String systemPrompt ="返回的教案内容请严格按照指定的markdown语法格式返回,用来生成ppt。需要注意:1、最开头的Title:..,Author: ... Date:... 不能省略掉,有用处。2、第一级用#,第二级用##,第二级是独立的PPT一个页,每页中的数据必须有> 开头,如果是页面中的条目,必须用 - 开头,结果不要返回图片!请仔细阅读参考格式:"+getSystemPrompt();
|
|
|
|
|
Message systemMsg = Message.builder()
|
|
|
|
|
.role(Role.SYSTEM.getValue())
|
|
|
|
|
//.content("You are a helpful assistant.")
|
|
|
|
|
.content(systemPrompt)
|
|
|
|
|
.build();
|
|
|
|
|
Message userMsg = Message.builder()
|
|
|
|
|
.role(Role.USER.getValue())
|
|
|
|
|
.content("请帮我生成一个小学数学内角和的教案,按标准格式输出。")
|
|
|
|
|
.build();
|
|
|
|
|
GenerationParam param = GenerationParam.builder()
|
|
|
|
|
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
|
|
|
|
|
.apiKey(APIKEY)
|
|
|
|
|
// 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
|
|
|
|
.model(R1)
|
|
|
|
|
.messages(Arrays.asList(systemMsg, userMsg))
|
|
|
|
|
.resultFormat(GenerationParam.ResultFormat.MESSAGE)
|
|
|
|
|
.build();
|
|
|
|
|
return gen.call(param);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
try {
|
|
|
|
|
GenerationResult result = callWithMessage();
|
|
|
|
|
String mdContent=result.getOutput().getChoices().getFirst().getMessage().getContent();
|
|
|
|
|
System.out.println(mdContent);
|
|
|
|
|
FileUtil.writeUtf8String(mdContent,"D:\\dsWork\\ppt-generator-master\\md-file\\readme\\4.md");
|
|
|
|
|
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
|
|
|
|
|
System.err.println("错误信息:" + e.getMessage());
|
|
|
|
|
System.out.println("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code");
|
|
|
|
|
}
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|