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.pswp.cn/news/895255.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/895255.shtml
英文地址,請注明出處:http://en.pswp.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…

CSS 性能優化全攻略:提升網站加載速度與流暢度

系列文章目錄 01-從零開始學CSS選擇器&#xff1a;屬性選擇器與偽類選擇器完全指南 02-避免樣式沖突&#xff1a;掌握CSS選擇器優先級與層疊規則的終極指南 03-如何精確掌控網頁布局&#xff1f;深入解析 CSS 樣式與盒模型 04-CSS 布局全面解析&#xff1a;從傳統浮動到現代 F…

自主項目面試點總結

1、許苑–OJ判題系統 技術棧&#xff1a;Spring BootSpring Cloud AlibabaRedisMybatisMQDocker 項目地址: https://github.com/xuyuan-upward/xyoj-backend-microservice 1.1、項目介紹: 一個基于微服務的OJ系統&#xff0c;具備能夠根據管理員預設的題目用例對用戶提交的代…

12.推薦系統的前沿技術

接下來我們將學習推薦系統的前沿技術。推薦系統是一個快速發展的領域&#xff0c;許多新技術和新方法不斷涌現&#xff0c;進一步提升了推薦系統的性能和效果。在這一課中&#xff0c;我們將介紹以下內容&#xff1a; 圖神經網絡&#xff08;GNN&#xff09;在推薦系統中的應用…

【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;每對卵要過兩個月長成成蟲…

Linux防火墻設置

目錄 Ubuntu防火墻&#xff08;UFW&#xff09;常用設置 1. 查看防火墻狀態 2. 開啟/關閉防火墻 3. 管理端口 4. 管理IP地址 5. 服務管理 CentOS防火墻&#xff08;firewalld&#xff09;常用設置 1. 查看防火墻狀態 2. 啟動/關閉防火墻 3. 設置開機啟動 4. 管理端口…

Git 日志查看與版本回溯

引言 在軟件開發的漫漫長路中&#xff0c;代碼就如同我們搭建軟件大廈的基石&#xff0c;而 Git 則是一位默默守護并精心管理這些基石的 “管家”。它不僅能記錄代碼的每一次變動&#xff0c;還提供了強大的日志查看和版本回溯功能&#xff0c;這些功能就像是給開發者配備了一…

針對Prompt優化的深入分析

一、針對Prompt優化的深入分析 1. 結構化設計 技術原理&#xff1a; 大語言模型&#xff08;LLMs&#xff09;本質是基于概率的序列生成器&#xff0c;結構化模板通過顯式定義輸出框架&#xff08;如角色、段落數、連接詞&#xff09;&#xff0c;利用模型的模式匹配能力&…

fps動作系統9:動畫音頻

文章目錄 動畫音頻創建音頻藍圖cue音量乘數 音效衰減衰減空間 綁定到動畫動畫序列軌道 動畫音頻 創建音頻藍圖 cue 音量乘數 音量大小 音效衰減 空間音效 衰減 空間 綁定到動畫 動畫序列 軌道 橫著的方向是有不同的軌道的&#xff0c;陰影的就是。

TensorRT【詳解】

文章目錄 1、 1、 參考&#xff1a; 1、nVidia TensorRT pytorch Docker 下載&#xff1a;https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch/tags 2、nVidia TensorRT pytorch Docker 版本講解&#xff1a;https://docs.nvidia.com/deeplearning/frameworks/py…

解決QTimer報“Timers cannot be started from another thread“錯誤

今天在Qt編程時&#xff0c;將QTimer在子線程里執行start()函數&#xff0c;遇到“Timers cannot be started from another thread”問題&#xff0c;使用了如下AI工具&#xff0c;進行查詢&#xff1a; ? ? 提示詞A&#xff1a;“C QTimer 如何跨線程” ? ? 提示詞B&#…

【AI知識點】苦澀的教訓 The Bitter Lesson by Rich Sutton(2019)

【AI論文解讀】【AI知識點】【AI小項目】【AI戰略思考】【AI日記】【讀書與思考】【AI應用】 “The Bitter Lesson” 是由 Richard Sutton&#xff08;強化學習領域的先驅之一&#xff09;提出的一個概念&#xff0c;指的是機器學習領域在長期發展過程中&#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操作系統提供一個高性能的數據庫解決方案。隨著…

VSOMEIP ROUTING應用和CLIENT應用之間交互的消息

#define VSOMEIP_ASSIGN_CLIENT 0x00 // client應用請求分配client_id #define VSOMEIP_ASSIGN_CLIENT_ACK 0x01 // routing應用返回分配的client_id #define VSOMEIP_REGISTER_APPLICATION 0x02 // client應用注冊someip應用 #…

jvm 線程監控調試

文章目錄 前言一、使用JDK工具轉儲線程文件(如jstack)1. 找到Java進程的PID:2. 使用jstack生成線程轉儲文件:3.驗證生成的線程轉儲文件:二、分析文件1.使用在線工具進行分析上傳thread-dump文件,等待解析完成2.查看分析結果總結前言 提示:使用jdk自帶工具轉儲線程監控文…

從零開始認識大語言模型(LLM)

“AI小美好——聚焦科技、商業、職場。前沿資訊&#xff0c;實用干貨&#xff0c;邂逅更美好的自己&#xff01;” 在當今數字化時代&#xff0c;語言不僅是人類交流的工具&#xff0c;更是信息傳遞的核心。隨著人工智能技術的飛速發展&#xff0c;大語言模型逐漸走進了我們的…