support example_user and example_assistant
This commit is contained in:
@@ -11,6 +11,7 @@ import CHATGPT_API_WEB_VERSION from "./CHATGPT_API_WEB_VERSION";
|
|||||||
export interface ChatStoreMessage extends Message {
|
export interface ChatStoreMessage extends Message {
|
||||||
hide: boolean;
|
hide: boolean;
|
||||||
token: number;
|
token: number;
|
||||||
|
example: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChatStore {
|
export interface ChatStore {
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ export default function ChatBOX(props: {
|
|||||||
content,
|
content,
|
||||||
hide: false,
|
hide: false,
|
||||||
token: responseTokenCount,
|
token: responseTokenCount,
|
||||||
|
example: false,
|
||||||
});
|
});
|
||||||
// manually copy status from client to chatStore
|
// manually copy status from client to chatStore
|
||||||
chatStore.maxTokens = client.max_tokens;
|
chatStore.maxTokens = client.max_tokens;
|
||||||
@@ -182,6 +183,7 @@ export default function ChatBOX(props: {
|
|||||||
content,
|
content,
|
||||||
hide: false,
|
hide: false,
|
||||||
token: data.usage.completion_tokens ?? calculate_token_length(content),
|
token: data.usage.completion_tokens ?? calculate_token_length(content),
|
||||||
|
example: false,
|
||||||
});
|
});
|
||||||
setShowGenerating(false);
|
setShowGenerating(false);
|
||||||
};
|
};
|
||||||
@@ -201,7 +203,14 @@ export default function ChatBOX(props: {
|
|||||||
.filter(({ hide }) => !hide)
|
.filter(({ hide }) => !hide)
|
||||||
.slice(chatStore.postBeginIndex)
|
.slice(chatStore.postBeginIndex)
|
||||||
// only copy content and role attribute to client for posting
|
// only copy content and role attribute to client for posting
|
||||||
.map(({ content, role }) => {
|
.map(({ content, role, example }) => {
|
||||||
|
if (example) {
|
||||||
|
return {
|
||||||
|
content,
|
||||||
|
role: "system",
|
||||||
|
name: role === "assistant" ? "example_assistant" : "example_user",
|
||||||
|
};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
content,
|
content,
|
||||||
role,
|
role,
|
||||||
@@ -251,6 +260,7 @@ export default function ChatBOX(props: {
|
|||||||
content: inputMsg.trim(),
|
content: inputMsg.trim(),
|
||||||
hide: false,
|
hide: false,
|
||||||
token: calculate_token_length(inputMsg.trim()),
|
token: calculate_token_length(inputMsg.trim()),
|
||||||
|
example: false,
|
||||||
});
|
});
|
||||||
// manually calculate token length
|
// manually calculate token length
|
||||||
chatStore.totalTokens += client.calculate_token_length(inputMsg.trim());
|
chatStore.totalTokens += client.calculate_token_length(inputMsg.trim());
|
||||||
@@ -472,6 +482,7 @@ export default function ChatBOX(props: {
|
|||||||
content: inputMsg,
|
content: inputMsg,
|
||||||
token: calculate_token_length(inputMsg),
|
token: calculate_token_length(inputMsg),
|
||||||
hide: false,
|
hide: false,
|
||||||
|
example: false,
|
||||||
});
|
});
|
||||||
update_total_tokens();
|
update_total_tokens();
|
||||||
setChatStore({ ...chatStore });
|
setChatStore({ ...chatStore });
|
||||||
@@ -490,6 +501,7 @@ export default function ChatBOX(props: {
|
|||||||
content: inputMsg,
|
content: inputMsg,
|
||||||
token: calculate_token_length(inputMsg),
|
token: calculate_token_length(inputMsg),
|
||||||
hide: false,
|
hide: false,
|
||||||
|
example: false,
|
||||||
});
|
});
|
||||||
update_total_tokens();
|
update_total_tokens();
|
||||||
setChatStore({ ...chatStore });
|
setChatStore({ ...chatStore });
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export interface Message {
|
export interface Message {
|
||||||
role: "system" | "user" | "assistant" | "function";
|
role: "system" | "user" | "assistant" | "function";
|
||||||
content: string;
|
content: string;
|
||||||
|
name?: "example_user" | "example_assistant";
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChunkMessage {
|
export interface ChunkMessage {
|
||||||
|
|||||||
@@ -157,6 +157,17 @@ export default function Message(props: Props) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
<span>
|
||||||
|
<label>example</label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={chat.example}
|
||||||
|
onChange={(event: any) => {
|
||||||
|
chat.example = event.target.checked;
|
||||||
|
setChatStore({ ...chatStore });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user