mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 21:10:18 +09:00
fix stream output
This commit is contained in:
parent
2044e1bbe6
commit
dc96278fda
@ -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 ""
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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";
|
||||
|
@ -52,7 +52,7 @@ 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");
|
||||
@ -60,6 +60,6 @@ const refreshQuota = async (dispatch: AppDispatch) => {
|
||||
};
|
||||
|
||||
export const refreshQuotaTask = (dispatch: AppDispatch) => {
|
||||
setInterval(() => refreshQuota(dispatch), 5000);
|
||||
setInterval(() => refreshQuota(dispatch), 8000);
|
||||
refreshQuota(dispatch).then();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user