message edit tool json

This commit is contained in:
2023-11-10 19:49:34 +08:00
parent 94f9434fe5
commit dd56f1b94a
2 changed files with 86 additions and 19 deletions

View File

@@ -12,35 +12,97 @@ interface EditMessageProps {
setChatStore: (cs: ChatStore) => void; setChatStore: (cs: ChatStore) => void;
} }
export const isVailedJSON = (str: string): boolean => {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
};
function EditMessage(props: EditMessageProps) { function EditMessage(props: EditMessageProps) {
const { setShowEdit, chat, setChatStore, chatStore } = props; const { setShowEdit, chat, setChatStore, chatStore } = props;
return ( return (
<div <div
className={ className={
"absolute bg-black bg-opacity-50 w-full h-full top-0 left-0 pt-5 px-5 pb-20 rounded z-10" "absolute bg-black bg-opacity-50 w-full h-full top-0 left-0 rounded z-10 overflow-scroll"
} }
onClick={() => setShowEdit(false)} onClick={() => setShowEdit(false)}
> >
<div className="w-full h-full z-20"> <div
className="m-10 p-2 bg-white rounded"
onClick={(event: any) => {
event.stopPropagation();
}}
>
{typeof chat.content === "string" ? ( {typeof chat.content === "string" ? (
<textarea <div className="flex flex-col">
className={"w-full h-full"} {chat.tool_call_id && (
value={chat.content} <span className="my-2">
onClick={(event: any) => { <label>tool_call_id: </label>
event.stopPropagation(); <input
}} className="rounded border border-gray-400"
onChange={(event: any) => { value={chat.tool_call_id}
chat.content = event.target.value; onChange={(event: any) => {
chat.token = calculate_token_length(chat.content); chat.tool_call_id = event.target.value;
setChatStore({ ...chatStore }); setChatStore({ ...chatStore });
}} }}
onKeyPress={(event: any) => { />
if (event.keyCode == 27) { </span>
setShowEdit(false); )}
} {chat.tool_calls &&
}} chat.tool_calls.map((tool_call) => (
></textarea> <div className="flex flex-col w-full">
<span className="my-2 w-full">
<label>Tool Call ID: </label>
<input
value={tool_call.id}
className="rounded border border-gray-400"
/>
</span>
<span className="my-2 w-full">
<label>Function: </label>
<input
value={tool_call.function.name}
className="rounded border border-gray-400"
/>
</span>
<span className="my-2">
<label>Arguments: </label>
<span className="underline">
Vailed JSON:{" "}
{isVailedJSON(tool_call.function.arguments) ? "🆗" : "❌"}
</span>
<textarea
className="rounded border border-gray-400 w-full h-32 my-2"
value={tool_call.function.arguments}
onChange={(event: any) => {
tool_call.function.arguments =
event.target.value.trim();
setChatStore({ ...chatStore });
}}
></textarea>
</span>
<hr className="my-2" />
</div>
))}
<textarea
className="rounded border border-gray-400 w-full h-32 my-2"
value={chat.content}
onChange={(event: any) => {
chat.content = event.target.value;
chat.token = calculate_token_length(chat.content);
setChatStore({ ...chatStore });
}}
onKeyPress={(event: any) => {
if (event.keyCode == 27) {
setShowEdit(false);
}
}}
></textarea>
</div>
) : ( ) : (
<div <div
className={"w-full h-full flex flex-col overflow-scroll"} className={"w-full h-full flex flex-col overflow-scroll"}

View File

@@ -5,6 +5,7 @@ import models from "./models";
import { TemplateChatStore } from "./chatbox"; import { TemplateChatStore } from "./chatbox";
import { tr, Tr, langCodeContext, LANG_OPTIONS } from "./translate"; import { tr, Tr, langCodeContext, LANG_OPTIONS } from "./translate";
import p from "preact-markdown"; import p from "preact-markdown";
import { isVailedJSON } from "./message";
const TTS_VOICES: string[] = [ const TTS_VOICES: string[] = [
"alloy", "alloy",
@@ -373,6 +374,10 @@ export default (props: {
help="系统消息用于指示ChatGPT的角色和一些前置条件例如“你是一个有帮助的人工智能助理”或者“你是一个专业英语翻译把我的话全部翻译成英语”详情参考 OPEAN AI API 文档" help="系统消息用于指示ChatGPT的角色和一些前置条件例如“你是一个有帮助的人工智能助理”或者“你是一个专业英语翻译把我的话全部翻译成英语”详情参考 OPEAN AI API 文档"
{...props} {...props}
/> />
<span>
Valied JSON:{" "}
{isVailedJSON(props.chatStore.toolsString) ? "🆗" : "❌"}
</span>
<LongInput <LongInput
field="toolsString" field="toolsString"
help="function call tools, should be valied json format in list" help="function call tools, should be valied json format in list"