免费接入DeepSeek等多种大模型

核心代码

import cn.hutool.core.collection.CollUtil;
import com.tool4j.pasteshare.entity.params.AiParams;
import com.tool4j.pasteshare.entity.params.Message;
import com.tool4j.pasteshare.service.AiCompletionService;
import com.tool4j.pasteshare.util.deepseek.DeepSeekResult;
import com.tool4j.pasteshare.util.deepseek.DeepSeekUtil;
import com.tool4j.pasteshare.util.http.HttpUtil;
import io.reactivex.Flowable;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Service("deepSeekCompletionService")
@Slf4j
public class DeepSeekCompletionServiceImpl implements AiCompletionService {
    private static final String api = "https://api.deepseek.com/chat/completions";

    @Override
    public String completions(List<Message> messages, float temperature) {
        AiParams aiParams = new AiParams();
        aiParams.setMessages(messages);
        aiParams.setTemperature(temperature);
        return HttpUtil.post(api, aiParams, Map.of("Authorization", DeepSeekUtil.API_KEY));
    }

    @Override
    public void completionsStream(HttpServletResponse response, List<Message> messages, float temperature, Long logId, Boolean enableSearch) {
        Flowable<DeepSeekResult> flow = DeepSeekUtil.completionsStream(messages, temperature);
        flow.blockingForEach(item -> {
            List<DeepSeekResult.Choices> choices = item.getChoices();
            if (CollUtil.isNotEmpty(choices)) {
                String content = choices.get(0).getDelta().getContent();
                response.getWriter().write(content == null ? "" : content);
                response.getWriter().flush();
            }
            try {
                Thread.sleep(20);
            } catch (Exception ex) {
            }
        });
    }

}

在线版本

支持当前最强chat-4.0大模型,此外还支持通义千问、DeepSeek、文心4.0、智谱等国内主流大语言模型)国内可以直连,响应速度超快 稳定使用 点击访问
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

合理选择不同的模型可以满足不同的需求,也可以用来对比哪个模型能力更强!
快来试试吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值