forked from Shinonome/dots-hyprland
gpts: allow no api key
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
// "description": "A model added by the user",
|
// "description": "A model added by the user",
|
||||||
// "base_url": "http://localhost:11434/v1/chat/completions",
|
// "base_url": "http://localhost:11434/v1/chat/completions",
|
||||||
// "key_get_url": "",
|
// "key_get_url": "",
|
||||||
|
// "requires_key": false,
|
||||||
// "key_file": "api_key_file.txt",
|
// "key_file": "api_key_file.txt",
|
||||||
// "model": "model-name"
|
// "model": "model-name"
|
||||||
// },
|
// },
|
||||||
|
|||||||
@@ -216,7 +216,9 @@ export const OpenaiApiKeyInstructions = () => Box({
|
|||||||
transitionDuration: userOptions.animations.durationLarge,
|
transitionDuration: userOptions.animations.durationLarge,
|
||||||
setup: (self) => self
|
setup: (self) => self
|
||||||
.hook(GPTService, (self, hasKey) => {
|
.hook(GPTService, (self, hasKey) => {
|
||||||
self.revealChild = (GPTService.key.length == 0);
|
self.revealChild = (
|
||||||
|
GPTService.providers[GPTService.providerID]["requires_key"]
|
||||||
|
&& GPTService.key.length == 0);
|
||||||
}, 'hasKey')
|
}, 'hasKey')
|
||||||
,
|
,
|
||||||
child: Button({
|
child: Button({
|
||||||
@@ -259,6 +261,11 @@ export const chatContent = Box({
|
|||||||
if (!message) return;
|
if (!message) return;
|
||||||
box.add(ChatMessage(message, `Model (${GPTService.providers[GPTService.providerID]['name']})`))
|
box.add(ChatMessage(message, `Model (${GPTService.providers[GPTService.providerID]['name']})`))
|
||||||
}, 'newMsg')
|
}, '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) => {
|
export const sendMessage = (text) => {
|
||||||
// Check if text or API key is empty
|
// Check if text or API key is empty
|
||||||
if (text.length == 0) return;
|
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;
|
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 = '';
|
text = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ export const sendMessage = (text) => {
|
|||||||
if (text.length == 0) return;
|
if (text.length == 0) return;
|
||||||
if (GeminiService.key.length == 0) {
|
if (GeminiService.key.length == 0) {
|
||||||
GeminiService.key = text;
|
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 = '';
|
text = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const PROVIDERS = Object.assign({
|
|||||||
"description": getString('Ollama - Llama-3.2'),
|
"description": getString('Ollama - Llama-3.2'),
|
||||||
"base_url": 'http://localhost:11434/v1/chat/completions',
|
"base_url": 'http://localhost:11434/v1/chat/completions',
|
||||||
"key_get_url": "",
|
"key_get_url": "",
|
||||||
|
"requires_key": false,
|
||||||
"key_file": "ollama_key.txt",
|
"key_file": "ollama_key.txt",
|
||||||
"model": "llama3.2",
|
"model": "llama3.2",
|
||||||
},
|
},
|
||||||
@@ -23,6 +24,7 @@ const PROVIDERS = Object.assign({
|
|||||||
"base_url": "http://localhost:11434/v1/chat/completions",
|
"base_url": "http://localhost:11434/v1/chat/completions",
|
||||||
"key_get_url": "",
|
"key_get_url": "",
|
||||||
"key_file": "ollama_key.txt",
|
"key_file": "ollama_key.txt",
|
||||||
|
"requires_key": false,
|
||||||
"model": "deepseek-r1",
|
"model": "deepseek-r1",
|
||||||
},
|
},
|
||||||
"ollama_gemma3": {
|
"ollama_gemma3": {
|
||||||
@@ -32,6 +34,7 @@ const PROVIDERS = Object.assign({
|
|||||||
"base_url": "http://localhost:11434/v1/chat/completions",
|
"base_url": "http://localhost:11434/v1/chat/completions",
|
||||||
"key_get_url": "",
|
"key_get_url": "",
|
||||||
"key_file": "ollama_key.txt",
|
"key_file": "ollama_key.txt",
|
||||||
|
"requires_key": false,
|
||||||
"model": "gemma3",
|
"model": "gemma3",
|
||||||
},
|
},
|
||||||
"openrouter": {
|
"openrouter": {
|
||||||
@@ -40,6 +43,7 @@ const PROVIDERS = Object.assign({
|
|||||||
"description": getString('A unified interface for LLMs'),
|
"description": getString('A unified interface for LLMs'),
|
||||||
"base_url": "https://openrouter.ai/api/v1/chat/completions",
|
"base_url": "https://openrouter.ai/api/v1/chat/completions",
|
||||||
"key_get_url": "https://openrouter.ai/keys",
|
"key_get_url": "https://openrouter.ai/keys",
|
||||||
|
"requires_key": true,
|
||||||
"key_file": "openrouter_key.txt",
|
"key_file": "openrouter_key.txt",
|
||||||
"model": "meta-llama/llama-3-70b-instruct",
|
"model": "meta-llama/llama-3-70b-instruct",
|
||||||
},
|
},
|
||||||
@@ -49,6 +53,7 @@ const PROVIDERS = Object.assign({
|
|||||||
"description": getString('Official OpenAI API.\nPricing: Free for the first $5 or 3 months, whichever is less.'),
|
"description": getString('Official OpenAI API.\nPricing: Free for the first $5 or 3 months, whichever is less.'),
|
||||||
"base_url": "https://api.openai.com/v1/chat/completions",
|
"base_url": "https://api.openai.com/v1/chat/completions",
|
||||||
"key_get_url": "https://platform.openai.com/api-keys",
|
"key_get_url": "https://platform.openai.com/api-keys",
|
||||||
|
"requires_key": true,
|
||||||
"key_file": "openai_key.txt",
|
"key_file": "openai_key.txt",
|
||||||
"model": "gpt-3.5-turbo",
|
"model": "gpt-3.5-turbo",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user