-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.js
30 lines (24 loc) · 842 Bytes
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Configuration, OpenAIApi } from 'openai'
import "dotenv/config"
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
})
export const openai = new OpenAIApi(configuration)
export const getCompletion = async (prompt, temperature = 0) => {
const response = await openai.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [
{ role: 'user', content: prompt },
],
temperature // Degree of randomness of the model's output
})
return response.data.choices[0].message.content
}
export const getCompletionFromMessages = async (messages, temperature = 0) => {
const response = await openai.createChatCompletion({
model: 'gpt-3.5-turbo',
messages,
temperature
})
return response.data.choices[0].message.content
}