MCPcopy
hub / github.com/ChatGPTNextWeb/NextChat / models

Method models

app/client/platforms/openai.ts:489–524  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

487 }
488
489 async models(): Promise<LLMModel[]> {
490 if (this.disableListModels) {
491 return DEFAULT_MODELS.slice();
492 }
493
494 const res = await fetch(this.path(OpenaiPath.ListModelPath), {
495 method: "GET",
496 headers: {
497 ...getHeaders(),
498 },
499 });
500
501 const resJson = (await res.json()) as OpenAIListModelResponse;
502 const chatModels = resJson.data?.filter(
503 (m) => m.id.startsWith("gpt-") || m.id.startsWith("chatgpt-"),
504 );
505 console.log("[Models]", chatModels);
506
507 if (!chatModels) {
508 return [];
509 }
510
511 //由于目前 OpenAI 的 disableListModels 默认为 true,所以当前实际不会运行到这场
512 let seq = 1000; //同 Constant.ts 中的排序保持一致
513 return chatModels.map((m) => ({
514 name: m.id,
515 available: true,
516 sorted: seq++,
517 provider: {
518 id: "openai",
519 providerName: "OpenAI",
520 providerType: "openai",
521 sorted: 1,
522 },
523 }));
524 }
525}
526export { OpenaiPath };

Callers

nothing calls this directly

Calls 3

pathMethod · 0.95
fetchFunction · 0.90
getHeadersFunction · 0.90

Tested by

no test coverage detected