-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayground.js
More file actions
124 lines (92 loc) · 3.58 KB
/
playground.js
File metadata and controls
124 lines (92 loc) · 3.58 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const readline = require('readline')
const { generateChatCompletion } = require('./controllers/chatGPTCloneController');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
function printLine() {
let output = '';
for (let i = 0; i < 50; i++) {
output += '='; // Replace '=' with the character you want to print
}
console.log('\n' + output + '\n');
}
const performChatCompleltionWithHistory = async () => {
q1 = 'What are the healthiest foods to eat every day?'
q2 = 'Make a recipe with those foods.'
q3 = 'What is the amount of kcal?'
system_role_content = "You reply as concisely as possible. If you are not sure about an answer, you will respond with \"I don't know\"."
// Q1
messages = [
{ 'role': 'system', 'content': system_role_content },
{ 'role': 'user', 'content': q1 }
]
generateChatCompletion(messages).then(response => {
console.log(response);
bot_response_1 = response
printLine()
// Q2
messages = [
{ 'role': 'system', 'content': system_role_content },
// { 'role': 'user', 'content': q1 },
// { 'role': 'assistant', 'content': bot_response_1 },
{ 'role': 'user', 'content': q2 }
]
generateChatCompletion(messages).then(response => {
console.log(response);
bot_response_2 = response
printLine()
// Q3
messages = [
{ 'role': 'system', 'content': system_role_content },
// { 'role': 'user', 'content': q1 },
// { 'role': 'assistant', 'content': bot_response_1 },
// { 'role': 'user', 'content': q2 },
// { 'role': 'assistant', 'content': bot_response_2 },
{ 'role': 'user', 'content': q3 }
]
generateChatCompletion(messages).then(response => {
console.log(response);
bot_response_3 = response
printLine()
}
)
}
)
}
)
}
const performChatCompleltionWithHistoryContinuous = () => {
rl.question("Enter System Prompt: ", async (prompt) => {
system_role_content = prompt;
if (!system_role_content || system_role_content.trim().length === 0)
system_role_content = "You reply as concisely as possible."
messages = [
{ 'role': 'system', 'content': system_role_content }
]
performChatCompleltionWithHistoryContinuousInternal(messages);
}
)
}
const performChatCompleltionWithHistoryContinuousInternal = (messages) => {
rl.question("Me: ", current_question => {
if (['exit', 'quit'].includes(current_question.toLocaleLowerCase())) {
console.log('Chat Bot: I was happy to asssist you. Bye bye!')
return
}
if (current_question.toLocaleLowerCase() == "") {
performChatCompleltionWithHistoryContinuousInternal(messages);
return
}
messages.push({ "role": "user", "content": current_question })
generateChatCompletion(messages).then(current_response => {
console.log('Chat Bot: ' + current_response);
messages.push({ "role": "assistant", "content": current_response })
performChatCompleltionWithHistoryContinuousInternal(messages);
}
)
}
)
}
//performChatCompleltionWithHistory()
performChatCompleltionWithHistoryContinuous();