Created
May 1, 2026 15:16
-
-
Save kaixinol/d853718b02e3c16c333f11ad85d50646 to your computer and use it in GitHub Desktop.
获取阿里云所有可用模型
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (async () => { | |
| const pages = [ | |
| "https://help.aliyun.com/zh/model-studio/text-generation-model/", | |
| "https://help.aliyun.com/zh/model-studio/compatibility-with-openai-responses-api", | |
| ]; | |
| async function fetchModels(url) { | |
| const html = await fetch(url).then((r) => r.text()); | |
| const doc = new DOMParser().parseFromString(html, "text/html"); | |
| const selectors = [ | |
| 'tbody.tbody code[data-tag="code"]', | |
| "#models code.code", | |
| ].join(","); | |
| return [...doc.querySelectorAll(selectors)] | |
| .map((el) => el.textContent.trim()) | |
| .filter(Boolean); | |
| } | |
| // 抓两个页面 | |
| const allModels = (await Promise.all(pages.map(fetchModels))).flat(); | |
| // 去重 | |
| const models = [...new Set(allModels)]; | |
| console.log("models:", models); | |
| // ====== 测试 API ====== | |
| const API_KEY = "sk-xxx"; | |
| const URL = | |
| "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"; | |
| const test = async (model) => { | |
| try { | |
| const r = await fetch(URL, { | |
| method: "POST", | |
| headers: { | |
| Authorization: `Bearer ${API_KEY}`, | |
| "Content-Type": "application/json", | |
| }, | |
| body: JSON.stringify({ | |
| model, | |
| messages: [{ role: "user", content: "ping" }], | |
| max_tokens: 1, | |
| temperature: 0, | |
| enable_thinking: false, | |
| }), | |
| }); | |
| return { model, ok: r.ok, status: r.status }; | |
| } catch { | |
| return { model, ok: false, status: "ERR" }; | |
| } | |
| }; | |
| // 并发=2 | |
| const limit = 10; | |
| const results = []; | |
| let index = 0; | |
| async function worker() { | |
| while (index < models.length) { | |
| const i = index++; | |
| results[i] = await test(models[i]); | |
| } | |
| } | |
| await Promise.all(Array.from({ length: limit }, worker)); | |
| const ok = results.filter((x) => x.ok).map((x) => x.model); | |
| const bad = results.filter((x) => !x.ok).map((x) => x.model); | |
| console.log("OK:", ok); | |
| console.log("OK CSV:", ok.join(",")); | |
| console.log("BAD:", bad); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment