Fix token limit issue in #161

This commit is contained in:
Webifi 2023-06-10 09:58:13 -05:00
parent 44d006b9de
commit 2b8eefe113
1 changed files with 20 additions and 11 deletions

View File

@ -20,7 +20,10 @@
type Request,
type Message,
type Chat,
type ChatCompletionOpts
type ChatCompletionOpts,
type Model
} from './Types.svelte'
import Prompts from './Prompts.svelte'
import Messages from './Messages.svelte'
@ -358,6 +361,7 @@
// Update token count with actual
promptTokenCount = countPromptTokens(messagePayload, model)
const maxAllowed = getModelMaxTokens(chatSettings.model as Model) - (promptTokenCount + 1)
try {
const request: Request = {
@ -369,9 +373,13 @@
if (typeof setting.apiTransform === 'function') {
value = setting.apiTransform(chatId, setting, value)
}
if (key === 'max_tokens') {
if (opts.maxTokens) {
if (key === 'max_tokens') value = opts.maxTokens // only as large as requested
value = opts.maxTokens // only as large as requested
}
if (value > maxAllowed || value < 1) value = null
}
if (key === 'n') {
if (opts.streaming || opts.summaryRequest) {
/*
Streaming goes insane with more than one completion.
@ -379,7 +387,8 @@
different completions.
Summary should only have one completion
*/
if (key === 'n') value = 1
value = 1
}
}
if (value !== null) acc[key] = value
return acc