-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
189 lines (173 loc) · 6.79 KB
/
Copy pathindex.html
File metadata and controls
189 lines (173 loc) · 6.79 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Maissistant</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #1a1a1a;
color: white;
}
.container {
width: 80%;
max-width: 600px;
background: #262626;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(255, 140, 0, 0.5);
display: flex;
flex-direction: column;
}
.chat-box {
height: 300px;
overflow-y: auto;
border: 1px solid #FF8C00;
border-radius: 5px;
padding: 10px;
background: #333;
}
.message {
margin-bottom: 10px;
padding: 8px;
border-radius: 5px;
max-width: 80%;
}
.user { background-color: #FF9500; align-self: flex-end; }
.ai { background-color: #FFD700; align-self: flex-start; color: black; }
.history { background-color: #555; align-self: flex-start; color: #ddd; }
textarea {
width: 100%;
height: 80px;
padding: 10px;
margin-top: 10px;
border: 1px solid #FF8C00;
border-radius: 5px;
background: #333;
color: white;
}
button {
margin-top: 10px;
padding: 10px;
border: none;
border-radius: 5px;
background-color: #FF9500;
color: white;
cursor: pointer;
}
button:hover { background-color: #FF7000; }
.options {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-top: 10px;
}
select {
width: 48%;
padding: 5px;
background: #333;
color: white;
border: 1px solid #FF8C00;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>Maissistant</h1>
<div id="chatBox" class="chat-box"></div>
<div class="options">
<select id="modelSelector">
<option value="ministral-3b-latest" selected>Ministral 3B (Lite & Éco)</option>
<option value="ministral-8b-latest">Ministral 8B (Lite & Précis)</option>
<option value="pixtral-12b">Pixtral 12B (Vision)</option>
<option value="open-mistral-nemo">Mistral Nemo</option>
<option value="codestral-latest">Codestral</option>
</select>
<select id="roleSelector">
<option value="assistant">Assistant</option>
<option value="professeur">Professeur</option>
<option value="mentor">Mentor</option>
<option value="coach">Coach</option>
<option value="custom">Personnalisé (PREMIUM)</option>
</select>
</div>
<input type="text" id="customRole" placeholder="Rôle personnalisé" style="display:none;">
<div class="options">
<select id="subjectSelector">
<option value="sport">🏅 Sport</option>
<option value="informatique">💻 Informatique</option>
<option value="business">📈 Business</option>
<option value="cuisine">🍳 Cuisine</option>
<option value="religion">🙏 Religion</option>
<option value="etudes">📚 Études</option>
<option value="custom">Personnalisé (PREMIUM)</option>
</select>
</div>
<input type="text" id="customSubject" placeholder="Sujet personnalisé" style="display:none;">
<textarea id="userInput" placeholder="A question ?"></textarea>
<button onclick="sendRequest()">! GO !</button>
<button onclick="clearChat()">🗑 Effacer</button>
</div>
<script>
async function sendRequest() {
const userInput = document.getElementById('userInput').value;
if (!userInput.trim()) return;
const selectedModel = document.getElementById('modelSelector').value;
const roleSelector = document.getElementById('roleSelector').value;
const subjectSelector = document.getElementById('subjectSelector').value;
const customRole = roleSelector === "custom" ? document.getElementById('customRole').value.trim() : roleSelector;
const customSubject = subjectSelector === "custom" ? document.getElementById('customSubject').value.trim() : subjectSelector;
chatHistory.push({ sender: "user", text: userInput });
displayMessages();
document.getElementById('userInput').value = "";
const response = await fetch('/.netlify/functions/askAI', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: userInput,
history: chatHistory,
model: selectedModel,
role: customRole || "assistant",
subject: customSubject || "général"
})
});
const data = await response.json();
const aiResponse = data.response || "Erreur dans la réponse de l'IA";
chatHistory.push({ sender: "ai", text: aiResponse });
localStorage.setItem("chatHistory", JSON.stringify(chatHistory));
displayMessages();
}
let chatHistory = JSON.parse(localStorage.getItem("chatHistory")) || [];
function displayMessages() {
const chatBox = document.getElementById("chatBox");
chatBox.innerHTML = "";
chatHistory.forEach(msg => {
const msgDiv = document.createElement("div");
msgDiv.className = `message ${msg.sender === 'ai' ? 'ai' : (msg.sender === 'user' ? 'user' : 'history')}`;
msgDiv.innerText = msg.text;
chatBox.appendChild(msgDiv);
});
chatBox.scrollTop = chatBox.scrollHeight;
}
document.getElementById("roleSelector").addEventListener("change", function() {
document.getElementById("customRole").style.display = this.value === "custom" ? "block" : "none";
});
document.getElementById("subjectSelector").addEventListener("change", function() {
document.getElementById("customSubject").style.display = this.value === "custom" ? "block" : "none";
});
function clearChat() {
chatHistory = [];
localStorage.removeItem("chatHistory");
displayMessages();
}
displayMessages();
</script>
</body>
</html>