Tool
OpenAI API call
A toolkit to call the Models API for OpenWebUI
Tool ID
openai_api_call
Creator
@mattismith
Downloads
167+

Tool Content
python
const express = require('express');
const bodyParser = require('body-parser');
const openai = require('openai');

const app = express();
app.use(bodyParser.json());

const openaiClient = new openai.OpenAIClient({ apiKey: 'your-api-key-here' });

app.post('/generate', async (req, res) => {
    const { prompt } = req.body;

    try {
        const response = await openaiClient.chat.completions.create({
            model: 'gpt-4',
            messages: [{ role: 'user', content: prompt }],
        });

        res.json({ response: response.choices[0].message.content });
    } catch (error) {
        res.status(500).json({ error: 'Error generating response' });
    }
});

app.listen(5000, () => {
    console.log('Server running on port 5000');
});