diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 73e3a74b..23520466 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1790,6 +1790,14 @@ "message": "If checked, the Model will think before answering. This option works only with models that support the 'think' feature.", "description": "" }, + "prefs_ollama_format_json": { + "message": "Force JSON output", + "description": "" + }, + "prefs_ollama_format_json_Info": { + "message": "If checked, Ollama will be forced to return a valid JSON response. This option works only with models that support structured output.", + "description": "" + }, "chatgpt_win_change_reply_type": { "message": "Click to change the reply type", "description": "" diff --git a/claude-spec/04-api-integrations.md b/claude-spec/04-api-integrations.md index 318eadbf..d4ef33e6 100644 --- a/claude-spec/04-api-integrations.md +++ b/claude-spec/04-api-integrations.md @@ -32,7 +32,7 @@ Content script `js/lib/diff.js` is injected into ChatGPT pages for diff-view sup ### Ollama (`ollama_api`) - Module: `js/api/ollama.js` - Worker: `js/workers/model-worker-ollama.js` -- Settings keys: `ollama_host`, `ollama_model`, `ollama_num_ctx`, `ollama_temperature`, `ollama_think` +- Settings keys: `ollama_host`, `ollama_model`, `ollama_num_ctx`, `ollama_temperature`, `ollama_think`, `ollama_format_json` - Requires CORS to be configured on the Ollama server ### OpenAI-Compatible (`openai_comp_api`) diff --git a/js/api/ollama.js b/js/api/ollama.js index 07d5a066..32433dda 100644 --- a/js/api/ollama.js +++ b/js/api/ollama.js @@ -24,7 +24,8 @@ export class Ollama { num_ctx = 0; temperature = ''; think = false; - + format_json = false; + constructor({ host = '', model = '', @@ -32,6 +33,7 @@ export class Ollama { num_ctx = 0, temperature = '', think = false, + format_json = false, } = {}) { this.host = (host || '').trim().replace(/\/+$/, ""); this.model = model; @@ -39,6 +41,7 @@ export class Ollama { this.num_ctx = num_ctx; this.temperature = temperature; this.think = think; + this.format_json = format_json; } fetchModels = async () => { @@ -93,6 +96,7 @@ export class Ollama { messages: messages, stream: this.stream, think: this.think, + ...(this.format_json ? { format: "json" } : {}), ...(this.num_ctx > 0 ? { options: { num_ctx: parseInt(this.num_ctx) } } : {}), ...(this.temperature != '' && !Number.isNaN(tempFloat) ? { options: { temperature: tempFloat } } : {}), }), diff --git a/options/mzta-options-default.js b/options/mzta-options-default.js index 4ac38c96..8776c8b6 100644 --- a/options/mzta-options-default.js +++ b/options/mzta-options-default.js @@ -31,7 +31,8 @@ export const integration_options_config = { model: '', num_ctx: 0, temperature: '', - think: false + think: false, + format_json: false }, openai_comp: { host: '', diff --git a/pages/_lib/connection-ui.js b/pages/_lib/connection-ui.js index 64a0d0eb..5ff56863 100644 --- a/pages/_lib/connection-ui.js +++ b/pages/_lib/connection-ui.js @@ -358,6 +358,17 @@ export async function injectConnectionUI({ + + + + + +