skip when choices is empty

This commit is contained in:
2023-12-22 17:14:28 +08:00
parent 54f2843677
commit 54abddc517
2 changed files with 6 additions and 9 deletions

View File

@@ -84,6 +84,10 @@ export default function ChatBOX(props: {
for await (const i of client.processStreamResponse(response)) { for await (const i of client.processStreamResponse(response)) {
chatStore.responseModelName = i.model; chatStore.responseModelName = i.model;
responseTokenCount += 1; responseTokenCount += 1;
// skip if choice is empty (e.g. azure)
if (!i.choices[0]) continue;
allChunkMessage.push(i.choices[0].delta.content ?? ""); allChunkMessage.push(i.choices[0].delta.content ?? "");
const tool_calls = i.choices[0].delta.tool_calls; const tool_calls = i.choices[0].delta.tool_calls;
if (tool_calls) { if (tool_calls) {
@@ -692,7 +696,7 @@ export default function ChatBOX(props: {
{chatStore.history.length > 0 && ( {chatStore.history.length > 0 && (
<button <button
className="disabled:line-through disabled:bg-slate-500 rounded m-2 p-2 border-2 bg-teal-500 hover:bg-teal-600" className="disabled:line-through disabled:bg-slate-500 rounded m-2 p-2 border-2 bg-teal-500 hover:bg-teal-600"
disabled={showGenerating || !chatStore.apiKey} disabled={showGenerating}
onClick={async () => { onClick={async () => {
const messageIndex = chatStore.history.length - 1; const messageIndex = chatStore.history.length - 1;
if (chatStore.history[messageIndex].role === "assistant") { if (chatStore.history[messageIndex].role === "assistant") {
@@ -712,7 +716,7 @@ export default function ChatBOX(props: {
{chatStore.develop_mode && chatStore.history.length > 0 && ( {chatStore.develop_mode && chatStore.history.length > 0 && (
<button <button
className="disabled:line-through disabled:bg-slate-500 rounded m-2 p-2 border-2 bg-yellow-500 hover:bg-yellow-600" className="disabled:line-through disabled:bg-slate-500 rounded m-2 p-2 border-2 bg-yellow-500 hover:bg-yellow-600"
disabled={showGenerating || !chatStore.apiKey} disabled={showGenerating}
onClick={async () => { onClick={async () => {
await complete(); await complete();
}} }}

View File

@@ -329,13 +329,6 @@ class Chat {
}; };
} }
completeWithSteam() {
this.total_tokens = this.messages
.map((msg) => this.calculate_token_length(msg.content as string) + 20)
.reduce((a, v) => a + v);
return this._fetch(true);
}
calculate_token_length(content: string | MessageDetail[]): number { calculate_token_length(content: string | MessageDetail[]): number {
return calculate_token_length(content); return calculate_token_length(content);
} }