| const express = require('express'); |
| const axios = require('axios'); |
| const bodyParser = require('body-parser'); |
|
|
| const app = express(); |
| const port = 3000; |
|
|
| app.use(bodyParser.json()); |
|
|
| app.post('/v1/chat/completions', async (req, res) => { |
| const requestBody = req.body; |
|
|
| |
| if (requestBody.model === 'llama-3.1-8b-instant') { |
| requestBody.model = 'test'; |
| } |
|
|
| try { |
| |
| const response = await axios.post('https://api.groq.com/openai/v1/chat/completions', requestBody, { |
| headers: { |
| 'Authorization': req.headers['authorization'], |
| 'Content-Type': 'application/json' |
| } |
| }); |
|
|
| |
| res.json(response.data); |
| } catch (error) { |
| |
| res.status(error.response ? error.response.status : 500).json({ |
| error: error.message, |
| details: error.response ? error.response.data : null |
| }); |
| } |
| }); |
|
|
| app.listen(port, () => { |
| console.log(`API proxy server running on port ${port}`); |
| }); |
|
|