mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-09-30 07:06:37 +08:00
Compare commits
11 Commits
ce1694b44b
...
c4f171ae89
Author | SHA1 | Date | |
---|---|---|---|
|
c4f171ae89 | ||
|
995bef73de | ||
|
38ac502d80 | ||
|
0511808900 | ||
|
42eff644b4 | ||
|
8ae6883784 | ||
|
c0f2ab6de3 | ||
|
c3b50a9c93 | ||
|
ab4bf3ba67 | ||
|
67192a7946 | ||
|
bcd50b89c8 |
@ -200,6 +200,7 @@ export class ChatGPTApi implements LLMApi {
|
||||
options.config.model.startsWith("o1") ||
|
||||
options.config.model.startsWith("o3") ||
|
||||
options.config.model.startsWith("o4-mini");
|
||||
const isGpt5 = options.config.model.startsWith("gpt-5");
|
||||
if (isDalle3) {
|
||||
const prompt = getMessageTextContent(
|
||||
options.messages.slice(-1)?.pop() as any,
|
||||
@ -230,7 +231,7 @@ export class ChatGPTApi implements LLMApi {
|
||||
messages,
|
||||
stream: options.config.stream,
|
||||
model: modelConfig.model,
|
||||
temperature: !isO1OrO3 ? modelConfig.temperature : 1,
|
||||
temperature: (!isO1OrO3 && !isGpt5) ? modelConfig.temperature : 1,
|
||||
presence_penalty: !isO1OrO3 ? modelConfig.presence_penalty : 0,
|
||||
frequency_penalty: !isO1OrO3 ? modelConfig.frequency_penalty : 0,
|
||||
top_p: !isO1OrO3 ? modelConfig.top_p : 1,
|
||||
@ -238,7 +239,13 @@ export class ChatGPTApi implements LLMApi {
|
||||
// Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore.
|
||||
};
|
||||
|
||||
if (isO1OrO3) {
|
||||
if (isGpt5) {
|
||||
// Remove max_tokens if present
|
||||
delete requestPayload.max_tokens;
|
||||
// Add max_completion_tokens (or max_completion_tokens if that's what you meant)
|
||||
requestPayload["max_completion_tokens"] = modelConfig.max_tokens;
|
||||
|
||||
} else if (isO1OrO3) {
|
||||
// by default the o1/o3 models will not attempt to produce output that includes markdown formatting
|
||||
// manually add "Formatting re-enabled" developer message to encourage markdown inclusion in model responses
|
||||
// (https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/reasoning?tabs=python-secure#markdown-output)
|
||||
@ -251,8 +258,9 @@ export class ChatGPTApi implements LLMApi {
|
||||
requestPayload["max_completion_tokens"] = modelConfig.max_tokens;
|
||||
}
|
||||
|
||||
|
||||
// add max_tokens to vision model
|
||||
if (visionModel && !isO1OrO3) {
|
||||
if (visionModel && !isO1OrO3 && ! isGpt5) {
|
||||
requestPayload["max_tokens"] = Math.max(modelConfig.max_tokens, 4000);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,76 @@
|
||||
import { TTSConfig, TTSConfigValidator } from "../store";
|
||||
import React, { useState } from "react";
|
||||
|
||||
import Locale from "../locales";
|
||||
import { ListItem, Select } from "./ui-lib";
|
||||
import {
|
||||
ModelProvider,
|
||||
DEFAULT_TTS_ENGINE,
|
||||
DEFAULT_TTS_ENGINES,
|
||||
DEFAULT_TTS_MODELS,
|
||||
DEFAULT_TTS_VOICES,
|
||||
} from "../constant";
|
||||
import { InputRange } from "./input-range";
|
||||
import { IconButton } from "./button";
|
||||
import SpeakIcon from "../icons/speak.svg";
|
||||
import SpeakStopIcon from "../icons/speak-stop.svg";
|
||||
import { createTTSPlayer } from "../utils/audio";
|
||||
import { useAppConfig } from "../store";
|
||||
import { ClientApi } from "../client/api";
|
||||
import { showToast } from "../components/ui-lib";
|
||||
|
||||
const ttsPlayer = createTTSPlayer();
|
||||
export function TTSConfigList(props: {
|
||||
ttsConfig: TTSConfig;
|
||||
updateConfig: (updater: (config: TTSConfig) => void) => void;
|
||||
}) {
|
||||
const [speechLoading, setSpeechLoading] = useState(false);
|
||||
const [speechStatus, setSpeechStatus] = useState(false);
|
||||
|
||||
const config = useAppConfig.getState();
|
||||
|
||||
function stopSpeech() {
|
||||
ttsPlayer.stop();
|
||||
setSpeechStatus(false);
|
||||
}
|
||||
|
||||
async function playSpeech(text: string, ttsConfig: TTSConfig) {
|
||||
try {
|
||||
const api = new ClientApi(ModelProvider.GPT);
|
||||
setSpeechLoading(true);
|
||||
ttsPlayer.init();
|
||||
|
||||
const audioBuffer = await api.llm.speech({
|
||||
model: ttsConfig.model,
|
||||
input: text,
|
||||
voice: ttsConfig.voice,
|
||||
speed: ttsConfig.speed,
|
||||
});
|
||||
|
||||
setSpeechStatus(true);
|
||||
await ttsPlayer.play(audioBuffer, () => {
|
||||
setSpeechStatus(false);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[OpenAI Speech]", error);
|
||||
setSpeechStatus(false);
|
||||
// Implement user-facing error notification here
|
||||
if (typeof (error as Error).message === "string") {
|
||||
showToast((error as Error).message);
|
||||
}
|
||||
} finally {
|
||||
setSpeechLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function openaiSpeech(text: string) {
|
||||
if (speechStatus) {
|
||||
stopSpeech();
|
||||
} else {
|
||||
await playSpeech(text, config.ttsConfig);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ListItem
|
||||
@ -88,15 +145,32 @@ export function TTSConfigList(props: {
|
||||
title={Locale.Settings.TTS.Voice.Title}
|
||||
subTitle={Locale.Settings.TTS.Voice.SubTitle}
|
||||
>
|
||||
<div style={{ display: "flex", gap: "10px" }}>
|
||||
<IconButton
|
||||
aria={Locale.Chat.Actions.Speech}
|
||||
icon={speechStatus ? <SpeakStopIcon /> : <SpeakIcon />}
|
||||
text={
|
||||
speechLoading
|
||||
? "Loading..."
|
||||
: speechStatus
|
||||
? Locale.Chat.Actions.Stop
|
||||
: Locale.Chat.Actions.Speech
|
||||
}
|
||||
onClick={() => {
|
||||
openaiSpeech(
|
||||
"NextChat,Unleash your imagination, experience the future of AI conversation.",
|
||||
);
|
||||
}}
|
||||
/>
|
||||
|
||||
<Select
|
||||
value={props.ttsConfig.voice}
|
||||
onChange={(e) => {
|
||||
props.updateConfig(
|
||||
(config) =>
|
||||
(config.voice = TTSConfigValidator.voice(
|
||||
props.updateConfig((config) => {
|
||||
config.voice = TTSConfigValidator.voice(
|
||||
e.currentTarget.value,
|
||||
)),
|
||||
);
|
||||
});
|
||||
}}
|
||||
>
|
||||
{DEFAULT_TTS_VOICES.map((v, i) => (
|
||||
@ -105,6 +179,7 @@ export function TTSConfigList(props: {
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
</ListItem>
|
||||
<ListItem
|
||||
title={Locale.Settings.TTS.Speed.Title}
|
||||
|
@ -493,6 +493,7 @@ export const VISION_MODEL_REGEXES = [
|
||||
/o3/,
|
||||
/o4-mini/,
|
||||
/grok-4/i,
|
||||
/gpt-5/
|
||||
];
|
||||
|
||||
export const EXCLUDE_VISION_MODEL_REGEXES = [/claude-3-5-haiku-20241022/];
|
||||
@ -517,6 +518,11 @@ const openaiModels = [
|
||||
"gpt-4.1-nano-2025-04-14",
|
||||
"gpt-4.5-preview",
|
||||
"gpt-4.5-preview-2025-02-27",
|
||||
"gpt-5-chat",
|
||||
"gpt-5-mini",
|
||||
"gpt-5-nano",
|
||||
"gpt-5",
|
||||
"gpt-5-chat-2025-01-01-preview",
|
||||
"gpt-4o",
|
||||
"gpt-4o-2024-05-13",
|
||||
"gpt-4o-2024-08-06",
|
||||
|
Loading…
Reference in New Issue
Block a user