Spaces:
Runtime error
Runtime error
File size: 7,739 Bytes
ddac6a2 2316bca fa4edd5 2316bca fa4edd5 5def997 ddac6a2 fa4edd5 2316bca fa4edd5 2316bca fa4edd5 ddac6a2 fa4edd5 2316bca fa4edd5 ddac6a2 fa4edd5 2316bca fa4edd5 5def997 fa4edd5 5def997 fa4edd5 ddac6a2 fa4edd5 2316bca d2876cb 2316bca fa4edd5 4218b1b fa4edd5 ddac6a2 5def997 |
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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
import { useState } from 'react';
function Settings({
profiles,
activeProfileId,
onSaveProfiles,
onChangeActiveProfile,
onCloseSettings,
onSaveSummarizationProfile,
summarizationProfile
}) {
const [localProfiles, setLocalProfiles] = useState(profiles);
const [localSummarizationProfile, setLocalSummarizationProfile] = useState(summarizationProfile || {
id: 'default-summarization-profile',
apiEndpoint: '',
apiKey: '',
model: 'DeepSeek-R1'
});
const [editingProfileId, setEditingProfileId] = useState(activeProfileId);
const [isHintExpanded, setIsHintExpanded] = useState(false);
const editingProfile = localProfiles.find(p => p.id === editingProfileId) || localProfiles[0];
const editingSummarizationProfile = localSummarizationProfile;
const handleProfileChange = (updatedProfile) => {
setLocalProfiles(localProfiles.map(p =>
p.id === updatedProfile.id ? updatedProfile : p
));
};
const handleSummarizationProfileChange = (updatedProfile) => {
setLocalSummarizationProfile(updatedProfile);
};
const handleAddProfile = () => {
const newId = `profile-${Date.now()}`;
const newProfile = {
id: newId,
name: `New Profile ${localProfiles.length + 1}`,
apiEndpoint: '',
apiKey: '',
model: 'DeepSeek-R1'
};
const updatedProfiles = [...localProfiles, newProfile];
setLocalProfiles(updatedProfiles);
setEditingProfileId(newId);
};
const handleDeleteProfile = (profileId) => {
if (localProfiles.length <= 1) {
alert("Cannot delete the last profile");
return;
}
const updatedProfiles = localProfiles.filter(p => p.id !== profileId);
setLocalProfiles(updatedProfiles);
if (editingProfileId === profileId) {
setEditingProfileId(updatedProfiles[0].id);
}
};
const handleSubmit = (e) => {
e.preventDefault();
onSaveProfiles(localProfiles);
onSaveSummarizationProfile(localSummarizationProfile);
onChangeActiveProfile(editingProfileId);
onCloseSettings();
};
return (
<div className="settings-panel">
<h2>Settings</h2>
<div className="profiles-section">
<div className="profiles-header">
<h3>Chat Profiles</h3>
<button
type="button"
className="add-profile-button"
onClick={handleAddProfile}
>
+ Add Profile
</button>
</div>
<div className="profiles-list">
{localProfiles.map(profile => (
<div
key={profile.id}
className={`profile-item ${profile.id === editingProfileId ? 'active' : ''}`}
onClick={() => setEditingProfileId(profile.id)}
>
<span>{profile.name}</span>
{localProfiles.length > 1 && (
<button
className="delete-profile-button"
onClick={(e) => {
e.stopPropagation();
handleDeleteProfile(profile.id);
}}
>
×
</button>
)}
</div>
))}
</div>
</div>
<form onSubmit={handleSubmit}>
{editingProfile && (
<div className="current-profile-section">
<h3>Edit Chat Profile: {editingProfile.name}</h3>
<div className="setting-item">
<label>Profile Name:</label>
<input
type="text"
value={editingProfile.name}
onChange={(e) => handleProfileChange({
...editingProfile,
})}
placeholder="Enter profile name"
/>
</div>
<div className="setting-item">
<label>API Endpoint:</label>
<input
type="text"
value={editingProfile.apiEndpoint}
onChange={(e) => handleProfileChange({
...editingProfile,
apiEndpoint: e.target.value
})}
placeholder="Enter API endpoint"
/>
<div className="setting-hint">
<button
type="button"
className="hint-toggle"
onClick={() => setIsHintExpanded(!isHintExpanded)}
>
{isHintExpanded ? 'Hide' : 'Show'} API Endpoint Format Examples
</button>
<div className={`hint-content ${isHintExpanded ? 'expanded' : ''}`}>
<p>API Endpoint format examples:</p>
<ul>
<li>Ends with / → /chat/completions will be appended</li>
<li>Ends with # → # will be removed</li>
<li>Other cases → /v1/chat/completions will be appended</li>
</ul>
</div>
</div>
</div>
<div className="setting-item">
<label>API Key:</label>
<input
type="password"
value={editingProfile.apiKey}
onChange={(e) => handleProfileChange({
...editingProfile,
apiKey: e.target.value
})}
placeholder="Enter your API key"
/>
</div>
<div className="setting-item">
<label>Model:</label>
<input
type="text"
value={editingProfile.model}
onChange={(e) => handleProfileChange({
...editingProfile,
model: e.target.value
})}
placeholder="Enter model name (e.g., DeepSeek-R1)"
/>
</div>
</div>
)}
<div className="profiles-section">
<h3>Summarization Profile</h3>
<div className="current-profile-section">
<div className="setting-item">
<label>API Endpoint:</label>
<input
type="text"
value={localSummarizationProfile.apiEndpoint}
onChange={(e) => handleSummarizationProfileChange({
...localSummarizationProfile,
apiEndpoint: e.target.value
})}
placeholder="Enter API endpoint"
/>
</div>
<div className="setting-item">
<label>API Key:</label>
<input
type="password"
value={localSummarizationProfile.apiKey}
onChange={(e) => handleSummarizationProfileChange({
...localSummarizationProfile,
apiKey: e.target.value
})}
placeholder="Enter your API key"
/>
</div>
<div className="setting-item">
<label>Model:</label>
<input
type="text"
value={localSummarizationProfile.model}
onChange={(e) => handleSummarizationProfileChange({
...localSummarizationProfile,
model: e.target.value
})}
placeholder="Enter model name (e.g., DeepSeek-R1)"
/>
</div>
</div>
</div>
<div className="settings-actions">
<button type="submit" className="save-button">Save Settings</button>
<button type="button" className="cancel-button" onClick={onCloseSettings}>Cancel</button>
</div>
</form>
</div>
);
}
export default Settings;
|