mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-11 01:20:12 +01:00
[wip] OpenRouter: Add model providers endpoint
This commit is contained in:
parent
71e1fc91f1
commit
bfd57b66ef
@ -4,6 +4,31 @@ import { jsonParser } from '../express-common.js';
|
|||||||
export const router = express.Router();
|
export const router = express.Router();
|
||||||
const API_OPENROUTER = 'https://openrouter.ai/api/v1';
|
const API_OPENROUTER = 'https://openrouter.ai/api/v1';
|
||||||
|
|
||||||
|
router.post('/models/providers', jsonParser, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { model } = req.body;
|
||||||
|
const response = await fetch(`${API_OPENROUTER}/models/${model}/endpoints`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return res.json([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
const endpoints = data?.data?.endpoints || [];
|
||||||
|
const providerNames = endpoints.map(e => e.provider_name);
|
||||||
|
|
||||||
|
return res.json(providerNames);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return res.sendStatus(500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.post('/models/multimodal', jsonParser, async (_req, res) => {
|
router.post('/models/multimodal', jsonParser, async (_req, res) => {
|
||||||
try {
|
try {
|
||||||
// The endpoint is available without authentication
|
// The endpoint is available without authentication
|
||||||
|
Loading…
x
Reference in New Issue
Block a user