max_tokens added to anthropic. see #349

This commit is contained in:
mic 2025-05-20 22:05:00 +02:00
parent 059fa8c62b
commit 19565ec7c5
4 changed files with 25 additions and 16 deletions

View file

@ -1466,5 +1466,13 @@
"Anthropic_Version_Info": {
"message": "REQUIRED. Do not change this value unless you know what you're doing. More info at: ",
"description": ""
}
},
"prefs_OptionText_anthropic_max_tokens": {
"message": "Anthropic Max Tokens",
"description": ""
},
"prefs_OptionText_anthropic_max_tokens_Info": {
"message": "The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length.",
"description": ""
}
}

View file

@ -24,14 +24,14 @@ export class Anthropic {
apiKey = '';
version = '';
model = '';
developer_messages = '';
max_tokens = 4096;
stream = false;
constructor(apiKey, version, model, developer_messages, stream) {
constructor(apiKey, version, model, max_tokens, stream) {
this.apiKey = apiKey;
this.version = version;
this.model = model;
this.developer_messages = developer_messages;
this.max_tokens = max_tokens > 0 ? max_tokens : 4096;
this.stream = stream;
}
@ -73,11 +73,7 @@ export class Anthropic {
}
}
fetchResponse = async (messages, maxTokens = 0) => {
if(this.developer_messages !== ''){
messages.push({role: "developer", content: [{"type": "text", "text": this.developer_messages}]});
}
fetchResponse = async (messages) => {
// console.log(">>>>>>>>>>> Anthropic API request: " + JSON.stringify(messages));
@ -90,10 +86,10 @@ export class Anthropic {
"anthropic-version": this.version,
},
body: JSON.stringify({
model: this.model,
model: this.model,
max_tokens: this.max_tokens,
messages: messages,
stream: this.stream,
...(maxTokens > 0 ? { 'max_tokens': parseInt(maxTokens) } : {})
}),
});
return response;

View file

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

View file

@ -425,11 +425,15 @@
</label>
</td>
</tr>
<tr class="conntype_anthropic_api">
<td><span class="opt_title">__MSG_prefs_OptionText_anthropic_max_tokens__</span></td>
<td>
<label>
<input type="number" id="anthropic_max_tokens" name="anthropic_max_tokens" class="option-input" />
<br>__MSG_prefs_OptionText_anthropic_max_tokens_Info__
</label>
</td>
</tr>
<tr id="max_prompt_length_tr">
<td><span class="opt_title">__MSG_prefs_OptionText_max_prompt_length__</span></td>
<td>