-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathprompt.js
164 lines (129 loc) · 5.34 KB
/
prompt.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
const prompts = [
{
name: 'DeveloperGPT',
description: 'DeveloperGPT Prompt',
prompt: 'You are DeveloperGPT, the most advanced AI developer tool on the planet. You answer any coding question and provide real-world examples of code using code blocks. Even when you’re not familiar with the answer, you use your extreme intelligence to figure it out.',
author: 'StanGirard',
},
{
name: 'BabyGPT',
description: 'Talk like a baby',
prompt: 'You are BabyGPT, the most advanced AI baby on the planet. You answer question with baby sounds that are cute and adorable. Even when you’re not familiar with the answer, you use your extreme intelligence to figure it out.',
author: 'StanGirard',
},
// Add more prompts as needed
];
function initPrompts() {
const promptList = document.getElementById('prompt-list');
if (!promptList) return;
for (const prompt of prompts) {
const listItem = document.createElement('div');
listItem.classList.add('prompt-list-item');
const promptName = document.createElement('div');
promptName.classList.add('prompt-name');
promptName.textContent = prompt.name;
listItem.appendChild(promptName);
const promptDescription = document.createElement('div');
promptDescription.classList.add('prompt-description');
promptDescription.textContent = prompt.description;
listItem.appendChild(promptDescription);
listItem.addEventListener('click', () => {
insertPromptIntoTextarea(prompt.prompt);
});
promptList.appendChild(listItem);
}
initCustomPromptForm();
}
function initCustomPrompts() {
const newCustomPromptButton = document.getElementById("new-custom-prompt-button");
if (!newCustomPromptButton) return;
newCustomPromptButton.addEventListener("click", () => {
const customPromptName = prompt("Enter a name for the custom prompt:");
if (!customPromptName) return;
const customPromptDescription = prompt("Enter a description for the custom prompt:");
if (!customPromptDescription) return;
const customPromptText = prompt("Enter the text for the custom prompt:");
if (!customPromptText) return;
const customPrompt = {
name: customPromptName,
description: customPromptDescription,
prompt: customPromptText,
};
addCustomPrompt(customPrompt);
});
}
function addCustomPrompt(customPrompt) {
const customPromptList = document.getElementById("custom-prompt-list");
if (!customPromptList) return;
const listItem = createPromptElement(customPrompt, () => {
customPromptList.removeChild(listItem);
});
customPromptList.appendChild(listItem);
}
function insertPromptIntoTextarea(promptText) {
const userInput = document.getElementById('user-input');
if (!userInput) return;
userInput.value = promptText;
}
function showCustomPromptForm() {
const formContainer = document.getElementById("custom-prompt-form-container");
if (formContainer) {
formContainer.style.display = "block";
}
}
function hideCustomPromptForm() {
const formContainer = document.getElementById("custom-prompt-form-container");
if (formContainer) {
formContainer.style.display = "none";
}
}
function submitCustomPrompt() {
const nameInput = document.getElementById("custom-prompt-name");
const descriptionInput = document.getElementById("custom-prompt-description");
const textInput = document.getElementById("custom-prompt-text");
if (nameInput && descriptionInput && textInput && nameInput.value && descriptionInput.value && textInput.value) {
addCustomPrompt({
name: nameInput.value,
description: descriptionInput.value,
prompt: textInput.value,
author: "Custom",
});
nameInput.value = "";
descriptionInput.value = "";
textInput.value = "";
}
hideCustomPromptForm();
}
function createPromptElement(prompt) {
const listItem = document.createElement('li');
listItem.classList.add('prompt-list-item');
const promptDescription = document.createElement('div');
promptDescription.classList.add('prompt-description');
promptDescription.textContent = prompt.description;
listItem.appendChild(promptDescription);
const promptName = document.createElement('div');
promptName.classList.add('prompt-name');
promptName.textContent = prompt.name;
listItem.appendChild(promptName);
listItem.addEventListener('click', () => {
insertPromptIntoTextarea(prompt.prompt);
});
return listItem;
}
function initCustomPromptForm() {
const newCustomPromptButton = document.getElementById("new-custom-prompt-button");
const customPromptSubmitButton = document.getElementById("custom-prompt-submit");
const customPromptCancelButton = document.getElementById("custom-prompt-cancel");
if (newCustomPromptButton) {
newCustomPromptButton.addEventListener("click", showCustomPromptForm);
}
if (customPromptSubmitButton) {
customPromptSubmitButton.addEventListener("click", submitCustomPrompt);
}
if (customPromptCancelButton) {
customPromptCancelButton.addEventListener("click", hideCustomPromptForm);
}
}
module.exports = {
initPrompts,
};