Skip to content

Commit 6318080

Browse files
author
GhzHost
committed
Enchantments AI Assistent
1 parent f98aec3 commit 6318080

File tree

9 files changed

+5178
-492
lines changed

9 files changed

+5178
-492
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEMINI_API_KEY="AIzaSyDTwFK3MYFa3HYwIu8yFDfLJ4zUYoFyMFM"

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ web_modules/
7373
.yarn-integrity
7474

7575
# dotenv environment variable files
76-
.env
7776
.env.development.local
7877
.env.test.local
7978
.env.production.local

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Um aplicativo desktop elegante e moderno para acessar os serviços da GHZHost.
1414
## Serviços Integrados
1515

1616
- Home GHZHost
17-
- MCP (Management Control Panel)
17+
- MCP (Minecraft Control Panel)
1818
- GCP (Game Control Panel)
1919
- WCP (Web Control Panel)
2020

gemini-api.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
require('dotenv').config();
2+
const { GoogleGenerativeAI } = require('@google/generative-ai');
3+
const express = require('express');
4+
const cors = require('cors');
5+
const path = require('path');
6+
7+
// Verificação da chave da API
8+
if (!process.env.GEMINI_API_KEY) {
9+
console.error('Erro: GEMINI_API_KEY não encontrada no arquivo .env');
10+
process.exit(1);
11+
}
12+
13+
// Configuração da API do Gemini
14+
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
15+
16+
// Configuração do chat com instruções do sistema
17+
const SYSTEM_PROMPT = `Você é o assistente virtual oficial da GhzHost, especializado em:
18+
- Suporte técnico para hospedagem de sites e servidores
19+
- Manutenção e gerenciamento de servidores
20+
- Configuração de serviços de hospedagem
21+
- Resolução de problemas relacionados a hosting
22+
- Recomendações sobre planos e serviços de hospedagem
23+
- Boas práticas de segurança e performance em servidores
24+
25+
Mantenha suas respostas:
26+
1. Profissionais e técnicas
27+
2. Focadas em hospedagem e servidores
28+
3. Alinhadas com os serviços da GhzHost
29+
4. Precisas e diretas
30+
5. Úteis para usuários técnicos e não técnicos
31+
32+
Se não souber algo específico sobre a GHZHost, mantenha a resposta genérica mas tecnicamente correta.`;
33+
34+
// Configuração do Express
35+
const app = express();
36+
app.use(cors());
37+
app.use(express.json());
38+
39+
// Serve arquivos estáticos
40+
app.use(express.static(path.join(__dirname)));
41+
42+
// Endpoint da API
43+
app.post('/api/chat', async (req, res) => {
44+
try {
45+
if (!process.env.GEMINI_API_KEY) {
46+
throw new Error('GEMINI_API_KEY não configurada');
47+
}
48+
49+
const { message } = req.body;
50+
const model = genAI.getGenerativeModel({ model: "gemini-2.0-flash" });
51+
52+
// Iniciar chat com o system prompt
53+
const chat = model.startChat({
54+
history: [
55+
{
56+
role: "user",
57+
parts: "Por favor, confirme suas instruções e papel como assistente da GHZHost."
58+
},
59+
{
60+
role: "model",
61+
parts: SYSTEM_PROMPT
62+
}
63+
],
64+
generationConfig: {
65+
maxOutputTokens: 1000,
66+
}
67+
});
68+
69+
// Enviar a mensagem do usuário
70+
const result = await chat.sendMessage(message);
71+
const response = await result.response;
72+
res.json({ response: response.text() });
73+
} catch (error) {
74+
console.error('Erro ao gerar resposta:', error);
75+
res.status(500).json({
76+
error: 'Erro interno do servidor',
77+
details: error.message
78+
});
79+
}
80+
});
81+
82+
// Endpoint para verificar status
83+
app.get('/api/status', (req, res) => {
84+
res.json({
85+
status: 'online',
86+
apiKeyConfigured: !!process.env.GEMINI_API_KEY
87+
});
88+
});
89+
90+
// Função para iniciar o servidor
91+
function startServer(port = 3000) {
92+
return new Promise((resolve, reject) => {
93+
try {
94+
if (!process.env.GEMINI_API_KEY) {
95+
reject(new Error('GEMINI_API_KEY não configurada no arquivo .env'));
96+
return;
97+
}
98+
99+
const server = app.listen(port, () => {
100+
console.log(`Servidor Gemini rodando na porta ${port}`);
101+
console.log('API Key configurada:', !!process.env.GEMINI_API_KEY);
102+
resolve(server);
103+
});
104+
} catch (error) {
105+
console.error('Erro ao iniciar servidor Gemini:', error);
106+
reject(error);
107+
}
108+
});
109+
}
110+
111+
module.exports = {
112+
startServer
113+
};

iagemini.html

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>GHZHost AI Assistant</title>
5+
<style>
6+
* {
7+
margin: 0;
8+
padding: 0;
9+
box-sizing: border-box;
10+
}
11+
12+
html, body {
13+
height: 100%;
14+
width: 100%;
15+
margin: 0;
16+
padding: 0;
17+
overflow: hidden;
18+
}
19+
20+
#app {
21+
display: flex;
22+
flex-direction: column;
23+
height: 100%;
24+
width: 100%;
25+
background-color: #000a20;
26+
color: #ffffff;
27+
font-family: Arial, sans-serif;
28+
position: relative;
29+
}
30+
31+
.chat-container {
32+
flex: 1;
33+
overflow-y: auto;
34+
background-color: #00233f;
35+
padding: 10px;
36+
padding-bottom: 70px; /* Maior que a altura do input-area para garantir espaço */
37+
}
38+
39+
.message {
40+
margin: 5px 0;
41+
padding: 10px;
42+
border-radius: 4px;
43+
max-width: 80%;
44+
word-break: break-word;
45+
}
46+
47+
.user-message {
48+
background-color: #00547f;
49+
margin-left: auto;
50+
}
51+
52+
.ai-message {
53+
background-color: #003366;
54+
margin-right: auto;
55+
}
56+
57+
.input-area {
58+
position: absolute;
59+
bottom: 0px;
60+
left: 0;
61+
right: 0;
62+
background-color: #00233f;
63+
border-top: 1px solid #003366;
64+
height: 100px;
65+
padding: 10px;
66+
z-index: 1000;
67+
}
68+
69+
.input-container {
70+
display: flex;
71+
align-items: center;
72+
gap: 10px;
73+
height: 40px; /* Reduzido para garantir que caiba dentro do input-area */
74+
max-width: calc(100% - 20px); /* Considerando o padding do input-area */
75+
margin: 0 auto;
76+
}
77+
78+
#messageInput {
79+
flex: 1;
80+
height: 100%;
81+
min-width: 100px; /* Garante um tamanho mínimo */
82+
max-width: calc(100% - 100px); /* Considera a largura do botão + gap */
83+
padding: 8px;
84+
border: 1px solid #00b2e8;
85+
border-radius: 4px;
86+
background-color: #001a2f;
87+
color: #ffffff;
88+
font-size: 14px;
89+
}
90+
91+
#sendButton {
92+
width: 80px;
93+
height: 100%;
94+
background-color: #00b2e8;
95+
color: #000a20;
96+
border: none;
97+
border-radius: 4px;
98+
cursor: pointer;
99+
font-weight: bold;
100+
flex-shrink: 0;
101+
white-space: nowrap;
102+
}
103+
104+
#sendButton:hover {
105+
background-color: #00547f;
106+
color: white;
107+
}
108+
109+
.typing-indicator {
110+
display: none;
111+
padding: 10px;
112+
margin: 5px 0;
113+
}
114+
115+
.typing-animation {
116+
display: flex;
117+
gap: 4px;
118+
background-color: #003366;
119+
padding: 10px;
120+
border-radius: 4px;
121+
width: fit-content;
122+
}
123+
124+
.dot {
125+
width: 6px;
126+
height: 6px;
127+
background-color: #00b2e8;
128+
border-radius: 50%;
129+
animation: bounce 1.4s infinite;
130+
}
131+
132+
.dot:nth-child(2) { animation-delay: 0.2s; }
133+
.dot:nth-child(3) { animation-delay: 0.4s; }
134+
135+
@keyframes bounce {
136+
0%, 100% { transform: translateY(0); }
137+
50% { transform: translateY(-4px); }
138+
}
139+
</style>
140+
</head>
141+
<body>
142+
<div id="app">
143+
<div class="chat-container" id="chatContainer">
144+
<div class="ai-message">
145+
Olá! Eu sou o assistente AI da GHZHost. Como posso ajudar você hoje?
146+
</div>
147+
<div class="typing-indicator" id="typingIndicator">
148+
<div class="typing-animation">
149+
<div class="dot"></div>
150+
<div class="dot"></div>
151+
<div class="dot"></div>
152+
</div>
153+
</div>
154+
</div>
155+
<div class="input-area">
156+
<div class="input-container">
157+
<input type="text" id="messageInput" placeholder="Digite sua mensagem..." />
158+
<button id="sendButton">Enviar</button>
159+
</div>
160+
</div>
161+
</div>
162+
163+
<script>
164+
const chatContainer = document.getElementById('chatContainer');
165+
const messageInput = document.getElementById('messageInput');
166+
const sendButton = document.getElementById('sendButton');
167+
const typingIndicator = document.getElementById('typingIndicator');
168+
169+
async function callGeminiAPI(message) {
170+
try {
171+
const response = await fetch('http://localhost:3000/api/chat', {
172+
method: 'POST',
173+
headers: {
174+
'Content-Type': 'application/json',
175+
},
176+
body: JSON.stringify({ message })
177+
});
178+
179+
if (!response.ok) {
180+
throw new Error('API request failed');
181+
}
182+
183+
const data = await response.json();
184+
return data.response;
185+
} catch (error) {
186+
console.error('Erro ao chamar API:', error);
187+
throw error;
188+
}
189+
}
190+
191+
async function sendMessage() {
192+
const message = messageInput.value.trim();
193+
if (!message) return;
194+
195+
// Adicionar mensagem do usuário
196+
addMessage(message, 'user');
197+
messageInput.value = '';
198+
199+
// Mostrar indicador de digitação
200+
typingIndicator.style.display = 'block';
201+
chatContainer.scrollTop = chatContainer.scrollHeight;
202+
203+
try {
204+
// Aqui será implementada a chamada para a API do Gemini
205+
const response = await callGeminiAPI(message);
206+
207+
// Esconder indicador de digitação
208+
typingIndicator.style.display = 'none';
209+
210+
// Adicionar resposta do AI
211+
addMessage(response, 'ai');
212+
} catch (error) {
213+
console.error('Erro ao chamar API:', error);
214+
typingIndicator.style.display = 'none';
215+
addMessage('Desculpe, ocorreu um erro ao processar sua mensagem.', 'ai');
216+
}
217+
}
218+
219+
function addMessage(text, type) {
220+
const messageDiv = document.createElement('div');
221+
messageDiv.className = `message ${type}-message`;
222+
messageDiv.textContent = text;
223+
chatContainer.insertBefore(messageDiv, typingIndicator);
224+
chatContainer.scrollTop = chatContainer.scrollHeight;
225+
}
226+
227+
// Event listeners
228+
sendButton.addEventListener('click', sendMessage);
229+
messageInput.addEventListener('keypress', (e) => {
230+
if (e.key === 'Enter') {
231+
sendMessage();
232+
}
233+
});
234+
</script>
235+
</body>
236+
</html>

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
<div class="tab" data-url="https://mcp.ghzhost.com/" onclick="switchTab(this)">MCP</div>
208208
<div class="tab" data-url="https://gcp.ghzhost.com/" onclick="switchTab(this)">GCP</div>
209209
<div class="tab" data-url="https://wcp-s1br.ghzhost.com/" onclick="switchTab(this)">WCP</div>
210+
<div class="tab" data-url="iagemini.html" onclick="switchTab(this)">IA</div>
210211
</div>
211212

212213
<div class="content-container" id="contentContainer">

0 commit comments

Comments
 (0)