Skip to content

Commit

Permalink
fix stream output
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Oct 24, 2023
1 parent 2044e1b commit dc96278
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion adapter/chatgpt/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *ChatInstance) ProcessLine(data string) string {

var form *ChatStreamResponse
if form = utils.UnmarshalForm[ChatStreamResponse](item); form == nil {
if form = utils.UnmarshalForm[ChatStreamResponse](item); form == nil {
if form = utils.UnmarshalForm[ChatStreamResponse](item[:len(item)-1]); form == nil {
fmt.Println(fmt.Sprintf("chatgpt error: cannot parse response: %s", item))
return ""
}
Expand Down
7 changes: 5 additions & 2 deletions adapter/claude/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,18 @@ func (c *ChatInstance) CreateStreamChatRequest(props *ChatProps, hook globals.Ho
// response example:
//
// event:completion
// {"completion":"么","stop_reason":null,"model":"claude-1.3","stop":null,"log_id":"605b37b2bbab7a557b811ce47d8beeab959cbab22e46b515cb15e3f00afcbe24"}
// data:{"completion":"!","stop_reason":null,"model":"claude-2.0","stop":null,"log_id":"f5f659a5807419c94cfac4a9f2f79a66e95733975714ce7f00e30689dd136b02"}

if !strings.HasPrefix(data, "data:") {
if !strings.HasPrefix(data, "data:") && strings.HasPrefix(data, "event:") {
return nil
} else {
data = strings.TrimSpace(strings.TrimPrefix(data, "data:"))
}

if len(data) == 0 {
return nil
}

if form := utils.UnmarshalForm[ChatResponse](data); form != nil {
if err := hook(form.Completion); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion app/src/conf.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import { Model } from "./conversation/types.ts";

export const version = "3.5.4";
export const version = "3.5.5";
export const dev: boolean = window.location.hostname === "localhost";
export const deploy: boolean = true;
export let rest_api: string = "http://localhost:8094";
Expand Down
4 changes: 2 additions & 2 deletions app/src/store/quota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ export const quotaSelector = (state: RootState): string =>

const refreshQuota = async (dispatch: AppDispatch) => {
const current = new Date().getTime(); //@ts-ignore
if (window.hasOwnProperty("quota") && current - window.quota < 2500) return; //@ts-ignore
if (window.hasOwnProperty("quota") && current - window.quota < 5000) return; //@ts-ignore
window.quota = current;

const response = await axios.get("/quota");
if (response.data.status) dispatch(setQuota(response.data.quota));
};

export const refreshQuotaTask = (dispatch: AppDispatch) => {
setInterval(() => refreshQuota(dispatch), 5000);
setInterval(() => refreshQuota(dispatch), 8000);
refreshQuota(dispatch).then();
};

0 comments on commit dc96278

Please sign in to comment.