forked from XiaoMo/ChatGPT-Next-Web
Merge pull request #1554 from yanCode/fix/non-stream-responses
fix: #1533 handle non-stream type
This commit is contained in:
commit
94ab5c7abf
@ -3,7 +3,10 @@ import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
|
|||||||
|
|
||||||
import { ChatOptions, getHeaders, LLMApi, LLMUsage } from "../api";
|
import { ChatOptions, getHeaders, LLMApi, LLMUsage } from "../api";
|
||||||
import Locale from "../../locales";
|
import Locale from "../../locales";
|
||||||
import { fetchEventSource } from "@microsoft/fetch-event-source";
|
import {
|
||||||
|
EventStreamContentType,
|
||||||
|
fetchEventSource,
|
||||||
|
} from "@microsoft/fetch-event-source";
|
||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
|
|
||||||
export class ChatGPTApi implements LLMApi {
|
export class ChatGPTApi implements LLMApi {
|
||||||
@ -79,6 +82,13 @@ export class ChatGPTApi implements LLMApi {
|
|||||||
...chatPayload,
|
...chatPayload,
|
||||||
async onopen(res) {
|
async onopen(res) {
|
||||||
clearTimeout(requestTimeoutId);
|
clearTimeout(requestTimeoutId);
|
||||||
|
if (
|
||||||
|
res.ok &&
|
||||||
|
res.headers.get("content-type") !== EventStreamContentType
|
||||||
|
) {
|
||||||
|
responseText += await res.clone().json();
|
||||||
|
return finish();
|
||||||
|
}
|
||||||
if (res.status === 401) {
|
if (res.status === 401) {
|
||||||
let extraInfo = { error: undefined };
|
let extraInfo = { error: undefined };
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user