diff --git a/src/chat.js b/src/chat.js index 353e747..400144c 100644 --- a/src/chat.js +++ b/src/chat.js @@ -110,15 +110,10 @@ export async function* sendMessage(message) { // Cap to model's max completion tokens limit const maxCompletionTokens = getSelectedModelMaxCompletionTokens(); - // For chat, prefer using the full calculated available space for coherent responses - // Only cap if we're exceeding the model's hard limit + // Use the full calculated available space or the model's limit, whichever is smaller const finalAvailable = Math.min(calculatedAvailable, maxCompletionTokens); - // However, for very large available token counts, cap at a reasonable max to prevent rambling - const reasonableMax = 4096; // Enough for very thorough responses without being excessive - const actualFinal = Math.min(finalAvailable, reasonableMax); - - console.log("Chat using tokens:", actualFinal, "calculated:", calculatedAvailable, "max completion:", maxCompletionTokens); + console.log("Chat using tokens:", finalAvailable, "calculated:", calculatedAvailable, "max completion:", maxCompletionTokens); const response = await fetch(apiUrl, { method: "POST", @@ -127,7 +122,7 @@ export async function* sendMessage(message) { model: model, messages: chatHistory, temperature: 0.5, - max_tokens: actualFinal, + max_tokens: finalAvailable, stream: true, }), });