GLM-5.4 and Seedance 2.5 Flash are live. Seedance adds a Character Library and 4K video on the standard 2.5 model →

Qwen 部落格

Qwen4-35B-A3B 洩露:線索、傳聞規格與發布時間
Dec 1, 2026
Qwen4
Qwen4 max

Qwen4-35B-A3B 洩露:線索、傳聞規格與發布時間

探索 Qwen4-35B-A3B 的洩露資訊、GitHub 線索、傳聞規格與發布時程,以及目前可透過 CometAPI 使用的替代模型。

如何使用 Qwen4-Max API:完整指南
Nov 23, 2026
Qwen4 max

如何使用 Qwen4-Max API:完整指南

以下示例以 Python 調用 Qwen4-Max(以 OpenAI 風格 Responses API 為例),並整合 Comet(comet-ml)做日誌與成本估算。涵蓋:首次請求、串流回覆、工具(函式)調用、圖像輸入與成本估算。 步驟 - 安裝依賴:pip install --upgrade openai comet-ml - 設定環境變數: - QWEN_API_KEY=你的API金鑰 - QWEN_BASE_URL=供應商的OpenAI相容端點(例如 https://api.your-qwen-provider.com/v1) - COMET_API_KEY=你的Comet金鑰 - COMET_WORKSPACE=你的Comet工作區 - COMET_PROJECT=你的Comet專案 Python 範例(單檔) - 檔名:qwen4_max_demo.py ```python import os import json import time from typing import Dict, Any, List # pip install --upgrade openai comet-ml from openai import OpenAI from comet_ml import Experiment # ---- 基本設定 ---- QWEN_MODEL = "qwen4-max" # 使用 OpenAI 風格的 Responses API,改用你的 Qwen 供應商 base_url client = OpenAI( api_key=os.environ.get("QWEN_API_KEY", ""), base_url=os.environ.get("QWEN_BASE_URL", "https://api.your-qwen-provider.com/v1"), ) # 建立 Comet 實驗(用於記錄) experiment = Experiment( api_key=os.environ.get("COMET_API_KEY", ""), workspace=os.environ.get("COMET_WORKSPACE"), project_name=os.environ.get("COMET_PROJECT", "qwen4-max"), disabled=False if os.environ.get("COMET_API_KEY") else True, ) # 定價(每百萬Token的美元價格;請依供應商實際公佈替換) PRICING_USD_PER_MTOK = { "input": 3.0, # 例:輸入每百萬Token 3.0 USD "output": 15.0 # 例:輸出每百萬Token 15.0 USD } def estimate_cost(usage: Dict[str, Any]) -> float: """ 根據 usage 計算粗略成本(美元)。 usage 應包含 input_tokens 與 output_tokens。 """ in_tok = usage.get("input_tokens", 0) or 0 out_tok = usage.get("output_tokens", 0) or 0 cost_in = (in_tok / 1_000_000.0) * PRICING_USD_PER_MTOK["input"] cost_out = (out_tok / 1_000_000.0) * PRICING_USD_PER_MTOK["output"] return round(cost_in + cost_out, 6) def log_to_comet( name: str, prompt: Any, response_text: str, usage: Dict[str, Any], extra: Dict[str, Any] = None ): """ 將一次請求與回覆記錄到 Comet。 """ if experiment.disabled: return # 參數與描述 experiment.log_parameters({ "model": QWEN_MODEL, "name": name }) # 輸入、輸出 experiment.log_text(f"[{name}] prompt:\n{json.dumps(prompt, ensure_ascii=False)}") experiment.log_text(f"[{name}] response:\n{response_text}") # Token 與成本 in_tok = usage.get("input_tokens", 0) or 0 out_tok = usage.get("output_tokens", 0) or 0 experiment.log_metrics({ "input_tokens": in_tok, "output_tokens": out_tok, "total_tokens": (in_tok or 0) + (out_tok or 0), "estimated_cost_usd": estimate_cost(usage) }) # 其他 if extra: experiment.log_other(f"{name}_extra", json.dumps(extra, ensure_ascii=False)) def send_first_request(): """ 發送第一個非串流請求。 """ prompt = [ { "role": "user", "content": [ {"type": "input_text", "text": "請用一句話介紹你自己。"} ] } ] resp = client.responses.create( model=QWEN_MODEL, input=prompt ) # 取出文字輸出(Responses API 提供便捷屬性) output_text = getattr(resp, "output_text", "") usage = getattr(resp, "usage", {}) or {} print("[First Request] output:") print(output_text) # 記錄至 Comet log_to_comet( name="first_request", prompt=prompt, response_text=output_text, usage=usage ) def stream_replies(): """ 串流回覆:邊接收邊輸出。 """ prompt = [ { "role": "user", "content": [ {"type": "input_text", "text": "用繁體中文,逐步解釋冒泡排序(Bubble Sort)。"} ] } ] print("[Streaming] start...") acc_text = [] with client.responses.stream( model=QWEN_MODEL, input=prompt, ) as stream: for event in stream: # 文字增量 if event.type == "response.output_text.delta": print(event.delta, end="", flush=True) acc_text.append(event.delta) # 工具調用事件(若有) elif event.type == "response.tool_call.delta": # 此處可觀察工具調用增量(若使用工具) pass elif event.type == "response.completed": print("\n[Streaming] completed.") elif event.type == "response.error": print(f"\n[Streaming] error: {event.error}") final = stream.get_final_response() output_text = "".join(acc_text) or getattr(final, "output_text", "") usage = getattr(final, "usage", {}) or {} # 記錄至 Comet log_to_comet( name="stream_replies", prompt=prompt, response_text=output_text, usage=usage ) # ---- 工具(函式)調用範例 ---- def get_weather(city: str) -> Dict[str, Any]: """ 範例工具:回傳指定城市的簡易天氣(本地假資料)。 真實情況下請調用你的天氣API。 """ sample = { "Taipei": {"temp_c": 27, "condition": "Cloudy"}, "Tokyo": {"temp_c": 24, "condition": "Rain"}, "San Francisco": {"temp_c": 18, "condition": "Fog"} } return sample.get(city, {"temp_c": 25, "condition": "Sunny"}) def use_tools(): """ 使用工具(函式調用): - 宣告 tools - 發送請求 - 接收 tool call - 執行本地函式並提交工具輸出 """ prompt = [ { "role": "user", "content": [ {"type": "input_text", "text": "請查詢台北的天氣,並用一句話回答。"} ] } ] tools = [ { "type": "function", "function": { "name": "get_weather", "description": "查詢城市天氣", "parameters": { "type": "object", "properties": { "city": {"type": "string", "description": "城市名稱,例如 Taipei"} }, "required": ["city"] } } } ] resp = client.responses.create( model=QWEN_MODEL, input=prompt, tools=tools ) # 檢查是否有工具調用 tool_calls: List[Any] = [] # 在 Responses API 中,工具調用會以結構化內容出現在輸出中 for item in getattr(resp, "output", []): for part in getattr(item, "content", []): if getattr(part, "type", "") == "tool_call": tool_calls.append(part) # 若無工具調用,直接輸出 if not tool_calls: output_text = getattr(resp, "output_text", "") usage = getattr(resp, "usage", {}) or {} print("[Use Tools] no tool call; output:") print(output_text) log_to_comet( name="use_tools_no_call", prompt=prompt, response_text=output_text, usage=usage ) return # 執行工具,收集輸出 tool_outputs = [] for tc in tool_calls: tool_name = getattr(tc, "name", "") tool_call_id = getattr(tc, "id", "") arguments = getattr(tc, "arguments", {}) or {} if tool_name == "get_weather": city = arguments.get("city", "Taipei") result = get_weather(city) tool_outputs.append({ "tool_call_id": tool_call_id, "output": json.dumps(result, ensure_ascii=False) }) # 提交工具輸出,讓模型完成回答 final = client.responses.submit_tool_outputs( response_id=resp.id, tool_outputs=tool_outputs ) output_text = getattr(final, "output_text", "") usage = getattr(final, "usage", {}) or {} print("[Use Tools] final output:") print(output_text) log_to_comet( name="use_tools", prompt=prompt, response_text=output_text, usage=usage, extra={"tool_outputs": tool_outputs} ) def use_images(): """ 多模態(圖像)輸入: - 提供圖像URL與文字說明 """ image_url = "https://example.com/sample.jpg" # 改為你的圖片 URL prompt = [ { "role": "user", "content": [ {"type": "input_text", "text": "請描述圖片中的主要物件與場景(繁體中文)。"}, {"type": "input_image", "image_url": image_url} ] } ] resp = client.responses.create( model=QWEN_MODEL, input=prompt ) output_text = getattr(resp, "output_text", "") usage = getattr(resp, "usage", {}) or {} print("[Use Images] output:") print(output_text) log_to_comet( name="use_images", prompt=prompt, response_text=output_text, usage=usage, extra={"image_url": image_url} ) def main(): print("== First request ==") send_first_request() time.sleep(0.5) print("\n== Streaming ==") stream_replies() time.sleep(0.5) print("\n== Tools ==") use_tools() time.sleep(0.5) print("\n== Images ==") use_images() print("\n== Done ==") if __name__ == "__main__": main() ``` 說明 - 以上以 OpenAI 風格 Responses API 調用方式示範,請將 base_url 設為提供 Qwen4-Max 的相容端點,並以實際可用的模型名稱替代 qwen4-max(若供應商命名不同)。 - 串流:使用 client.responses.stream(...) 逐步輸出 response.output_text.delta;完成後以 get_final_response() 取得 usage 等資訊。 - 工具:以 tools 定義 JSON-Schema;若觸發 tool_call,執行本地函式並使用 submit_tool_outputs 上傳結果,模型才會產出最終答案。 - 圖像:使用 input_image 搭配 image_url;若需本地圖片可改為 base64 串流(視供應商支援)。 - 成本估算:以 usage.input_tokens、usage.output_tokens 乘上每百萬Token價格,輸出估算值。請替換 PRICING_USD_PER_MTOK 為你的實際定價。 - Comet:示例使用 comet-ml 的 Experiment 記錄 prompt、回覆、token 與成本;請在環境中配置 COMET_API_KEY/WORKSPACE/PROJECT。

Qwen4-Max 發布:功能、基準測試、API 定價與存取指南
Nov 17, 2026
Qwen4 max

Qwen4-Max 發布:功能、基準測試、API 定價與存取指南

探索 Qwen4-Max 的功能、基準測試、API 定價與 Token Plan 選項。了解如何存取具備 1M-token 上下文窗口的 Qwen 旗艦模型。

Qwen4-Max-Preview 已發布
Nov 12, 2026
Qwen4

Qwen4-Max-Preview 已發布

Qwen4-Max-Preview 發布:Alibaba 的新一代旗艦 AI 模型,具備 1M 上下文視窗 – 完整規格、真實使用體驗、存取指南

Qwen 4 預測:發佈日期與基準測試
Nov 11, 2026
Qwen 4

Qwen 4 預測:發佈日期與基準測試

探索 Qwen 4 的發布日期預測、其在早期基準測試中的領先與模型,以及開發者在發布時應關注的內容,並評估是否應該等待。

FLUX 3 Image 與 Qwen Image 3.0:哪個 AI 圖像模型更好?
Oct 30, 2026
flux 3 image
qwen image 3.0

FLUX 3 Image 與 Qwen Image 3.0:哪個 AI 圖像模型更好?

請比較 FLUX 3 Image 與 Qwen Image 3.0 在以下方面的表現:影像品質、編輯功能、文字渲染、速度、基準測試、API 價格,以及最佳使用情境。

如何使用 Qwen Image 3.0 API:生成、編輯與定價
Oct 19, 2026
qwen image 3.0

如何使用 Qwen Image 3.0 API:生成、編輯與定價

瞭解如何使用 Qwen Image 3.0 API 搭配 CometAPI:文字轉圖像、多參考編輯、參數、程式碼與定價。

如何使用 Qwen3.8-Omni-Flash API
Oct 8, 2026
Qwen3.8 Omni Flash

如何使用 Qwen3.8-Omni-Flash API

如何使用 Qwen3.8-Omni-Flash API,搭配 Python、cURL、圖片、音訊與影片,並包含生產環境指引與 CometAPI 可用性檢查。