Improve OpenRouter model lists in extensions (#5459) * fix: extensions OpenRouter model lists * fix: update JSDoc for optional mapping function parameter in fetchModelsByModality * fix: update JSDoc to clarify return type of fetchModelsByModality function * fix: encode output modality in fetchModelsByModality API request

3f72d3df80fa446bf9a9f6625306a0990037650e

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +10 -10Ignore whitespace
src/endpoints/openrouter.js+10 -10
@@ -38,11 +38,11 @@ router.post('/models/providers', async (req, res) => {
3838 * @param {string} endpoint - The API endpoint to fetch from
3939 * @param {string} inputModality - Required input modality
4040 * @param {string} outputModality - Required output modality
4141 * @param {boolean((model: any) => any) | null} [idsOnlymapFn=falsenull] - WhetherOptional tomapping returnfunction onlyto modeltransform IDsthe results
4242 * @returns {Promise<any[]>} Filtered models and/or modelmapped IDsmodels
4343 */
4444async function fetchModelsByModality(endpoint, inputModality, outputModality, idsOnlymapFn = falsenull) {
4545 const response = await fetch(`${API_OPENROUTER}${endpoint}?output_modalities=${encodeURIComponent(outputModality)}`, {
4646 method: 'GET',
4747 headers: { 'Accept': 'application/json' },
4848 });
@@ -67,12 +67,12 @@ async function fetchModelsByModality(endpoint, inputModality, outputModality, id
6767 .filter(m => m.architecture.output_modalities.includes(outputModality))
6868 .sort((a, b) => a?.id && b?.id ? a.id.localeCompare(b.id) : 0);
6969
7070 return idsOnlytypeof mapFn === 'function' ? filtered.map(m => m.idmapFn) : filtered;
7171}
7272
7373router.post('/models/multimodal', async (_req, res) => {
7474 try {
7575 const models = await fetchModelsByModality('/models', 'image', 'text', truem => m.id);
7676 return res.json(models);
7777 } catch (error) {
7878 console.error(error);
@@ -82,7 +82,7 @@ router.post('/models/multimodal', async (_req, res) => {
8282
8383router.post('/models/embedding', async (_req, res) => {
8484 try {
8585 const models = await fetchModelsByModality('/embeddings/models', 'text', 'embeddings', m => ({ id: m.id, name: m.name }));
8686 return res.json(models);
8787 } catch (error) {
8888 console.error(error);
@@ -92,8 +92,8 @@ router.post('/models/embedding', async (_req, res) => {
9292
9393router.post('/models/image', async (_req, res) => {
9494 try {
9595 const models = await fetchModelsByModality('/models', 'text', 'image', m => ({ value: m.id, text: m.name || m.id }));
96- return res.json(models.map(m => ({ value: m.id, text: m.name || m.id })));
96+ return res.json(models);
9797 } catch (error) {
9898 console.error(error);
9999 return res.sendStatus(500);
@@ -132,7 +132,7 @@ router.post('/image/generate', async (req, res) => {
132132 content: prompt,
133133 },
134134 ],
135135 modalities: ['image', 'text'],
136136 image_config: {
137137 aspect_ratio: req.body.aspect_ratio || '1:1',
138138 },