通过火山引擎本地部署DeepSeek-R1

火山引擎为 DeepSeek-R1 模型提供的免费额度及相关信息如下:
1.50 万 Tokens 体验包
新用户注册火山引擎并完成实名认证后,可免费获得 50 万 Tokens 的推理额度,支持文本生成、对话、代码编写等全功能。该额度适用于 DeepSeek-R1 满血版(非蒸馏版),用完后才会开始按量计费。
2.后续计费标准
若免费额度用完,当前半价优惠期间的费用为:
输入:每 100 万 Tokens 收费 2 元
输出:每 100 万 Tokens 收费 8 元
这一价格低于 DeepSeek 官方定价,且无隐性流量限制。

1.进入火山引擎模型广场

火山引擎大模型地址: https://console.volcengine.com/ark/region:ark+cn-beijing/model?vendor=Bytedance&view=LIST_VIEW
在这里插入图片描述

2.点击API接入

在这里插入图片描述

3.进行API KEY创建,得到API KEY

在这里插入图片描述

4.创建一个Maven项目,导入依赖,以及测试用例

在这里插入图片描述

在这里插入图片描述
代码:

<dependency>
	<groupId>com.volcengine</groupId>
	<artifactId>volcengine-java-sdk-ark-runtime</artifactId>
	<version>LATEST</version>
</dependency>


package org.example;
import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionRequest;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessage;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessageRole;
import com.volcengine.ark.runtime.service.ArkService;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import org.apache.commons.lang.StringUtils;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class ChatCompletionsExample {
    static String apiKey = "你的api key";
    static ConnectionPool connectionPool = new ConnectionPool(5, 1, TimeUnit.SECONDS);
    static Dispatcher dispatcher = new Dispatcher();
    // The output time of the reasoning model is relatively long. Please increase the timeout period.
    static ArkService service = ArkService.builder().timeout(Duration.ofSeconds(1800)).connectTimeout(Duration.ofSeconds(20)).dispatcher(dispatcher).connectionPool(connectionPool).baseUrl("https://ark.cn-beijing.volces.com/api/v3").apiKey(apiKey).build();
    public static void main(String[] args) {
        System.out.println("\n[Recommended]----- streaming request -----");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您的问题:");
        String question = scanner.nextLine();
        while (!question.equals("exit")) {
            final List<ChatMessage> streamMessages = new ArrayList<>();
            final ChatMessage streamUserMessage = ChatMessage.builder().role(ChatMessageRole.USER).content(question).build();
            streamMessages.add(streamUserMessage);
            ChatCompletionRequest streamChatCompletionRequest = ChatCompletionRequest.builder()
                    .model("deepseek-r1-250120")
                    .messages(streamMessages)
                    .build();
            service.streamChatCompletion(streamChatCompletionRequest)
                    .doOnError(Throwable::printStackTrace)
                    .blockingForEach(
                            delta -> {
                                if (!delta.getChoices().isEmpty()) {
                                    if (StringUtils.isNotEmpty(delta.getChoices().get(0).getMessage().getReasoningContent())) {
                                        System.out.print(delta.getChoices().get(0).getMessage().getReasoningContent());
                                    } else {
                                        System.out.print(delta.getChoices().get(0).getMessage().getContent());
                                    }
                                }
                            }
                    );
            System.out.println("\n请输入您的问题:");
            question = scanner.nextLine();
        }
        // shutdown service after all requests is finished
        System.out.println("\n欢迎下次光临~");
        service.shutdownExecutor();
    }
}

5.测试

5.1 测试执行成功
在这里插入图片描述
5.2 输入exit执行程序退出
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值