add: add & delete tool_call

This commit is contained in:
2023-11-10 20:59:47 +08:00
parent b7f519a679
commit 35f1e9f052

View File

@@ -1,6 +1,7 @@
import { ChatStore, ChatStoreMessage } from "./app"; import { ChatStore, ChatStoreMessage } from "./app";
import { isVailedJSON } from "./message"; import { isVailedJSON } from "./message";
import { calculate_token_length } from "./chatgpt"; import { calculate_token_length } from "./chatgpt";
import { Tr } from "./translate";
interface Props { interface Props {
chat: ChatStoreMessage; chat: ChatStoreMessage;
@@ -30,6 +31,7 @@ export function EditMessageString({
/> />
</span> </span>
)} )}
<hr className="my-2" />
{chat.tool_calls && {chat.tool_calls &&
chat.tool_calls.map((tool_call) => ( chat.tool_calls.map((tool_call) => (
<div className="flex flex-col w-full"> <div className="flex flex-col w-full">
@@ -62,9 +64,43 @@ export function EditMessageString({
}} }}
></textarea> ></textarea>
</span> </span>
<span className="flex flex-col my-2 justify-between">
<button
className="bg-red-300 text-black p-1 rounded"
onClick={() => {
if (!chat.tool_calls) return;
chat.tool_calls = chat.tool_calls.filter(
(tc) => tc.id !== tool_call.id
);
setChatStore({ ...chatStore });
}}
>
{Tr("Delete this tool call")}
</button>
</span>
<hr className="my-2" /> <hr className="my-2" />
</div> </div>
))} ))}
<span className="flex flex-col my-2 justify-between">
<button
className="bg-blue-300 text-black p-1 rounded"
onClick={() => {
if (!chat.tool_calls) return;
chat.tool_calls.push({
type: "function",
index: chat.tool_calls.length,
id: "",
function: {
name: "",
arguments: "",
},
});
setChatStore({ ...chatStore });
}}
>
{Tr("Add a tool call")}
</button>
</span>
<textarea <textarea
className="rounded border border-gray-400 w-full h-32 my-2" className="rounded border border-gray-400 w-full h-32 my-2"
value={chat.content} value={chat.content}