Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/appbuilder/app_builder_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ func TestAppBuilderClientRunCustomMetadata(t *testing.T) {
res, err := client.Run(AppBuilderClientRunRequest{
AppID: appID,
Query: "我要回老家相亲",
Stream: false,
Stream: true,
ConversationID: conversationID,
CustomMetadata: &CustomMetadata{
OverrideRoleInstruction: `# 角色任务\n" +
Expand All @@ -1002,7 +1002,7 @@ func TestAppBuilderClientRunCustomMetadata(t *testing.T) {
"# 要求与限制\n" +
"\n" +
"1. 输出内容的风格为幽默\n" +
"2.输出的字数限制为100字以内"`,
"2.输出的字数限制为1000字范围"`,
},
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/appbuilder/component_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestComponentClientHeader(t *testing.T) {

componentID := "c-wf-a39ee06c-808f-4a19-9f5f-544044283749"
parameters := map[string]any{
SysOriginQuery: "梦到巨人,是怎么回事",
SysOriginQuery: "梦到巨人,是怎么回事,请仔细分析,写一篇不少于1000字的文章",
}
componentClient, err := NewComponentClient(config)
if err != nil {
Expand Down
45 changes: 22 additions & 23 deletions go/appbuilder/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package appbuilder

import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
Expand All @@ -30,51 +31,49 @@ type SSEEvent struct {
}

func checkHTTPResponse(rsp *http.Response) (string, error) {
requestID := rsp.Header.Get("X-Appbuilder-Request-Id")
if rsp.StatusCode == http.StatusOK {
log.Printf("Successful HTTP response. RequestID: %s", requestID)
return requestID, nil
}
requestID := rsp.Header.Get("X-Appbuilder-Request-Id")
if rsp.StatusCode == http.StatusOK {
log.Printf("Successful HTTP response. RequestID: %s", requestID)
return requestID, nil
}

data, err := io.ReadAll(rsp.Body)
if err != nil {
log.Printf("Failed to read response body. RequestID: %s, Error: %v", requestID, err)
return requestID, err
}
log.Printf("HTTP response with unexpected status code. RequestID: %s, StatusCode: %d, Content: %s", requestID, rsp.StatusCode, string(data))
return requestID, fmt.Errorf("http status code is %d, content is %s", rsp.StatusCode, string(data))
data, err := io.ReadAll(rsp.Body)
if err != nil {
log.Printf("Failed to read response body. RequestID: %s, Error: %v", requestID, err)
return requestID, err
}
log.Printf("HTTP response with unexpected status code. RequestID: %s, StatusCode: %d, Content: %s", requestID, rsp.StatusCode, string(data))
return requestID, fmt.Errorf("http status code is %d, content is %s", rsp.StatusCode, string(data))
}

func NewSSEReader(bufSize int, reader *bufio.Reader) *sseReader {
buf := make([]byte, bufSize)
return &sseReader{reader: reader, buf: buf}
//buf := make([]byte, bufSize)
return &sseReader{reader: reader, buf: bytes.Buffer{}}
}

type sseReader struct {
reader *bufio.Reader
buf []byte
buf bytes.Buffer
}

func (t *sseReader) ReadMessageLine() ([]byte, error) {
size := 0
t.buf.Reset()
for {
line, isPrefix, err := t.reader.ReadLine()
if err != nil {
return nil, err
}
if len(line)+size > cap(t.buf) {
panic("buffer overflow")
}
size += copy(t.buf[size:], line)
t.buf.Grow(len(line))
t.buf.Write(line)
if !isPrefix {
break
}
}
// 读取空行
line, _, err := t.reader.ReadLine()
if err != nil || len(line) != 0 {
size += copy(t.buf[size:], line)
return nil, errors.New(string(t.buf[0:size]))
t.buf.Grow(len(line))
return nil, errors.New(t.buf.String())
}
return t.buf[0:size], nil
return t.buf.Bytes(), nil
}
Loading