snippets_js
Integration
New integration from credential
const openai = yepcode.integration.openai('credential-slug');
New integration from plain authentication data
const OpenAI = require('openai');
const openai = new OpenAI({
apiKey: "OPENAI_API_KEY"
});
Completions
Create completion
const completion = await openai.completions.create({
model: 'gpt-3.5-turbo',
prompt: 'Say this is a test',
max_tokens: 7,
temperature: 0,
});
console.log(completion.choices[0].text);
Chat
Create chat completion
const completion = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{role: "user", content: 'Hello World'}],
});
console.log(completion.choices[0].message);
Models
List models
const models = await openai.models.list();
console.log(models)
Images
Create image
const response = await openai.images.generate({
prompt: 'A cute baby sea otter',
n: 2,
size: '1024x1024',
});
console.log(response.data)