有時候我們會發現使用deepseek服務器,異常卡頓,這是由于多方面原因造成的,比如說訪問人數過多等。想要解決這個問題,我們可以選擇第三方平臺進行部署
第三方平臺
我們可以選擇的第三方平臺很多,比如硅基流動、秘塔搜索、百度千帆等,常見平臺官網如下
- 阿里云:https://pai.console.aliyun.com/#/quick-start/models.
- 騰訊云:https://console.cloud.tencent.com/tione/v2/aimarket/detail/deepseek series?regionld=1&detailTab=introducee
- cursor:https://cursor.com 需要cursor會員
- grok:https://groq.com/蒸餾版llama 70b,中文能力不足
- 國家超算中心:https://www.scnet.cn/ui/mall/
- 硅基流動:https://siliconflow.cn/zh-cn/models
我們以硅基流動為例來介紹第三方平臺部署
部署
-
打卡硅基流動官網,我們可以看到他可以使用的模型
-
我們以V3模型為例來進行部署,點擊第一行第二個模型,他會出現模型的詳情信息
-
我們可以在線體檢,也可以看api文檔進行部署,我們打開API文檔,在左側我們可以看到它支持的接口
,右側就是相關的例子了
-
我們以創建文本對話為例來進行部署,以官網為例寫下如下代碼
import requestsurl = "https://api.siliconflow.cn/v1/chat/completions"payload = {"model": "Qwen/QwQ-32B","messages": [{"role": "user","content": "What opportunities and challenges will the Chinese large model industry face in 2025?"}],"stream": False,"max_tokens": 512,"stop": None,"temperature": 0.7,"top_p": 0.7,"top_k": 50,"frequency_penalty": 0.5,"n": 1,"response_format": {"type": "text"},"tools": [{"type": "function","function": {"description": "<string>","name": "<string>","parameters": {},"strict": False}}]
}
headers = {"Authorization": "Bearer <token>","Content-Type": "application/json"
}response = requests.request("POST", url, json=payload, headers=headers)print(response.text)
對于代碼解釋
這段代碼是使用 Python 的 requests
庫向 SiliconFlow API 發送一個 POST 請求,調用 Qwen/QwQ-32B 大語言模型,并獲取其對 “2025年中國大模型產業面臨的機遇與挑戰” 這個問題的回答。
1. 請求目標(API 端點)
url = "https://api.siliconflow.cn/v1/chat/completions"
? 這是 SiliconFlow 提供的 Chat Completions API,用于與大模型對話。
2. 請求數據(Payload)
payload = {"model": "Qwen/QwQ-32B", # 指定調用的模型"messages": [{"role": "user", # 用戶角色"content": "What opportunities and challenges will the Chinese large model industry face in 2025?" # 用戶提問}],"stream": False, # 是否流式返回(False 表示一次性返回完整回答)"max_tokens": 512, # 限制返回的最大 token 數量(防止回答過長)"temperature": 0.7, # 控制回答的隨機性(0-1,越高越有創意)"top_p": 0.7, # 控制生成多樣性(類似 temperature)"top_k": 50, # 限制采樣范圍(僅從 top_k 個最可能的 token 中選擇)"frequency_penalty": 0.5, # 降低重復內容的概率"n": 1, # 只生成 1 個回答"response_format": {"type": "text"}, # 返回純文本格式"tools": [...] # (可選)用于函數調用,但這里未實際使用
}
? model
: 指定調用的模型(這里是 Qwen/QwQ-32B)。
? messages
: 對話歷史,這里只有用戶的一條提問。
? stream
: 是否流式返回(False
表示一次性返回完整回答)。
? max_tokens
: 限制回答長度(防止過長)。
? temperature
、top_p
、top_k
: 控制回答的隨機性和多樣性。
? frequency_penalty
: 減少重復內容。
? tools
: 可用于 函數調用(Function Calling)
3. 請求頭(Headers)
headers = {"Authorization": "Bearer <token>", # 替換為你的 API Key"Content-Type": "application/json" # 告訴服務器發送的是 JSON 數據
}
? Authorization
: 需要替換 <token>
為你的 SiliconFlow API Key(否則會返回 401 未授權錯誤)。
? Content-Type
: 指定數據格式為 application/json
。
4. 發送請求
response = requests.request("POST", url, json=payload, headers=headers)
? 使用 requests.post()
發送 POST 請求,傳遞 payload
(JSON 格式)和 headers
(包含認證信息)。
5. 打印響應
print(response.text)
? 打印 API 返回的 JSON 格式 的完整響應。
對于各個參數的取值,官網會有更詳細的說明,點擊
申請API KEY
在代碼中,我們需要替換<token>
,也就是API KEY
來進行正確的調用,所以我們應該先進行申請 API KEY
-
進入申請API KEY 的頁面,并登錄
-
點擊新建API KEY
-
點擊余額充值,我們可以看到剩余的金額
-
新建好后,我們將API KEY替換,運行上面代碼,得到如下回答
{"id": "0195e27f092c94bd150980adec837ef5","object": "chat.completion","created": 1743261731,"model": "Qwen/QwQ-32B","choices": [{"index": 0,"message": {"role": "assistant","content": "","reasoning_content": "Okay, the user is asking about the opportunities and challenges the Chinese large model industry will face in 2025. Hmm, I need to break this down. First, I should consider what tools are available. The provided functions might include something like a market analysis tool or a future prediction model.\n\ nLooking at the tools given,there 's a function called \"analyze_market_trends\" which takes parameters like region, industry, and year. That seems relevant here. The user is focusing on China's large model industry,so region would be\ "China\", industry \"AI/ML\" or \"Large Language Models\", and year 2025.\n\nWait, the parameters for analyze_market_trends include region (string), industry (string), year (integer), and maybe others like specific_subsector. Since the question is about large models specifically, maybe adding \"large language models\" as the specific_subsector would help narrow it down.\n\nI should also check if there's another function called \"predict_future_impact\" which takes technology (string), region (string), timeframe (string like \"2025\"), and factors like economic, regulatory. That could cover both opportunities and challenges by considering different factors.\n\nSo combining both functions might give a comprehensive answer. First use analyze_market_trends to get market trends in China's AI/ML sector focusing on large models by 2025. Then use predict_future_impact to look at technological, economic, regulatory factors affecting them.\n\nWait but the user's question is about opportunities and challenges specifically. The functions might already capture that in their outputs. Let me make sure each function's parameters are correctly filled. For analyze_market_trends: region China, industry \"AI/ML\", year 2025, specific_subsector \"large language models\". For predict_future_impact: technology \"large language models\", region China, timeframe \"2025\", factors including economic, regulatory, technological.\n\nI need to structure the tool calls correctly in XML tags as specified. Each tool_call should be separate. Let me format that properly.\n","tool_calls": [{"id": "0195e27f26b353d40e8c41265d8faa9f","type": "function","function": {"name": "analyze_market_trends","arguments": "{\"region\": \"China\", \"industry\": \"AI/ML\", \"year\": 2025, \"specific_subsector\": \"large language models\"}"}}]},"finish_reason": "tool_calls"}],"usage": {"prompt_tokens": 140,"completion_tokens": 512,"total_tokens": 652},"system_fingerprint": ""
}