MCPcopy Create free account
hub / github.com/pollinations/pollinations / loadModels

Function loadModels

apps/chat/src/utils/api.js:78–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

76};
77
78export const loadModels = async () => {
79 if (
80 modelsCache &&
81 modelsCacheTime &&
82 Date.now() - modelsCacheTime < CACHE_DURATION
83 ) {
84 return modelsCache;
85 }
86
87 const token = getApiToken();
88 const headers = token ? { Authorization: `Bearer ${token}` } : {};
89
90 const [textRes, imageRes, audioRes] = await Promise.allSettled([
91 fetch(`${BASE_URL}/v1/models`, { headers }),
92 fetch(`${BASE_URL}/image/models`, { headers }),
93 fetch(`${BASE_URL}/audio/models`, { headers }),
94 ]);
95
96 // Text models
97 if (textRes.status === "fulfilled" && textRes.value.ok) {
98 const data = await textRes.value.json();
99 const arr = Array.isArray(data) ? data : data.data;
100 if (Array.isArray(arr)) {
101 textModels = arr.map((m) => ({
102 id: m.id || m.name || m,
103 name: m.title || getRealModelName(m.id || m.name || m),
104 description: m.description || m.id || m.name || m,
105 type: "text",
106 ownedBy: m.owned_by || "unknown",
107 created: m.created,
108 supportsVision: m.vision === true,
109 supportsAudio: m.audio === true,
110 inputModalities: m.input_modalities || ["text"],
111 outputModalities: m.output_modalities || ["text"],
112 tier: m.tier || "unknown",
113 community: m.community || false,
114 }));
115 }
116 } else {
117 textModels = [];
118 }
119
120 // Image + video models
121 if (imageRes.status === "fulfilled" && imageRes.value.ok) {
122 const data = await imageRes.value.json();
123 if (Array.isArray(data)) {
124 const all = data.map((m) => {
125 const id = typeof m === "string" ? m : m.name || m.id || m;
126 const outputMods = m.output_modalities || ["image"];
127 return {
128 id,
129 name:
130 typeof m === "object" && m.title
131 ? m.title
132 : getRealModelName(id),
133 description: m.description || id,
134 type: outputMods.includes("video") ? "video" : "image",
135 tier: m.tier || "unknown",

Callers 1

initializeModelsFunction · 0.85

Calls 4

getApiTokenFunction · 0.85
getRealModelNameFunction · 0.85
jsonMethod · 0.80
fetchFunction · 0.50

Tested by

no test coverage detected