-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (36 loc) · 1.3 KB
/
Copy pathindex.js
File metadata and controls
42 lines (36 loc) · 1.3 KB
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
39
40
41
42
const OpenAI = require("openai");
require('dotenv').config()
const openai = new OpenAI({
apiKey: process.env.GPT
});
run("Happy birthday jack and jill")// Low Score
run("you want some smurf frog powder?")// High Score
async function run(statment){
const gptResponse = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{
role: 'user',
content: `create new Score object with the score set to the appropriateness of the statement "${statment}" with a value between 1 and 10. 1 being very appropriate and 10 being not appropriate at all.` }],
functions:[
{
name: "createScoreObject",
parameters: {
type: "object",
properties: {
statment: {
type: "string",
description: "statement to be evaluated"
},
score: {
type: "integer"
},
},
}
}
],
function_call: { name: "createScoreObject"}
});
const functionCall = gptResponse.choices[0].message.function_call;
const json = JSON.parse(functionCall.arguments);
console.log(JSON.stringify(json));
}