Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#1554 from yanCode/fix/non-stream-re…
Browse files Browse the repository at this point in the history
…sponses

fix: ChatGPTNextWeb#1533 handle non-stream type
  • Loading branch information
Yidadaa authored May 17, 2023
2 parents 3749509 + 8fafb46 commit 6807ab9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";

import { ChatOptions, getHeaders, LLMApi, LLMUsage } from "../api";
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";

export class ChatGPTApi implements LLMApi {
Expand Down Expand Up @@ -79,6 +82,13 @@ export class ChatGPTApi implements LLMApi {
...chatPayload,
async onopen(res) {
clearTimeout(requestTimeoutId);
if (
res.ok &&
res.headers.get("content-type") !== EventStreamContentType
) {
responseText += await res.clone().json();
return finish();
}
if (res.status === 401) {
let extraInfo = { error: undefined };
try {
Expand Down

0 comments on commit 6807ab9

Please sign in to comment.