-
Notifications
You must be signed in to change notification settings - Fork 13
/
setup.js
38 lines (30 loc) · 963 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
31
32
33
34
35
36
37
38
import { Configuration, OpenAIApi } from 'openai'
import { OpenAI } from "langchain/llms/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
}
export const model = new OpenAI(
{
temperature: 0,
}
)