发现这个不容易百度到,说实话有了大模型后我也很少用百度了,阿里的通义千问其实叫模型服务灵积模型服务灵积 DashScope - 阿里云阿里云模型服务灵积 DashScope建立在“模型即服务”(Model-as-a-Service,MaaS)的理念基础之上,通过灵活、易用的通义大模型API接口,为AI开发者提供丰富可集成的模型能力,让AI应用开发更简单!https://dashscope.aliyun.com/登陆后在左侧可以看到有一个模型广场,不止是通义千问,有很多模型都可以调用,当然有些是要申请才能调用的。
我以通义千问为例用java来实现,大部分都是参考官方的api,详情介绍参考
java调用通义千问具体例子
package net.mbzj.utils;
import com.alibaba.dashscope.aigc.conversation.Conversation;
import com.alibaba.dashscope.aigc.conversation.ConversationParam;
import com.alibaba.dashscope.aigc.conversation.ConversationResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
public class DashscopeUtils {
public static String quickStart(String question) throws ApiException, NoApiKeyException, InputRequiredException {
Conversation conversation = new Conversation();
// String prompt = "你好";
ConversationParam param = ConversationParam
.builder()
.model(Conversation.Models.QWEN_TURBO)
.prompt(question)
.build();
ConversationResult result = conversation.call(param);
System.out.println(JsonUtils.toJson(result));
return result.getOutput().getText();
//System.out.println("模型回复:"+result.getOutput().getText());
}
public static void main(String[] args) throws InputRequiredException {
Constants.apiKey="换成自己的KEY";
try {
String question = "你好";
quickStart(question);
} catch (ApiException | NoApiKeyException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
返回的标准JSON数据
{"requestId":"02ab8328-0f03-98af-a7d7-b38c4ed79412","usage":{"input_tokens":20,"output_tokens":13,"total_tokens":33},"output":{"text":"你好!很高兴为你提供帮助。有什么我可以解答的问题吗?","finish_reason":"stop"}}
调用成功后有很多应用场景,比如接入微信客服机器人,具体体现可以扫下面的二维码。