Skip to content

Commit bd722b0

Browse files
committed
Refactor ChatBot Index component to enhance model and prompt selection with dynamic options and improved user experience
1 parent 936fdba commit bd722b0

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

resources/js/Pages/ChatBot/Index.vue

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,27 @@
1616
<label class="block text-sm font-medium text-gray-700 dark:text-gray-200">
1717
Model
1818
</label>
19-
<select v-model="selectedModel" class="mt-1 w-full p-2 border rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-200 border-gray-300 dark:border-gray-600">
20-
<option value="gpt-3.5-turbo">GPT-3.5 Turbo</option>
21-
<option value="gpt-4o-mini">GPT-4o-mini</option>
22-
<option value="gpt-4o">GPT-4o</option>
19+
<select v-model="selectedModel" :disabled="isGenerating" class="mt-1 w-full p-2 border rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-200 border-gray-300 dark:border-gray-600">
20+
<option v-for="model in modelOptions" :key="model.value" :value="model.value">
21+
{{ model.text }}
22+
</option>
2323
</select>
2424
</div>
2525
<div class="flex-1">
2626
<label class="block text-sm font-medium text-gray-700 dark:text-gray-200">
2727
Temperature
2828
</label>
29-
<input type="number" step="0.1" min="0" max="1.5" v-model="temperature" class="mt-1 w-full p-2 border rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-200 border-gray-300 dark:border-gray-600"/>
29+
<input type="number" step="0.1" min="0" max="1.5" v-model="temperature" :disabled="isGenerating" class="mt-1 w-full p-2 border rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-200 border-gray-300 dark:border-gray-600"/>
3030
</div>
3131
<!-- Prompt as Select -->
3232
<div class="flex-1">
3333
<label class="block text-sm font-medium text-gray-700 dark:text-gray-200">
3434
Prompt
3535
</label>
36-
<select v-model="prompt" class="mt-1 w-full p-2 border rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-200 border-gray-300 dark:border-gray-600">
37-
<option value="assistant">Assistant</option>
38-
<option value="grammar_correction">Grammar Correction</option>
39-
<option value="sarcastic_response">Sarcastic</option>
40-
<option value="code_explainer">Code Explainer</option>
41-
<option value="simplify_text">Simplify Text</option>
42-
<option value="code_interviewer">Code Interviewer</option>
43-
<option value="improve_code_efficiency">Improve Code</option>
44-
<option value="translator">Translation</option>
45-
<option value="psychologist">Psychologist</option>
36+
<select v-model="prompt" @change="sendPrompt" :disabled="isGenerating" class="mt-1 w-full p-2 border rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-200 border-gray-300 dark:border-gray-600">
37+
<option v-for="option in promptOptions" :key="option.value" :value="option.value">
38+
{{ option.text }}
39+
</option>
4640
</select>
4741
</div>
4842
</div>
@@ -95,7 +89,9 @@
9589
Send
9690
</button>
9791
<button @click="clearChat"
98-
class="px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600 focus:outline-none">
92+
:disabled="isGenerating"
93+
class="px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600 focus:outline-none
94+
disabled:opacity-50 disabled:cursor-not-allowed">
9995
Clear Chat
10096
</button>
10197
</div>
@@ -117,7 +113,7 @@ function renderMarkdown(text) {
117113
return marked(text || '');
118114
}
119115
120-
const selectedModel = ref("gpt-4o-mini");
116+
const selectedModel = ref("gpt-3.5-turbo");
121117
const temperature = ref(0.5);
122118
const prompt = ref("assistant");
123119
const userInput = ref("");
@@ -127,15 +123,41 @@ const chatContainer = ref(null);
127123
128124
const errorMessage = ref("");
129125
126+
const modelOptions = [
127+
{ value: "gpt-3.5-turbo", text: "GPT-3.5 Turbo" },
128+
{ value: "gpt-4o-mini", text: "GPT-4o-mini" },
129+
{ value: "gpt-4o", text: "GPT-4o" },
130+
];
131+
130132
const initialPrompts = [
131133
{ title: "Explicación de código PHP", text: "Explica cómo hacer una función recursiva en PHP." },
132-
{ title: "Resumen de 'Cien años de soledad'", text: "Haz un resumen de 'Cien años de soledad' destacando los puntos importantes." },
134+
{ title: "Resumen de 'Cien años de soledad'", text: "Haz un resumen detallado de 'Cien años de soledad' destacando los puntos importantes, personajes, trama, giros argumentales, analogias." },
133135
{ title: "Plan para una salida divertida", text: "Proporciona un plan para una salida divertida con amigos." },
134-
{ title: "Consejos para mejorar hábitos", text: "Dame consejos para mejorar mis hábitos." },
136+
{ title: "Consejos para mejorar hábitos", text: "Dame consejos solidos para mejorar mis hábitos." },
135137
{ title: "Analisis de Mushoku Tensei", text: "Has un resumen de la obra japonesa Mushoku Tensei, destacando punto importante, el protagonista, los simbolismos y los personajes"},
136138
{ title: "Guia de Estudio para Laravel", text: "Dame una guia de estudio completa paso a paso para aprender el framework laravel, desde lo mas basico hasta lo mas avanzado, con el fin de tenes los conocimientos necesarios para un entorno laboral" },
137139
];
138140
141+
const promptOptions = [
142+
{ value: "assistant", text: "Assistant" },
143+
{ value: "grammar_correction", text: "Grammar Correction" },
144+
{ value: "sarcastic_response", text: "Sarcastic" },
145+
{ value: "code_explainer", text: "Code Explainer" },
146+
{ value: "simplify_text", text: "Simplify Text" },
147+
{ value: "code_interviewer", text: "Code Interviewer" },
148+
{ value: "improve_code_efficiency", text: "Improve Code" },
149+
{ value: "translator", text: "Translation" },
150+
{ value: "psychologist", text: "Psychologist" },
151+
];
152+
153+
const sendPrompt = async () => {
154+
const selectedPrompt = initialPrompts.find(p => p.title.toLowerCase().replace(/\s+/g, '_') === prompt.value);
155+
if (selectedPrompt) {
156+
userInput.value = selectedPrompt.text;
157+
await sendMessage();
158+
}
159+
};
160+
139161
const scrollToBottom = async () => {
140162
await nextTick();
141163
if (chatContainer.value) {

0 commit comments

Comments
 (0)