gpts: allow no api key

This commit is contained in:
end-4
2025-04-06 17:37:05 +02:00
parent 885c4b9679
commit 3dc0a61acc
4 changed files with 19 additions and 4 deletions
@@ -20,6 +20,7 @@
// "description": "A model added by the user",
// "base_url": "http://localhost:11434/v1/chat/completions",
// "key_get_url": "",
// "requires_key": false,
// "key_file": "api_key_file.txt",
// "model": "model-name"
// },
+12 -3
View File
@@ -216,7 +216,9 @@ export const OpenaiApiKeyInstructions = () => Box({
transitionDuration: userOptions.animations.durationLarge,
setup: (self) => self
.hook(GPTService, (self, hasKey) => {
self.revealChild = (GPTService.key.length == 0);
self.revealChild = (
GPTService.providers[GPTService.providerID]["requires_key"]
&& GPTService.key.length == 0);
}, 'hasKey')
,
child: Button({
@@ -259,6 +261,11 @@ export const chatContent = Box({
if (!message) return;
box.add(ChatMessage(message, `Model (${GPTService.providers[GPTService.providerID]['name']})`))
}, 'newMsg')
.hook(GPTService, (self, hasKey) => {
self.revealChild = (
GPTService.providers[GPTService.providerID]["requires_key"]
&& GPTService.key.length == 0);
}, 'providerChanged')
,
});
@@ -291,9 +298,11 @@ export const chatGPTCommands = Box({
export const sendMessage = (text) => {
// Check if text or API key is empty
if (text.length == 0) return;
if (GPTService.key.length == 0) {
if (GPTService.providers[GPTService.providerID]["requires_key"]
&& GPTService.key.length == 0
&& !text.startsWith('/key')) {
GPTService.key = text;
chatContent.add(SystemMessage(`Key saved to\n\`${GPTService.keyPath}\``, 'API Key', ChatGPTView));
chatContent.add(SystemMessage(`Key saved to \`${GPTService.keyPath}\`\nUpdate anytime with \`/key YOUR_API_KEY\`.`, 'API Key', ChatGPTView));
text = '';
return;
}
+1 -1
View File
@@ -220,7 +220,7 @@ export const sendMessage = (text) => {
if (text.length == 0) return;
if (GeminiService.key.length == 0) {
GeminiService.key = text;
chatContent.add(SystemMessage(`Key saved to\n\`${GeminiService.keyPath}\``, 'API Key', GeminiView));
chatContent.add(SystemMessage(`Key saved to \`${GeminiService.keyPath}\`\nUpdate anytime with /key YOUR_API_KEY.`, 'API Key', GeminiView));
text = '';
return;
}