temperature added to the Claude API. see #573

This commit is contained in:
mic 2025-12-27 22:21:20 +01:00
parent f95fbeb00e
commit c2d99076b2
5 changed files with 60 additions and 14 deletions

View file

@ -59,6 +59,10 @@
"message": "More info",
"description": ""
},
"prompt_string":{
"message": "Prompt",
"description": ""
},
"customPrompts_managePrompts_info_default": {
"message": "The default prompts are not editable. You can disable them, then copy the prompt text and paste it into a new one to create a modified version.",
"description": ""
@ -1496,7 +1500,7 @@
"description": ""
},
"prefs_OptionText_anthropic_max_tokens": {
"message": "Claude Max Tokens",
"message": "Max Tokens",
"description": ""
},
"prefs_OptionText_anthropic_max_tokens_Info": {
@ -1709,6 +1713,14 @@
"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": ""
},
"Optional_Permission_Denied_Model_Fetching": {
"message": "You have denied the optional permission needed to fetch models for this integration.",
"description": ""

View file

@ -102,7 +102,7 @@ switch (llm) {
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: "Prompt", value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
additional_text_elements.push({label: browser.i18n.getMessage("prompt_string"), value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
messagesArea.appendUserMessage(getAPIsInitMessageString({
api_string: "ChatGPT API",
model_string: prefs_api.chatgpt_model,
@ -138,7 +138,7 @@ switch (llm) {
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});
}
additional_text_elements.push({label: "Prompt", value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
additional_text_elements.push({label: browser.i18n.getMessage("prompt_string"), value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
worker.postMessage({
type: 'init',
google_gemini_api_key: prefs_api.google_gemini_api_key,
@ -186,7 +186,7 @@ switch (llm) {
window_id: (await browser.windows.getCurrent()).id
});
let additional_text_elements = [];
additional_text_elements.push({label: "Prompt", value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
additional_text_elements.push({label: browser.i18n.getMessage("prompt_string"), value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
messagesArea.appendUserMessage(getAPIsInitMessageString({
api_string: "Ollama API",
model_string: prefs_api.ollama_model,
@ -219,7 +219,7 @@ switch (llm) {
i18nStrings: i18nStrings,
});
let additional_text_elements = [];
additional_text_elements.push({label: "Prompt", value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
additional_text_elements.push({label: browser.i18n.getMessage("prompt_string"), value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
messagesArea.appendUserMessage(getAPIsInitMessageString({
api_string: "OpenAI Compatible API",
model_string: prefs_api.openai_comp_model,
@ -237,6 +237,7 @@ switch (llm) {
anthropic_api_key: prefs_default.anthropic_api_key,
anthropic_model: prefs_default.anthropic_model,
anthropic_system_prompt: prefs_default.anthropic_system_prompt,
anthropic_temperature: prefs_default.anthropic_temperature,
anthropic_version: prefs_default.anthropic_version,
anthropic_max_tokens: prefs_default.anthropic_max_tokens,
do_debug: prefs_default.do_debug,
@ -257,8 +258,19 @@ switch (llm) {
i18nStrings: i18nStrings,
});
let additional_text_elements = [];
additional_text_elements.push({label: "Prompt", value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
additional_text_elements.push({label: "System Prompt", value: prefs_api.anthropic_system_prompt});
additional_text_elements.push({label: browser.i18n.getMessage("prompt_string"), value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
if(prefs_api.anthropic_system_prompt && prefs_api.anthropic_system_prompt.length > 0){
additional_text_elements.push({label: browser.i18n.getMessage("Anthropic_System_Prompt"), value: prefs_api.anthropic_system_prompt});
}
if(prefs_api.anthropic_version && prefs_api.anthropic_version.length > 0){
additional_text_elements.push({label: browser.i18n.getMessage("_api_connecting_version"), value: prefs_api.anthropic_version});
}
if(prefs_api.anthropic_max_tokens > 0){
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});
}
messagesArea.appendUserMessage(getAPIsInitMessageString({
api_string: "Claude API",
model_string: prefs_api.anthropic_model,

View file

@ -25,6 +25,7 @@ export class Anthropic {
version = '';
model = '';
system_prompt = '';
temperature = '';
max_tokens = 4096;
stream = false;
@ -33,6 +34,7 @@ export class Anthropic {
version = '',
model = '',
system_prompt = '',
temperature = '',
max_tokens = 4096,
stream = false,
} = {}) {
@ -40,6 +42,7 @@ export class Anthropic {
this.version = version;
this.model = model;
this.system_prompt = system_prompt;
this.temperature = temperature;
this.max_tokens = max_tokens > 0 ? max_tokens : 4096;
this.stream = stream;
}
@ -87,6 +90,17 @@ export class Anthropic {
// console.log(">>>>>>>>>>> Anthropic API request: " + JSON.stringify(messages));
try {
let claude_body = {
model: this.model,
max_tokens: this.max_tokens,
system: this.system_prompt,
messages: messages,
stream: this.stream,
};
if(this.temperature != '') claude_body.temperature = this.temperature;
const response = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
@ -95,13 +109,7 @@ export class Anthropic {
"anthropic-version": this.version,
"anthropic-dangerous-direct-browser-access": "true",
},
body: JSON.stringify({
model: this.model,
max_tokens: this.max_tokens,
system: this.system_prompt,
messages: messages,
stream: this.stream,
}),
body: JSON.stringify(claude_body),
});
return response;
}catch (error) {

View file

@ -52,6 +52,7 @@ export const prefs_default = {
anthropic_version: '2023-06-01',
anthropic_max_tokens: 4096,
anthropic_system_prompt: '',
anthropic_temperature: '',
dynamic_menu_force_enter: false,
dynamic_menu_order_alphabet: true,
placeholders_use_default_value: false,

View file

@ -410,6 +410,19 @@ export async function injectConnectionUI({
</label>
</td>
</tr>
<tr class="conntype_anthropic_api${tr_class ? ` ${tr_class}` : ''}">
<td>
<label>
<span class="opt_title">__MSG_prefs_anthropic_temperature__</span>
</label>
</td>
<td>
<label>
<input type="text" id="anthropic_temperature" name="anthropic_temperature" class="option-input" />
<br>__MSG_prefs_anthropic_temperature_Info__
</label>
</td>
</tr>
<tr class="conntype_anthropic_api${tr_class ? ` ${tr_class}` : ''}">
<td>
<label>