DeepSeek模型R1服务器繁忙,怎么解决?

在当今科技飞速发展的时代,人工智能领域不断涌现出令人瞩目的创新成果,其中DeepSeek模型无疑成为了众多关注焦点。它凭借着先进的技术和卓越的性能,在行业内掀起了一股热潮,吸引了无数目光。然而,如同许多前沿技术在发展初期所面临的挑战一样,DeepSeek模型在实际应用中也暴露出了一系列亟待解决的问题,这些问题犹如一道道屏障,限制了其更广泛的应用和深入的发展。而讯飞开放平台,凭借其强大的实力和丰富的经验,正致力于为解决这些痛点提供全面而有效的解决方案。

首先,服务不稳定是DeepSeek模型当前面临的一个突出问题。在实际应用中,用户对于服务的稳定性有着极高的要求。无论是企业的生产运营,还是个人的日常使用,都希望能够获得持续、稳定的服务支持。然而,DeepSeek模型由于各种因素的影响,时常出现服务波动的情况,这给用户带来了极大的困扰。比如,在进行重要任务处理时,突然的服务中断可能导致数据丢失、工作延误等一系列严重后果。讯飞开放平台深知服务稳定性的重要性,通过优化自身的技术架构和服务体系,采用先进的云计算技术和分布式存储方案,确保平台的高可用性和可靠性。同时,讯飞还建立了完善的监控和预警机制,能够实时监测服务的运行状态,及时发现并解决潜在的问题,为用户的使用提供了坚实的保障。

HTTP调用源代码:
 

package day;import com.google.gson.Gson;
import org.json.JSONArray;
import org.json.JSONObject;import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;public class MaasApiClient {public static Gson gson = new Gson();public static void main(String[] args) {try {URL url = new URL("http://maas-api.cn-huabei-1.xf-yun.com/v1/chat/completions");HttpURLConnection connection = (HttpURLConnection) url.openConnection();// 设置请求头connection.setRequestMethod("POST");connection.setRequestProperty("Content-Type", "application/json");connection.setRequestProperty("Authorization", "Bearer ");connection.setDoOutput(true);connection.setChunkedStreamingMode(0); // 啓用分塊傳輸// 构建JSON请求体JSONObject requestBody = new JSONObject();requestBody.put("model", "xdeepseekr1");JSONArray messages = new JSONArray();JSONObject message = new JSONObject();message.put("role", "user");message.put("content", "你是谁?");messages.put(message);requestBody.put("messages", messages);requestBody.put("temperature", 0.01);requestBody.put("stream", true);requestBody.put("max_tokens", 4096);// 发送请求try (OutputStream os = connection.getOutputStream()) {byte[] input = requestBody.toString().getBytes(StandardCharsets.UTF_8);os.write(input, 0, input.length);}// 处理流式返回try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {String line;while ((line = reader.readLine()) != null) {// System.out.println(line);if (!line.contains("[DONE]")) {line = line.replace("data: ", "");// System.out.println(line);JsonParse jsonParse = gson.fromJson(line, JsonParse.class);if (!line.isEmpty()) {List<Choices> choicesList = jsonParse.choices;for (Choices temp : choicesList) {System.out.print(temp.delta.reasoning_content);}}}}}connection.disconnect();} catch (Exception e) {e.printStackTrace();}}
}class JsonParse {List<Choices> choices;
}class Choices {Delta delta;
}class Delta {String reasoning_content;
}

Webscoket调用源代码:

package org.example;import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import okhttp3.*;import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;public class BigModelNew extends WebSocketListener {// 以下信息从服务管控页面获取:https://training.xfyun.cn/modelServicepublic static final String hostUrl = "wss://maas-api.cn-huabei-1.xf-yun.com/v1.1/chat"; // 服务地址public static final String appid = "";public static final String apiSecret = "";public static final String apiKey = "";public static final String patch_id = "0";    //调用微调大模型时必传,否则不传。对应为模型服务卡片上的resourceIdpublic static final String domain = "xdeepseekr1";    //从服务管控获取要访问服务的serviceID:https://training.xfyun.cn/modelServicepublic static List<RoleContent> historyList = new ArrayList<>(); // 对话历史存储集合public static String totalAnswer = ""; // 大模型的答案汇总  你是满血671b版本吗// 环境治理的重要性  环保  人口老龄化  我爱我的祖国 你是谁 明天合肥的天气 我的名字叫大王 我叫什么名字// 点评一下安徽的发展和经济,以及工资和发展的差距,说的要直接,可以public static String NewQuestion = "";public static final Gson gson = new Gson();// 个性化参数private String userId;private Boolean wsCloseFlag;private static Boolean totalFlag = true; // 控制提示用户是否输入// 构造函数public BigModelNew(String userId, Boolean wsCloseFlag) {this.userId = userId;this.wsCloseFlag = wsCloseFlag;}// 主函数public static void main(String[] args) throws Exception {// 个性化参数入口,如果是并发使用,可以在这里模拟while (true) {if (totalFlag) {Scanner scanner = new Scanner(System.in);System.out.print("我:");totalFlag = false;NewQuestion = scanner.nextLine();// 构建鉴权urlString authUrl = getAuthUrl(hostUrl, apiKey, apiSecret);OkHttpClient client = new OkHttpClient.Builder().build();String url = authUrl.toString().replace("http://", "ws://").replace("https://", "wss://");Request request = new Request.Builder().url(url).build();for (int i = 0; i < 1; i++) {totalAnswer = "";WebSocket webSocket = client.newWebSocket(request, new BigModelNew(i + "", false));}} else {Thread.sleep(200);}}}public static boolean canAddHistory() {  // 由于历史记录最大上线1.2W左右,需要判断是能能加入历史int history_length = 0;for (RoleContent temp : historyList) {history_length = history_length + temp.content.length();}if (history_length > 12000) {historyList.remove(0);historyList.remove(1);historyList.remove(2);historyList.remove(3);historyList.remove(4);return false;} else {return true;}}// 线程来发送音频与参数class MyThread extends Thread {private WebSocket webSocket;public MyThread(WebSocket webSocket) {this.webSocket = webSocket;}public void run() {try {JSONObject requestJson = new JSONObject();String[] arr = new String[1];arr[0] = patch_id;JSONObject header = new JSONObject();  // header参数header.put("app_id", appid);header.put("uid", UUID.randomUUID().toString().substring(0, 10));header.put("patch_id", arr);JSONObject parameter = new JSONObject(); // parameter参数JSONObject chat = new JSONObject();chat.put("domain", domain); //调用微调大模型时,对应为模型服务卡片上的serviceidchat.put("temperature", 0.5);chat.put("max_tokens", 4096);  //请根据不同模型支持范围,适当调整该值的大小parameter.put("chat", chat);JSONObject payload = new JSONObject(); // payload参数JSONObject message = new JSONObject();JSONArray text = new JSONArray();// 历史问题获取if (historyList.size() > 0) {for (RoleContent tempRoleContent : historyList) {text.add(JSON.toJSON(tempRoleContent));}}// 最新问题RoleContent roleContent = new RoleContent();roleContent.role = "user";roleContent.content = NewQuestion;text.add(JSON.toJSON(roleContent));historyList.add(roleContent);message.put("text", text);payload.put("message", message);requestJson.put("header", header);requestJson.put("parameter", parameter);requestJson.put("payload", payload);System.err.println(requestJson); // 可以打印看每次的传参明细webSocket.send(requestJson.toString());// 等待服务端返回完毕后关闭while (true) {// System.err.println(wsCloseFlag + "---");Thread.sleep(200);if (wsCloseFlag) {break;}}webSocket.close(1000, "");} catch (Exception e) {e.printStackTrace();}}}@Overridepublic void onOpen(WebSocket webSocket, Response response) {super.onOpen(webSocket, response);System.out.print("大模型:");MyThread myThread = new MyThread(webSocket);myThread.start();}@Overridepublic void onMessage(WebSocket webSocket, String text) {// System.out.println(userId + "用来区分那个用户的结果" + text);JsonParse myJsonParse = gson.fromJson(text, JsonParse.class);if (myJsonParse.header.code != 0) {System.out.println("发生错误,错误码为:" + myJsonParse.header.code);System.out.println("本次请求的sid为:" + myJsonParse.header.sid);webSocket.close(1000, "");}List<Text> textList = myJsonParse.payload.choices.text;for (Text temp : textList) {System.out.print(temp.content);totalAnswer = totalAnswer + temp.content;}if (myJsonParse.header.status == 2) {// 可以关闭连接,释放资源System.out.println();System.out.println("*************************************************************************************");if (canAddHistory()) {RoleContent roleContent = new RoleContent();roleContent.setRole("assistant");roleContent.setContent(totalAnswer);historyList.add(roleContent);} else {historyList.remove(0);RoleContent roleContent = new RoleContent();roleContent.setRole("assistant");roleContent.setContent(totalAnswer);historyList.add(roleContent);}wsCloseFlag = true;totalFlag = true;}}@Overridepublic void onFailure(WebSocket webSocket, Throwable t, Response response) {super.onFailure(webSocket, t, response);try {if (null != response) {int code = response.code();System.out.println("onFailure code:" + code);System.out.println("onFailure body:" + response.body().string());if (101 != code) {System.out.println("connection failed");System.exit(0);}}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}// 鉴权方法public static String getAuthUrl(String hostUrl, String apiKey, String apiSecret) throws Exception {String newUrl = hostUrl.toString().replace("ws://", "http://").replace("wss://", "https://");URL url = new URL(newUrl);// 时间SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);format.setTimeZone(TimeZone.getTimeZone("GMT"));String date = format.format(new Date());// 拼接String preStr = "host: " + url.getHost() + "\n" + "date: " + date + "\n" + "GET " + url.getPath() + " HTTP/1.1";// System.err.println(preStr);// SHA256加密Mac mac = Mac.getInstance("hmacsha256");SecretKeySpec spec = new SecretKeySpec(apiSecret.getBytes(StandardCharsets.UTF_8), "hmacsha256");mac.init(spec);byte[] hexDigits = mac.doFinal(preStr.getBytes(StandardCharsets.UTF_8));// Base64加密String sha = Base64.getEncoder().encodeToString(hexDigits);// System.err.println(sha);// 拼接String authorization = String.format("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"", apiKey, "hmac-sha256", "host date request-line", sha);// 拼接地址HttpUrl httpUrl = Objects.requireNonNull(HttpUrl.parse("https://" + url.getHost() + url.getPath())).newBuilder().//addQueryParameter("authorization", Base64.getEncoder().encodeToString(authorization.getBytes(StandardCharsets.UTF_8))).//addQueryParameter("date", date).//addQueryParameter("host", url.getHost()).//build();//System.err.println(httpUrl.toString());return httpUrl.toString();}//返回的json结果拆解class JsonParse {Header header;Payload payload;}class Header {int code;int status;String sid;}class Payload {Choices choices;}class Choices {List<Text> text;}class Text {String role;String content;}class RoleContent {String role;String content;public String getRole() {return role;}public void setRole(String role) {this.role = role;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/895255.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

AIGC-微头条爆款文案创作智能体完整指令(DeepSeek,豆包,千问,Kimi,GPT)

Unity3D特效百例案例项目实战源码Android-Unity实战问题汇总游戏脚本-辅助自动化Android控件全解手册再战Android系列Scratch编程案例软考全系列Unity3D学习专栏蓝桥系列AIGC(GPT、DeepSeek、豆包、千问、Kimi)👉关于作者 专注于Android/Unity和各种游戏开发技巧,以及各种资…

[LLM面试题] 指示微调(Prompt-tuning)与 Prefix-tuning区别

一、提示调整(Prompt Tuning) Prompt Tuning是一种通过改变输入提示语&#xff08;input prompt&#xff09;以获得更优模型效果的技术。举个例子&#xff0c;如果我们想将一条英语句子翻译成德语&#xff0c;可以采用多种不同的方式向模型提问&#xff0c;如下图所示&#xf…

自主项目面试点总结

1、许苑–OJ判题系统 技术栈&#xff1a;Spring BootSpring Cloud AlibabaRedisMybatisMQDocker 项目地址: https://github.com/xuyuan-upward/xyoj-backend-microservice 1.1、项目介绍: 一个基于微服务的OJ系统&#xff0c;具备能够根据管理员预设的题目用例对用户提交的代…

【py】python安装教程(Windows系统,python3.13.2版本为例)

1.下载地址 官网&#xff1a;https://www.python.org/ 官网下载地址&#xff1a;https://www.python.org/downloads/ 2.64版本或者32位选择 【Stable Releases】&#xff1a;稳定发布版本&#xff0c;指的是已经测试过的版本&#xff0c;相对稳定。 【Pre-releases】&#…

CEF132 编译指南 MacOS 篇 - depot_tools 安装与配置 (四)

1. 引言 在 CEF132&#xff08;Chromium Embedded Framework&#xff09;的编译过程中&#xff0c;depot_tools 扮演着举足轻重的角色。这套由 Chromium 项目精心打造的脚本和工具集&#xff0c;专门用于获取、管理和更新 Chromium 及其相关项目&#xff08;包括 CEF&#xff…

1312:【例3.4】昆虫繁殖

1312&#xff1a;【例3.4】昆虫繁殖 时间限制: 1000 ms 内存限制: 65536 KB 提交数:60386 通过数: 29787 【题目描述】 科学家在热带森林中发现了一种特殊的昆虫&#xff0c;这种昆虫的繁殖能力很强。每对成虫过xx个月产yy对卵&#xff0c;每对卵要过两个月长成成虫…

单片机上SPI和IIC的区别

SPI&#xff08;Serial Peripheral Interface&#xff09;和IC&#xff08;Inter-Integrated Circuit&#xff09;是两种常用的嵌入式外设通信协议&#xff0c;它们各有优缺点&#xff0c;适用于不同的场景。以下是它们的详细对比&#xff1a; — 1. 基本概念 SPI&#xff0…

SQL Server安装流程

SQL Server 2022在安全性、可用性和性能方面不断创新&#xff0c;是现在最支持Azure的SQL Server版本。 SQL Server发展史 SQL Server的历史始于1989年&#xff0c;当时是由微软与Sybase合作的产品&#xff0c;旨在为Windows NT操作系统提供一个高性能的数据库解决方案。随着…

从零开始认识大语言模型(LLM)

“AI小美好——聚焦科技、商业、职场。前沿资讯&#xff0c;实用干货&#xff0c;邂逅更美好的自己&#xff01;” 在当今数字化时代&#xff0c;语言不仅是人类交流的工具&#xff0c;更是信息传递的核心。随着人工智能技术的飞速发展&#xff0c;大语言模型逐渐走进了我们的…

安装OpenJDK21(linux、macos)

文章目录 安装OpenJDK21java21linux下安装配置mac下安装 安装OpenJDK21 java21 封神&#xff01;Java 21正式发布了&#xff0c;迎来了史诗级新特性&#xff0c;堪称版本最强&#xff01;&#xff01;&#xff01; 视频链接&#xff1a;https://www.bilibili.com/video/BV1E8…

基于Java的自助多张图片合成拼接实战

目录 前言 一、图片合成需求描述 二、图片合成设计与实现 1、编程语言 2、基础数据准备 3、图片合成流程 4、图片合成实现 三、总结 前言 在当今数字化时代&#xff0c;图像处理技术在各个领域都发挥着至关重要的作用。从社交媒体到电子商务&#xff0c;从在线教育到虚拟…

计算机网络结课设计:通过思科Cisco进行中小型校园网搭建

上学期计算机网络课程的结课设计是使用思科模拟器搭建一个中小型校园网&#xff0c;当时花了几天时间查阅相关博客总算是做出来了&#xff0c;在验收后一直没管&#xff0c;在寒假想起来了简单分享一下&#xff0c;希望可以给有需求的小伙伴一些帮助 目录 一、设计要求 二、…

在npm上传属于自己的包

最近在整理代码&#xff0c;上传到npm方便使用&#xff0c;所以学习了如何在npm发布一个包&#xff0c;整理写成一篇文章和大家一起交流。 1、注册npm账号 npm | Home 2、确保是登录状态 &#xff08;在包目录下&#xff0c;终端执行 npm login) 按enter键自动打开页面&…

物联网(IoT)详解

物联网&#xff08;IoT&#xff09;详解 1. IoT定义简介2. IoT工作原理3. IoT关键技术4. 物联网与互联网区别5. IoT使用场景6. 开源物联网平台7. 参考资料 1. IoT定义简介 首先第一个问题&#xff0c;什么是物联网&#xff08;IoT&#xff09;? 物联网&#xff08;英文&#…

idea项目列表不出现,展示loading

2025年02月08 11:23:36 星期六 发生在webstorm中&#xff0c;跟其他idea类似 原因是将 ignore 插件升级到 4.5.5 版本 https://github.com/JetBrains/idea-gitignore/pull/933 解决方案&#xff1a;将ignore版本将为 4.5.4 我是将 4.5.5 降低为 4.5.4 正常显示文件夹了。

【Vue】在Vue3中使用Echarts的示例 两种方法

文章目录 方法一template渲染部分js部分方法一实现效果 方法二template部分js or ts部分方法二实现效果 贴个地址~ Apache ECharts官网地址 Apache ECharts示例地址 官网有的时候示例显示不出来&#xff0c;属于正常现象&#xff0c;多进几次就行 开始使用前&#xff0c;记得先…

Ollama 简单 好用 好玩

简介 Ollama https://github.com/ollama/ollama/ 是一个基于 Go 语言 的 本地大语言模型运行框架&#xff0c;专注于本地化运行大型语言模型&#xff08;LLM&#xff09;的开源工具。 类 Docker 产品&#xff08;支持 list,pull,push,run 等命令&#xff09;&#xff0c;更好玩…

储能系统-系统架构

已更新系列文章包括104、61850、modbus 、单片机等&#xff0c;欢迎关注 IEC61850实现方案和测试-1-CSDN博客 快速了解104协议-CSDN博客 104调试工具2_104协议调试工具-CSDN博客 1 电池储能系统&#xff08;BESS&#xff09; 架构 电池储能系统主要包括、电池、pcs、本地控制…

百度高德地图坐标转换

百度地图和高德地图的侧重点不太一样。同样一个地名&#xff0c;在百度地图网站上搜索到的地点可能是商业网点&#xff0c;在高德地图网站上搜索到的地点可能是自然行政地点。 高德地图api 在高德地图中&#xff0c;搜索地名&#xff0c;如“乱石头川”&#xff0c;该地名会出…

网络安全溯源 思路 网络安全原理

网络安全背景 网络就是实现不同主机之间的通讯。网络出现之初利用TCP/IP协议簇的相关协议概念&#xff0c;已经满足了互连两台主机之间可以进行通讯的目的&#xff0c;虽然看似简简单单几句话&#xff0c;就描述了网络概念与网络出现的目的&#xff0c;但是为了真正实现两台主机…