Skip to content

Commit

Permalink
optional max_tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Algorithm5838 committed Mar 27, 2024
1 parent 43824bd commit 8eb78c9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface LLMConfig {
stream?: boolean;
presence_penalty?: number;
frequency_penalty?: number;
useMaxTokens?: boolean;
}

export interface ChatOptions {
Expand Down
3 changes: 1 addition & 2 deletions app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ export class ChatGPTApi implements LLMApi {
presence_penalty: modelConfig.presence_penalty,
frequency_penalty: modelConfig.frequency_penalty,
top_p: modelConfig.top_p,
// max_tokens: Math.max(modelConfig.max_tokens, 1024),
// Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore.
max_tokens: modelConfig.useMaxTokens ? modelConfig.max_tokens : undefined,
};

// add max_tokens to vision model
Expand Down
37 changes: 25 additions & 12 deletions app/components/model-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,38 @@ export function ModelConfigList(props: {
}}
></InputRange>
</ListItem>
<ListItem
title={Locale.Settings.MaxTokens.Title}
subTitle={Locale.Settings.MaxTokens.SubTitle}
>
<ListItem title={"Use Max Tokens"}>
<input
type="number"
min={1024}
max={512000}
value={props.modelConfig.max_tokens}
type="checkbox"
checked={props.modelConfig.useMaxTokens}
onChange={(e) =>
props.updateConfig(
(config) =>
(config.max_tokens = ModalConfigValidator.max_tokens(
e.currentTarget.valueAsNumber,
)),
(config) => (config.useMaxTokens = e.currentTarget.checked),
)
}
></input>
</ListItem>
{props.modelConfig.useMaxTokens && (
<ListItem
title={Locale.Settings.MaxTokens.Title}
subTitle={Locale.Settings.MaxTokens.SubTitle}
>
<input
type="number"
min={1}
max={32768}
value={props.modelConfig.max_tokens}
onChange={(e) =>
props.updateConfig(
(config) =>
(config.max_tokens = ModalConfigValidator.max_tokens(
e.currentTarget.valueAsNumber,
)),
)
}
></input>
</ListItem>
)}

{props.modelConfig.model.startsWith("gemini") ? null : (
<>
Expand Down
3 changes: 2 additions & 1 deletion app/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ export const DEFAULT_CONFIG = {
model: "gpt-3.5-turbo" as ModelType,
temperature: 0.5,
top_p: 1,
max_tokens: 4000,
max_tokens: 2048,
presence_penalty: 0,
frequency_penalty: 0,
sendMemory: true,
historyMessageCount: 4,
compressMessageLengthThreshold: 1000,
enableInjectSystemPrompts: true,
template: DEFAULT_INPUT_TEMPLATE,
useMaxTokens: false,
},
};

Expand Down

0 comments on commit 8eb78c9

Please sign in to comment.