#Trying to change from text-davinci-003 to gpt-3.5-turbo

7 messages · Page 1 of 1 (latest)

dark zealot
#

This is what I have so far i, trying to get it to work

import express from 'express';
import * as dotenv from 'dotenv';
import cors from 'cors';
import { Configuration, OpenAIApi } from 'openai';

dotenv.config();

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);

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

app.get('/', async (req, res) => {
res.status(200).send({
message: 'This is OpenAI CodeX'
})
})

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

    const response = await openai.createChatCompletion({
        model: "gpt-3.5-turbo",
        messages: `${prompt}`,
        temperature: 0.5, // Higher values means the model will take more risks.
        max_tokens: 1000, // The maximum number of tokens to generate in the completion. Most models have a context length of 2048 tokens (except for the newest models, which support 4096).
        top_p: 1, // alternative to sampling with temperature, called nucleus sampling
        frequency_penalty: 0.5, // Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
        presence_penalty: 0.5, // Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics
    })

    res.status(200).send({
        bot: response.data.choices[0].message
    })
}   catch (error) {
    console.log(error);
    res.status(500).send({ error })
}

})

app.listen(5000, () => console.log('Server is running on port http://localhost:5000'));

glossy willow
#

What error are you getting?

fleet shale
#

they have updated the format, you query chat send model and message with user and content, see updated API reference on openAI site. I just got this working but still havent played with incorporating the assistant yet which not sure why there is a user we can specify if we need the assistant to remember things but only had about 8 hours with it. https://platform.openai.com/docs/api-reference/chat/create

tepid minnow
#

I have this:

    const completion = await openai.createChatCompletion({
      model: "gpt-3.5-turbo",
      messages: [{"role": "user", "content": payload}],
      temperature: 0,
      max_tokens: 510,
      "top_p": 1
    });
    res.status(200).json({ result: completion.data.choices[0].message.content });
  } catch (error) {

Its working, but I use the node library https://www.npmjs.com/package/openai

Make sure to update to the latest version (3.2.1) of the library.

slim pecan
dark zealot
#

ill share the full code give me a second

dark zealot