diff --git a/sdkjs-plugins/content/ai/scripts/engine/local_storage.js b/sdkjs-plugins/content/ai/scripts/engine/local_storage.js index c9cac0e3..bd2a0c59 100644 --- a/sdkjs-plugins/content/ai/scripts/engine/local_storage.js +++ b/sdkjs-plugins/content/ai/scripts/engine/local_storage.js @@ -2,6 +2,8 @@ { exports.AI = exports.AI || {}; var AI = exports.AI; + + AI.DEFAULT_SERVER_SETTINGS = null; var localStorageKey = "onlyoffice_ai_plugin_storage_key"; @@ -53,9 +55,18 @@ }; AI.Storage.load = function() { + let obj = null; try { - let obj = JSON.parse(window.localStorage.getItem(localStorageKey)); + obj = JSON.parse(window.localStorage.getItem(localStorageKey)); + } catch (e) { + obj = AI.DEFAULT_SERVER_SETTINGS; + if (obj) { + AI.DEFAULT_SERVER_SETTINGS.version = AI.Storage.Version; + } + } + + if (obj) { let fixVersion2 = false; switch (obj.version) { @@ -98,8 +109,6 @@ return true; } - catch (e) { - } return false; }; diff --git a/sdkjs-plugins/content/ai/scripts/engine/providers/preinstall-example.json b/sdkjs-plugins/content/ai/scripts/engine/providers/preinstall-example.json new file mode 100644 index 00000000..43b8278a --- /dev/null +++ b/sdkjs-plugins/content/ai/scripts/engine/providers/preinstall-example.json @@ -0,0 +1,163 @@ +{ + "actions": { + "Chat": { + "name": "Ask AI", + "icon": "ask-ai", + "model": "llama-3.2-90b-vision-preview", + "capabilities": 1 + }, + "Summarization": { + "name": "Summarization", + "icon": "summarization", + "model": "llama3.2:latest", + "capabilities": 1 + }, + "Translation": { + "name": "Translation", + "icon": "translation", + "model": "gemini-1.5-pro-latest", + "capabilities": 1 + }, + "TextAnalyze": { + "name": "Text analysis", + "icon": "", + "model": "claude-3-sonnet-20240229", + "capabilities": 1 + } + }, + + "providers": { + "OpenAI": { + "name": "OpenAI", + "url": "https://api.openai.com", + "key": "OPEN-AI-KEY", + "models": [ + { + "id": "chatgpt-4o-latest", + "object": "model", + "created": 1723515131, + "owned_by": "system", + "name": "chatgpt-4o-latest", + "endpoints": [ + 1 + ], + "options": {} + }, + { + "id": "gpt-4o", + "object": "model", + "created": 1715367049, + "owned_by": "system", + "name": "gpt-4o", + "endpoints": [ + 1 + ], + "options": { + "max_input_tokens": 131072 + } + } + ] + }, + "Together AI": { + "name": "Together AI", + "url": "https://api.together.xyz", + "key": "", + "models": [] + }, + "Mistral": { + "name": "Mistral", + "url": "https://api.mistral.ai", + "key": "", + "models": [] + }, + "Deepseek": { + "name": "Deepseek", + "url": "https://api.deepseek.com", + "key": "", + "models": [ + { + "id": "deepseek-chat", + "object": "model", + "owned_by": "deepseek", + "name": "deepseek-chat", + "endpoints": [], + "options": {} + }, + { + "id": "deepseek-reasoner", + "object": "model", + "owned_by": "deepseek", + "name": "deepseek-reasoner", + "endpoints": [], + "options": {} + } + ] + }, + "Ollama": { + "name": "Ollama", + "url": "http://localhost:11434", + "key": "", + "models": [ + { + "id": "llama3.2:latest", + "object": "model", + "created": 1739120925, + "owned_by": "library", + "name": "llama3.2:latest", + "endpoints": [], + "options": {} + } + ] + } + }, + "models": [ + { + "capabilities": 129, + "provider": "Groq", + "name": "Groq [llama-3.2-90b-vision-preview]", + "id": "llama-3.2-90b-vision-preview" + }, + { + "capabilities": 1, + "provider": "Together AI", + "name": "Together AI [mistralai/Mistral-7B-v0.1]", + "id": "mistralai/Mistral-7B-v0.1" + }, + { + "capabilities": 1, + "provider": "Together AI", + "name": "Together AI [deepseek-ai/DeepSeek-V3]", + "id": "deepseek-ai/DeepSeek-V3" + }, + { + "capabilities": 129, + "provider": "OpenAI", + "name": "OpenAI [chatgpt-4o-latest]", + "id": "chatgpt-4o-latest" + }, + { + "capabilities": 129, + "provider": "Anthropic", + "name": "Anthropic [claude-3-sonnet-20240229]", + "id": "claude-3-sonnet-20240229" + }, + { + "capabilities": 129, + "provider": "Google-Gemini", + "name": "Google-Gemini [gemini-1.5-pro-latest]", + "id": "gemini-1.5-pro-latest" + }, + { + "capabilities": 255, + "provider": "Ollama", + "name": "Ollama [llama3.2:latest]", + "id": "llama3.2:latest" + }, + { + "capabilities": 255, + "provider": "Deepseek", + "name": "Deepseek [deepseek-chat]", + "id": "deepseek-chat" + } + ] +} \ No newline at end of file diff --git a/sdkjs-plugins/content/ai/scripts/engine/register.js b/sdkjs-plugins/content/ai/scripts/engine/register.js index fad7e5bf..06fbb159 100644 --- a/sdkjs-plugins/content/ai/scripts/engine/register.js +++ b/sdkjs-plugins/content/ai/scripts/engine/register.js @@ -534,9 +534,18 @@ AI.ActionsLoad = function() { + let obj = null; try { - let obj = JSON.parse(window.localStorage.getItem(actions_key)); + obj = JSON.parse(window.localStorage.getItem(actions_key)); + } + catch (e) + { + obj = (AI.DEFAULT_SERVER_SETTINGS && AI.DEFAULT_SERVER_SETTINGS.actions) ? AI.DEFAULT_SERVER_SETTINGS.actions : null; + } + + if (obj) + { for (let i in obj) { if (AI.Actions[i] && obj[i].model) @@ -544,9 +553,6 @@ } return true; } - catch (e) - { - } return false; };