File size: 10,326 Bytes
cafe130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Settings - Algorithmic Harmony Maestro</title>
    <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
    <link rel="stylesheet" href="style.css">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://unpkg.com/feather-icons"></script>
</head>
<body class="bg-gradient-to-br from-purple-900 via-blue-900 to-indigo-900 min-h-screen">
    <custom-navbar></custom-navbar>
    
    <main class="container mx-auto px-4 py-8 pt-20">
        <div class="max-w-4xl mx-auto">
            <h1 class="text-4xl md:text-5xl font-bold text-white text-center mb-8">
                Settings
            </h1>
            <p class="text-gray-300 text-center mb-12">
                Configure your AI API keys and preferences
            </p>

            <!-- API Settings Section -->
            <div class="glass rounded-2xl p-8 mb-8">
                <h2 class="text-2xl font-semibold text-white mb-6">AI API Configuration</h2>
                
                <div class="space-y-6">
                    <!-- DeepSeek API -->
                    <div class="bg-gray-800/30 rounded-lg p-6">
                    <h3 class="text-xl font-semibold text-white mb-4">DeepSeek API</h3>
                    <div class="space-y-4">
                        <div>
                            <label class="block text-gray-300 mb-2">DeepSeek API Key</label>
                            <input 
                                type="password" 
                                id="deepseek-api-key" 
                                placeholder="Enter your DeepSeek API key"
                                class="w-full bg-gray-700/50 border border-gray-600 rounded-lg px-4 py-3 text-white focus:outline-none focus:ring-2 focus:ring-purple-500"
                            >
                        </div>
                        <div>
                            <label class="block text-gray-300 mb-2">API Base URL</label>
                            <input 
                                type="text" 
                                id="deepseek-base-url" 
                                value="https://api.deepseek.com/v1"
                            class="w-full bg-gray-700/50 border border-gray-600 rounded-lg px-4 py-3 text-white focus:outline-none focus:ring-2 focus:ring-purple-500"
                            >
                        </div>
                        <button id="test-deepseek" class="bg-purple-600 hover:bg-purple-700 text-white px-6 py-3 rounded-lg font-semibold transition-all">
                                <i data-feather="wifi" class="inline mr-2"></i>
                            Test DeepSeek Connection
                        </button>
                    </div>
                </div>

                <!-- OpenAI/ChatGPT API -->
                <div class="bg-gray-800/30 rounded-lg p-6">
                    <h3 class="text-xl font-semibold text-white mb-4">OpenAI API</h3>
                    <div class="space-y-4">
                        <div>
                            <label class="block text-gray-300 mb-2">OpenAI API Key</label>
                        <input 
                            type="password" 
                            id="openai-api-key" 
                            placeholder="Enter your OpenAI API key"
                            class="w-full bg-gray-700/50 border border-gray-600 rounded-lg px-4 py-3 text-white focus:outline-none focus:ring-2 focus:ring-purple-500"
                        >
                    </div>
                    <div>
                        <label class="block text-gray-300 mb-2">Model Selection</label>
                        <select id="openai-model" class="w-full bg-gray-700/50 border border-gray-600 rounded-lg px-4 py-3 text-white focus:outline-none focus:ring-2 focus:ring-purple-500">
                            <option value="gpt-3.5-turbo">GPT-3.5 Turbo</option>
                            <option value="gpt-4">GPT-4</option>
                            <option value="gpt-4-turbo">GPT-4 Turbo</option>
                        </select>
                    </div>
                    <button id="test-openai" class="bg-green-600 hover:bg-green-700 text-white px-6 py-3 rounded-lg font-semibold transition-all">
                                <i data-feather="wifi" class="inline mr-2"></i>
                        Test OpenAI Connection
                    </button>
                </div>
            </div>

            <!-- API Provider Selection -->
            <div class="bg-gray-800/30 rounded-lg p-6 mb-6">
                <h3 class="text-xl font-semibold text-white mb-4">Preferred AI Provider</h3>
                <div class="space-y-3">
                    <label class="flex items-center">
                        <input type="radio" name="ai-provider" value="deepseek" class="mr-3">
                        <span class="text-gray-300">Use DeepSeek (Recommended)</span>
                    </label>
                    <label class="flex items-center">
                        <input type="radio" name="ai-provider" value="openai" class="mr-3">
                        <span class="text-gray-300">Use OpenAI</span>
                    </label>
                </div>
            </div>

            <!-- Save Settings -->
            <div class="text-center">
                <button id="save-settings" class="bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-700 hover:to-pink-700 text-white font-semibold px-8 py-4 rounded-lg transition-all transform hover:scale-105">
                    <i data-feather="save" class="inline mr-2"></i>
                    Save Settings
                </button>
            </div>
        </div>
    </main>

    <custom-footer></custom-footer>

    <script src="components/navbar.js"></script>
    <script src="components/footer.js"></script>
    <script src="script.js"></script>
    <script>
        feather.replace();
        
        // Load saved settings
        document.addEventListener('DOMContentLoaded', function() {
            const settings = JSON.parse(localStorage.getItem('ai_settings') || '{}');
            
            // Populate form fields
            document.getElementById('deepseek-api-key').value = settings.deepseekApiKey || '';
            document.getElementById('openai-api-key').value = settings.openaiApiKey || '';
            document.getElementById('openai-model').value = settings.openaiModel || 'gpt-3.5-turbo';
            
            // Set preferred provider
            const provider = settings.preferredProvider || 'deepseek';
            document.querySelector(`input[name="ai-provider"][value="${provider}"]').checked = true;
        });

        // Test DeepSeek Connection
        document.getElementById('test-deepseek').addEventListener('click', async function() {
            const apiKey = document.getElementById('deepseek-api-key').value.trim();
            if (!apiKey) {
                alert('Please enter your DeepSeek API key first!');
                return;
            }

            const originalText = this.innerHTML;
            this.innerHTML = '<i data-feather="loader" class="animate-spin inline mr-2"></i> Testing...';
            feather.replace();

            try {
                const response = await fetch('https://api.deepseek.com/v1/models', {
                    method: 'GET',
                    headers: {
                        'Authorization': `Bearer ${apiKey}`,
                        'Content-Type': 'application/json'
                    }
                });

                if (response.ok) {
                    alert('βœ… DeepSeek API connection successful!');
                } else {
                    alert('❌ DeepSeek API connection failed. Please check your API key.');
                }
            } catch (error) {
                alert('❌ Connection test failed. Please check your network connection.');
            } finally {
                this.innerHTML = originalText;
                feather.replace();
            }
        });

        // Test OpenAI Connection
        document.getElementById('test-openai').addEventListener('click', async function() {
            const apiKey = document.getElementById('openai-api-key').value.trim();
            if (!apiKey) {
                alert('Please enter your OpenAI API key first!');
                return;
            }

            const originalText = this.innerHTML;
            this.innerHTML = '<i data-feather="loader" class="animate-spin inline mr-2"></i> Testing...';
            feather.replace();

            try {
                const response = await fetch('https://api.openai.com/v1/models', {
                method: 'GET',
                headers: {
                    'Authorization': `Bearer ${apiKey}`,
                    'Content-Type': 'application/json'
                }
            });

            if (response.ok) {
                alert('βœ… OpenAI API connection successful!');
            } else {
                alert('❌ OpenAI API connection failed. Please check your API key.');
            }
        } catch (error) {
                alert('❌ Connection test failed. Please check your network connection.');
            } finally {
                this.innerHTML = originalText;
                feather.replace();
            }
        });

        // Save Settings
        document.getElementById('save-settings').addEventListener('click', function() {
                const settings = {
                    deepseekApiKey: document.getElementById('deepseek-api-key').value.trim(),
                    openaiApiKey: document.getElementById('openai-api-key').value.trim(),
                    openaiModel: document.getElementById('openai-model').value,
                    preferredProvider: document.querySelector('input[name="ai-provider"]:checked').value
                };

                localStorage.setItem('ai_settings', JSON.stringify(settings));
                alert('Settings saved successfully!');
            });
        </script>
    </body>
    </html>