temperature added to Open AI API. see #571

This commit is contained in:
mic 2025-12-27 22:40:51 +01:00
parent 0408f6f45e
commit dfa4da5b2e
5 changed files with 32 additions and 0 deletions

View file

@ -1577,6 +1577,14 @@
"message": "If checked, your chats will be stored by OpenAI.", "message": "If checked, your chats will be stored by OpenAI.",
"description": "" "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": ""
},
"prefs_ollama_think": { "prefs_ollama_think": {
"message": "Enable thinking", "message": "Enable thinking",
"description": "" "description": ""

View file

@ -81,6 +81,7 @@ switch (llm) {
chatgpt_model: prefs_default.chatgpt_model, chatgpt_model: prefs_default.chatgpt_model,
chatgpt_developer_messages: prefs_default.chatgpt_developer_messages, chatgpt_developer_messages: prefs_default.chatgpt_developer_messages,
chatgpt_api_store: prefs_default.chatgpt_api_store, chatgpt_api_store: prefs_default.chatgpt_api_store,
chatgpt_api_temperature: prefs_default.chatgpt_api_temperature,
do_debug: prefs_default.do_debug, do_debug: prefs_default.do_debug,
}); });
let i18nStrings = {}; let i18nStrings = {};
@ -94,6 +95,7 @@ switch (llm) {
chatgpt_model: prefs_api.chatgpt_model, chatgpt_model: prefs_api.chatgpt_model,
chatgpt_developer_messages: prefs_api.chatgpt_developer_messages, chatgpt_developer_messages: prefs_api.chatgpt_developer_messages,
chatgpt_api_store: prefs_api.chatgpt_api_store, chatgpt_api_store: prefs_api.chatgpt_api_store,
chatgpt_api_temperature: prefs_api.chatgpt_api_temperature,
do_debug: prefs_api.do_debug, do_debug: prefs_api.do_debug,
i18nStrings: i18nStrings, i18nStrings: i18nStrings,
}); });
@ -103,6 +105,9 @@ switch (llm) {
if(prefs_api.chatgpt_developer_messages && prefs_api.chatgpt_developer_messages.length > 0) { if(prefs_api.chatgpt_developer_messages && prefs_api.chatgpt_developer_messages.length > 0) {
additional_text_elements.push({label: browser.i18n.getMessage("ChatGPT_Developer_Messages"), value: prefs_api.chatgpt_developer_messages}); 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});
}
messagesArea.appendUserMessage(getAPIsInitMessageString({ messagesArea.appendUserMessage(getAPIsInitMessageString({
api_string: "ChatGPT API", api_string: "ChatGPT API",
model_string: prefs_api.chatgpt_model, model_string: prefs_api.chatgpt_model,
@ -145,6 +150,7 @@ switch (llm) {
google_gemini_model: prefs_api.google_gemini_model, google_gemini_model: prefs_api.google_gemini_model,
google_gemini_system_instruction: prefs_api.google_gemini_system_instruction, google_gemini_system_instruction: prefs_api.google_gemini_system_instruction,
google_gemini_thinking_budget: prefs_api.google_gemini_thinking_budget, google_gemini_thinking_budget: prefs_api.google_gemini_thinking_budget,
google_gemini_temperature: prefs_api.google_gemini_temperature,
do_debug: prefs_api.do_debug, do_debug: prefs_api.do_debug,
i18nStrings: i18nStrings, i18nStrings: i18nStrings,
}); });

View file

@ -24,6 +24,7 @@ export class OpenAI {
apiKey = ''; apiKey = '';
model = ''; model = '';
developer_messages = ''; developer_messages = '';
temperature = '';
stream = false; stream = false;
store = false; store = false;
@ -31,12 +32,14 @@ export class OpenAI {
apiKey = '', apiKey = '',
model = '', model = '',
developer_messages = '', developer_messages = '',
temperature = '',
stream = false, stream = false,
store = false store = false
} = {}) { } = {}) {
this.apiKey = apiKey; this.apiKey = apiKey;
this.model = model; this.model = model;
this.developer_messages = developer_messages; this.developer_messages = developer_messages;
this.temperature = temperature;
this.stream = stream; this.stream = stream;
this.store = store; this.store = store;
} }
@ -90,6 +93,7 @@ export class OpenAI {
input: input, input: input,
stream: this.stream, stream: this.stream,
store: this.store, store: this.store,
...(this.temperature != '' ? { 'temperature': this.temperature } : {}),
...(maxTokens > 0 ? { 'max_output_tokens': parseInt(maxTokens) } : {}), ...(maxTokens > 0 ? { 'max_output_tokens': parseInt(maxTokens) } : {}),
...(previous_response_id && this.store ? { 'previous_response_id': previous_response_id } : {}) ...(previous_response_id && this.store ? { 'previous_response_id': previous_response_id } : {})
} }

View file

@ -33,6 +33,7 @@ export const prefs_default = {
chatgpt_api_store: false, chatgpt_api_store: false,
chatgpt_model: '', chatgpt_model: '',
chatgpt_developer_messages: '', chatgpt_developer_messages: '',
chatgpt_api_temperature: '',
ollama_host: '', ollama_host: '',
ollama_model: '', ollama_model: '',
ollama_num_ctx: 0, ollama_num_ctx: 0,

View file

@ -156,6 +156,19 @@ export async function injectConnectionUI({
</label> </label>
</td> </td>
</tr> </tr>
<tr class="conntype_chatgpt_api${tr_class ? ` ${tr_class}` : ''}">
<td>
<label>
<span class="opt_title">__MSG_prefs_chatgpt_api_temperature__</span>
</label>
</td>
<td>
<label>
<input type="text" id="chatgpt_api_temperature" name="chatgpt_api_temperature" class="option-input" />
<br>__MSG_prefs_chatgpt_api_temperature_Info__
</label>
</td>
</tr>
<tr class="conntype_chatgpt_api${tr_class ? ` ${tr_class}` : ''}"> <tr class="conntype_chatgpt_api${tr_class ? ` ${tr_class}` : ''}">
<td> <td>
<label> <label>