support json_mode
This commit is contained in:
@@ -60,6 +60,7 @@ export interface ChatStore {
|
|||||||
tts_speed_enabled: boolean;
|
tts_speed_enabled: boolean;
|
||||||
image_gen_api: string;
|
image_gen_api: string;
|
||||||
image_gen_key: string;
|
image_gen_key: string;
|
||||||
|
json_mode: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _defaultAPIEndpoint = "https://api.openai.com/v1/chat/completions";
|
const _defaultAPIEndpoint = "https://api.openai.com/v1/chat/completions";
|
||||||
@@ -79,7 +80,8 @@ export const newChatStore = (
|
|||||||
tts_speed_enabled = false,
|
tts_speed_enabled = false,
|
||||||
toolsString = "",
|
toolsString = "",
|
||||||
image_gen_api = "https://api.openai.com/v1/images/generations",
|
image_gen_api = "https://api.openai.com/v1/images/generations",
|
||||||
image_gen_key = ""
|
image_gen_key = "",
|
||||||
|
json_mode = false
|
||||||
): ChatStore => {
|
): ChatStore => {
|
||||||
return {
|
return {
|
||||||
chatgpt_api_web_version: CHATGPT_API_WEB_VERSION,
|
chatgpt_api_web_version: CHATGPT_API_WEB_VERSION,
|
||||||
@@ -114,6 +116,7 @@ export const newChatStore = (
|
|||||||
tts_speed_enabled: tts_speed_enabled,
|
tts_speed_enabled: tts_speed_enabled,
|
||||||
image_gen_api: image_gen_api,
|
image_gen_api: image_gen_api,
|
||||||
image_gen_key: image_gen_key,
|
image_gen_key: image_gen_key,
|
||||||
|
json_mode: json_mode,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -273,7 +276,8 @@ export function App() {
|
|||||||
chatStore.tts_speed_enabled,
|
chatStore.tts_speed_enabled,
|
||||||
chatStore.toolsString,
|
chatStore.toolsString,
|
||||||
chatStore.image_gen_api,
|
chatStore.image_gen_api,
|
||||||
chatStore.image_gen_key
|
chatStore.image_gen_key,
|
||||||
|
chatStore.json_mode
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
setSelectedChatIndex(newKey as number);
|
setSelectedChatIndex(newKey as number);
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ export default function ChatBOX(props: {
|
|||||||
client.enable_top_p = chatStore.top_p_enabled;
|
client.enable_top_p = chatStore.top_p_enabled;
|
||||||
client.frequency_penalty = chatStore.frequency_penalty;
|
client.frequency_penalty = chatStore.frequency_penalty;
|
||||||
client.presence_penalty = chatStore.presence_penalty;
|
client.presence_penalty = chatStore.presence_penalty;
|
||||||
|
client.json_mode = chatStore.json_mode;
|
||||||
client.messages = chatStore.history
|
client.messages = chatStore.history
|
||||||
// only copy non hidden message
|
// only copy non hidden message
|
||||||
.filter(({ hide }) => !hide)
|
.filter(({ hide }) => !hide)
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ class Chat {
|
|||||||
enable_top_p: boolean;
|
enable_top_p: boolean;
|
||||||
presence_penalty: number;
|
presence_penalty: number;
|
||||||
frequency_penalty: number;
|
frequency_penalty: number;
|
||||||
|
json_mode: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
OPENAI_API_KEY: string | undefined,
|
OPENAI_API_KEY: string | undefined,
|
||||||
@@ -150,6 +151,7 @@ class Chat {
|
|||||||
enable_top_p = false,
|
enable_top_p = false,
|
||||||
presence_penalty = 0,
|
presence_penalty = 0,
|
||||||
frequency_penalty = 0,
|
frequency_penalty = 0,
|
||||||
|
json_mode = false,
|
||||||
} = {}
|
} = {}
|
||||||
) {
|
) {
|
||||||
this.OPENAI_API_KEY = OPENAI_API_KEY ?? "";
|
this.OPENAI_API_KEY = OPENAI_API_KEY ?? "";
|
||||||
@@ -169,6 +171,7 @@ class Chat {
|
|||||||
this.enable_top_p = enable_top_p;
|
this.enable_top_p = enable_top_p;
|
||||||
this.presence_penalty = presence_penalty;
|
this.presence_penalty = presence_penalty;
|
||||||
this.frequency_penalty = frequency_penalty;
|
this.frequency_penalty = frequency_penalty;
|
||||||
|
this.json_mode = json_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
_fetch(stream = false) {
|
_fetch(stream = false) {
|
||||||
@@ -217,6 +220,11 @@ class Chat {
|
|||||||
if (this.enable_max_gen_tokens) {
|
if (this.enable_max_gen_tokens) {
|
||||||
body["max_tokens"] = this.max_gen_tokens;
|
body["max_tokens"] = this.max_gen_tokens;
|
||||||
}
|
}
|
||||||
|
if (this.json_mode) {
|
||||||
|
body["response_format"] = {
|
||||||
|
type: "json_object",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// parse toolsString to function call format
|
// parse toolsString to function call format
|
||||||
const ts = this.toolsString.trim();
|
const ts = this.toolsString.trim();
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ const Number = (props: {
|
|||||||
const Choice = (props: {
|
const Choice = (props: {
|
||||||
chatStore: ChatStore;
|
chatStore: ChatStore;
|
||||||
setChatStore: (cs: ChatStore) => void;
|
setChatStore: (cs: ChatStore) => void;
|
||||||
field: "streamMode" | "develop_mode";
|
field: "streamMode" | "develop_mode" | "json_mode";
|
||||||
help: string;
|
help: string;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
@@ -420,6 +420,7 @@ export default (props: {
|
|||||||
help="开发者模式,拥有更多选项及功能"
|
help="开发者模式,拥有更多选项及功能"
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
<Choice field="json_mode" help="JSON Mode" {...props} />
|
||||||
<SelectModel
|
<SelectModel
|
||||||
help="模型,默认 3.5。不同模型性能和定价也不同,请参考 API 文档。(GPT-4 模型处于内测阶段,需要向 OPENAI 申请, 请确保您有访问权限)"
|
help="模型,默认 3.5。不同模型性能和定价也不同,请参考 API 文档。(GPT-4 模型处于内测阶段,需要向 OPENAI 申请, 请确保您有访问权限)"
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
Reference in New Issue
Block a user