format: json added to Ollama. see #703
This commit is contained in:
parent
ca56c2d971
commit
ce041fad64
5 changed files with 39 additions and 15 deletions
|
|
@ -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": ""
|
||||
|
|
|
|||
|
|
@ -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`)
|
||||
|
|
|
|||
|
|
@ -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 } } : {}),
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ export const integration_options_config = {
|
|||
model: '',
|
||||
num_ctx: 0,
|
||||
temperature: '',
|
||||
think: false
|
||||
think: false,
|
||||
format_json: false
|
||||
},
|
||||
openai_comp: {
|
||||
host: '',
|
||||
|
|
|
|||
|
|
@ -358,6 +358,17 @@ export async function injectConnectionUI({
|
|||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="conntype_ollama_api${tr_class ? ` ${tr_class}` : ''}">
|
||||
<td><label>
|
||||
<span class="opt_title">__MSG_prefs_ollama_format_json__</span>
|
||||
</label></td>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" id="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_format_json" name="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_format_json" class="option-input"/>
|
||||
__MSG_prefs_ollama_format_json_Info__
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="conntype_ollama_api${tr_class ? ` ${tr_class}` : ''}">
|
||||
<td><label>
|
||||
<span class="opt_title">__MSG_prefs_ollama_num_ctx__ <i>[num_ctx]</i></span>
|
||||
|
|
@ -571,20 +582,20 @@ export async function injectConnectionUI({
|
|||
}
|
||||
|
||||
conntype_select.addEventListener("change", () => showConnectionOptions(conntype_select));
|
||||
conntype_select.addEventListener("change", (ev) => warn_ChatGPT_APIKeyEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", (ev) => warn_Ollama_HostEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", (ev) => warn_OpenAIComp_HostEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", (ev) => warn_GoogleGemini_APIKeyEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", (ev) => warn_Anthropic_APIKeyEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", (ev) => warn_Anthropic_VersionEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", () => warn_ChatGPT_APIKeyEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", () => warn_Ollama_HostEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", () => warn_OpenAIComp_HostEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", () => warn_GoogleGemini_APIKeyEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", () => warn_Anthropic_APIKeyEmpty(modelId_prefix));
|
||||
conntype_select.addEventListener("change", () => warn_Anthropic_VersionEmpty(modelId_prefix));
|
||||
document.getElementById("chatgpt_web_project").addEventListener("input", validateCustomData_ChatGPTWeb);
|
||||
document.getElementById("chatgpt_web_custom_gpt").addEventListener("input", validateCustomData_ChatGPTWeb);
|
||||
document.getElementById(getPrefixedId("chatgpt_api_key")).addEventListener("change", (ev) => warn_ChatGPT_APIKeyEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("ollama_host")).addEventListener("change", (ev) => warn_Ollama_HostEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("openai_comp_host")).addEventListener("change", (ev) => warn_OpenAIComp_HostEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("google_gemini_api_key")).addEventListener("change", (ev) => warn_GoogleGemini_APIKeyEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("anthropic_api_key")).addEventListener("change", (ev) => warn_Anthropic_APIKeyEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("anthropic_version")).addEventListener("change", (ev) => warn_Anthropic_VersionEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("chatgpt_api_key")).addEventListener("change", () => warn_ChatGPT_APIKeyEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("ollama_host")).addEventListener("change", () => warn_Ollama_HostEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("openai_comp_host")).addEventListener("change", () => warn_OpenAIComp_HostEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("google_gemini_api_key")).addEventListener("change", () => warn_GoogleGemini_APIKeyEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("anthropic_api_key")).addEventListener("change", () => warn_Anthropic_APIKeyEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("anthropic_version")).addEventListener("change", () => warn_Anthropic_VersionEmpty(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("openai_comp_host")).addEventListener("input", () => resetOpenAICompConfigs(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("openai_comp_chat_name")).addEventListener("input", () => resetOpenAICompConfigs(modelId_prefix));
|
||||
document.getElementById(getPrefixedId("openai_comp_use_v1")).addEventListener("input", () => resetOpenAICompConfigs(modelId_prefix));
|
||||
|
|
|
|||
Loading…
Reference in a new issue