temperature added to OpenAI Compatibile API. see #575

This commit is contained in:
mic 2025-12-28 21:23:09 +01:00
parent 17a0aeb632
commit 69516bd056
6 changed files with 43 additions and 26 deletions

View file

@ -1577,18 +1577,10 @@
"message": "If checked, your chats will be stored by OpenAI.",
"description": ""
},
"prefs_chatgpt_api_temperature": {
"message": "Temperature",
"description": ""
},
"prefs_chatgpt_api_temperature_Info": {
"message": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.",
"description": ""
},
"ollama_temperature": {
"message": "Temperature",
"description": ""
},
"ollama_temperature_Info": {
"message": "The temperature of the model. Increasing the temperature will make the model answer more creatively. The default value is 0.8. It is recommended to use values between 0 and 1.",
"description": ""
@ -1689,6 +1681,14 @@
"message": "Are you sure you want to clear the Models List? This action cannot be undone.",
"description": ""
},
"prefs_api_temperature": {
"message": "Temperature",
"description": ""
},
"prefs_openai_comp_temperature_Info": {
"message": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.",
"description": ""
},
"chatgpt_click_force_completion": {
"message": "It seems that it's not possible to get if ChatGPT has finished. Click here to force the completion of the job.",
"description": ""
@ -1705,10 +1705,6 @@
"message": "Define the number of tokens to be used for thinking. Leave this field blank if the selected model does not support thinking or if you want to use the default method. Enter 0 to disable thinking, or -1 to enable dynamic thinking.",
"description": ""
},
"prefs_google_gemini_temperature": {
"message": "Temperature",
"description": ""
},
"prefs_google_gemini_temperature_Info": {
"message": "This parameter must be a number between 0.0 and 2.0. It controls the randomness of the output. The default value varies depending on the model. Leave it empty to avoid setting the parameter in the API call.",
"description": ""
@ -1729,10 +1725,6 @@
"message": "You can improve Claude performance by using a System Prompt to give it a role. This technique, known as role prompting, is the most powerful way to use system prompts with Claude. The right role can turn Claude from a general assistant into your virtual domain expert.",
"description": ""
},
"prefs_anthropic_temperature": {
"message": "Temperature",
"description": ""
},
"prefs_anthropic_temperature_Info": {
"message": "Amount of randomness injected into the response. Defaults to 1.0. Ranges from 0.0 to 1.0. Use temperature closer to 0.0 for analytical / multiple choice, and closer to 1.0 for creative and generative tasks. Note that even with temperature of 0.0, the results will not be fully deterministic.",
"description": ""

View file

@ -106,7 +106,7 @@ switch (llm) {
additional_text_elements.push({label: browser.i18n.getMessage("ChatGPT_Developer_Messages"), value: prefs_api.chatgpt_developer_messages});
}
if(prefs_api.chatgpt_api_temperature && prefs_api.chatgpt_api_temperature.length > 0){
additional_text_elements.push({label: browser.i18n.getMessage("prefs_chatgpt_api_temperature"), value: prefs_api.chatgpt_api_temperature});
additional_text_elements.push({label: browser.i18n.getMessage("prefs_api_temperature"), value: prefs_api.chatgpt_api_temperature});
}
messagesArea.appendUserMessage(getAPIsInitMessageString({
api_string: "ChatGPT API",
@ -139,7 +139,7 @@ switch (llm) {
additional_text_elements.push({label: browser.i18n.getMessage("GoogleGemini_SystemInstruction"), value: prefs_api.google_gemini_system_instruction});
}
if(prefs_api.google_gemini_temperature.length > 0){
additional_text_elements.push({label: browser.i18n.getMessage("prefs_google_gemini_temperature"), value: prefs_api.google_gemini_temperature});
additional_text_elements.push({label: browser.i18n.getMessage("prefs_api_temperature"), value: prefs_api.google_gemini_temperature});
}
if(prefs_api.google_gemini_thinking_budget.length > 0){
additional_text_elements.push({label: browser.i18n.getMessage("prefs_google_gemini_thinking_budget"), value: prefs_api.google_gemini_thinking_budget});
@ -197,7 +197,7 @@ switch (llm) {
additional_text_elements.push({label: browser.i18n.getMessage("prompt_string"), value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
additional_text_elements.push({label: browser.i18n.getMessage("prefs_ollama_think"), value: (prefs_api.ollama_think ? 'Yes' : 'No')});
if(prefs_api.ollama_temperature && prefs_api.ollama_temperature.length > 0){
additional_text_elements.push({label: browser.i18n.getMessage("prefs_ollama_temperature"), value: prefs_api.ollama_temperature});
additional_text_elements.push({label: browser.i18n.getMessage("prefs_api_temperature"), value: prefs_api.ollama_temperature});
}
if(prefs_api.ollama_num_ctx > 0){
additional_text_elements.push({label: browser.i18n.getMessage("prefs_ollama_num_ctx"), value: prefs_api.ollama_num_ctx});
@ -217,6 +217,7 @@ switch (llm) {
openai_comp_api_key: prefs_default.openai_comp_api_key,
openai_comp_use_v1: prefs_default.openai_comp_use_v1,
openai_comp_chat_name: prefs_default.openai_comp_chat_name,
openai_comp_temperature: prefs_default.openai_comp_temperature,
do_debug: prefs_default.do_debug,
});
let i18nStrings = {};
@ -230,11 +231,15 @@ switch (llm) {
openai_comp_model: prefs_api.openai_comp_model,
openai_comp_api_key: prefs_api.openai_comp_api_key,
openai_comp_use_v1: prefs_api.openai_comp_use_v1,
openai_comp_temperature: prefs_api.openai_comp_temperature,
do_debug: prefs_api.do_debug,
i18nStrings: i18nStrings,
});
let additional_text_elements = [];
additional_text_elements.push({label: browser.i18n.getMessage("prompt_string"), value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
if(prefs_api.openai_comp_temperature && prefs_api.openai_comp_temperature.length > 0){
additional_text_elements.push({label: browser.i18n.getMessage("prefs_api_temperature"), value: prefs_api.openai_comp_temperature});
}
messagesArea.appendUserMessage(getAPIsInitMessageString({
api_string: "OpenAI Compatible API",
model_string: prefs_api.openai_comp_model,
@ -282,7 +287,7 @@ switch (llm) {
additional_text_elements.push({label: browser.i18n.getMessage("prefs_OptionText_anthropic_max_tokens"), value: prefs_api.anthropic_max_tokens});
}
if(prefs_api.anthropic_temperature && prefs_api.anthropic_temperature.length > 0){
additional_text_elements.push({label: browser.i18n.getMessage("prefs_anthropic_temperature"), value: prefs_api.anthropic_temperature});
additional_text_elements.push({label: browser.i18n.getMessage("prefs_api_temperature"), value: prefs_api.anthropic_temperature});
}
messagesArea.appendUserMessage(getAPIsInitMessageString({
api_string: "Claude API",

View file

@ -26,6 +26,7 @@ export class OpenAIComp {
apiKey = '';
use_v1 = true;
stream = false;
openai_comp_temperature = '';
constructor({
host = '',
@ -33,12 +34,14 @@ export class OpenAIComp {
apiKey = '',
stream = false,
use_v1 = true,
openai_comp_temperature = '',
} = {}) {
this.host = (host || '').trim().replace(/\/+$/, "");
this.model = model;
this.stream = stream;
this.apiKey = apiKey;
this.use_v1 = use_v1;
this.openai_comp_temperature = openai_comp_temperature;
}
@ -91,7 +94,8 @@ export class OpenAIComp {
model: this.model,
messages: messages,
stream: this.stream,
...(maxTokens > 0 ? { 'max_tokens': parseInt(maxTokens) } : {})
...(maxTokens > 0 ? { 'max_tokens': parseInt(maxTokens) } : {}),
...(parseFloat(this.openai_comp_temperature) != NaN ? { 'temperature': parseFloat(this.openai_comp_temperature) } : {})
}),
});
return response;

View file

@ -42,12 +42,14 @@ self.onmessage = async function(event) {
openai_comp_model = event.data.openai_comp_model;
openai_comp_api_key = event.data.openai_comp_api_key;
openai_comp_use_v1 = event.data.openai_comp_use_v1;
openai_comp_temperature = event.data.openai_comp_temperature;
openai_comp = new OpenAIComp({
host: openai_comp_host,
model: openai_comp_model,
apiKey: openai_comp_api_key,
stream: true,
use_v1: openai_comp_use_v1
use_v1: openai_comp_use_v1,
openai_comp_temperature: openai_comp_temperature
});
do_debug = event.data.do_debug;
i18nStrings = event.data.i18nStrings;

View file

@ -44,6 +44,7 @@ export const prefs_default = {
openai_comp_api_key: '',
openai_comp_use_v1: true,
openai_comp_chat_name: 'OpenAI Comp',
openai_comp_temperature: '',
google_gemini_api_key: '',
google_gemini_model: '',
google_gemini_system_instruction: '',

View file

@ -159,7 +159,7 @@ export async function injectConnectionUI({
<tr class="conntype_chatgpt_api${tr_class ? ` ${tr_class}` : ''}">
<td>
<label>
<span class="opt_title">__MSG_prefs_chatgpt_api_temperature__</span>
<span class="opt_title">__MSG_prefs_api_temperature__</span>
</label>
</td>
<td>
@ -224,7 +224,7 @@ export async function injectConnectionUI({
<tr class="conntype_google_gemini_api${tr_class ? ` ${tr_class}` : ''}">
<td>
<label>
<span class="opt_title">__MSG_prefs_google_gemini_temperature__</span>
<span class="opt_title">__MSG_prefs_api_temperature__</span>
</label>
</td>
<td>
@ -296,7 +296,7 @@ export async function injectConnectionUI({
<tr class="conntype_ollama_api${tr_class ? ` ${tr_class}` : ''}">
<td>
<label>
<span class="opt_title">__MSG_prefs_ollama_temperature__</span>
<span class="opt_title">__MSG_prefs_api_temperature__</span>
</label>
</td>
<td>
@ -410,6 +410,19 @@ export async function injectConnectionUI({
</label>
</td>
</tr>
<tr class="conntype_openai_comp_api${tr_class ? ` ${tr_class}` : ''}">
<td>
<label>
<span class="opt_title">__MSG_prefs_api_temperature__</span>
</label>
</td>
<td>
<label>
<input type="text" id="openai_comp_temperature" name="openai_comp_temperature" class="option-input" />
<br>__MSG_prefs_openai_comp_temperature_Info__
</label>
</td>
</tr>
<tr class="conntype_anthropic_api${tr_class ? ` ${tr_class}` : ''}">
<td><label>
<span class="opt_title">__MSG_prefs_Anthropic_API_Key__</span>
@ -439,7 +452,7 @@ export async function injectConnectionUI({
<tr class="conntype_anthropic_api${tr_class ? ` ${tr_class}` : ''}">
<td>
<label>
<span class="opt_title">__MSG_prefs_anthropic_temperature__</span>
<span class="opt_title">__MSG_prefs_api_temperature__</span>
</label>
</td>
<td>