Niansuh commited on
Commit
251d9dc
1 Parent(s): c6cdd7d

Create routes/api.js

Browse files
Files changed (1) hide show
  1. routes/api.js +34 -0
routes/api.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const router = express.Router();
3
+ const { openaiCompatibleEndpoints } = require('../config');
4
+
5
+ // Get available endpoints
6
+ router.get('/endpoints', (req, res) => {
7
+ res.json(openaiCompatibleEndpoints);
8
+ });
9
+
10
+ // Test endpoint with chat model (basic playground)
11
+ router.post('/playground', async (req, res) => {
12
+ const { endpoint, apiKey, modelName, message } = req.body;
13
+
14
+ // Dummy example for testing a response structure
15
+ try {
16
+ const response = await fetch(endpoint, {
17
+ method: 'POST',
18
+ headers: {
19
+ 'Content-Type': 'application/json',
20
+ 'Authorization': `Bearer ${apiKey}`
21
+ },
22
+ body: JSON.stringify({
23
+ model: modelName,
24
+ messages: [{ role: 'user', content: message }]
25
+ })
26
+ });
27
+ const data = await response.json();
28
+ res.json(data);
29
+ } catch (err) {
30
+ res.status(500).json({ error: 'Failed to connect to the model' });
31
+ }
32
+ });
33
+
34
+ module.exports = router;