Skip to content

Commit

Permalink
feat(AI): 百度千帆修改为直接返回,不使用流式返回
Browse files Browse the repository at this point in the history
  • Loading branch information
dydhyhwu committed Mar 4, 2024
1 parent bda1c5b commit 81053db
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions wclient/aichat/baidu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aichat
import (
"context"
"errors"
"io"
"strings"

"github.com/liudding/go-llm-api/baidu"
Expand Down Expand Up @@ -53,26 +52,13 @@ func BaiDuText(id, rid, ask string) (string, error) {
})

// 请求模型接口
res, err := client.CreateChatCompletion(context.Background(), req)

stream, err := client.CreateChatCompletionStream(context.Background(), req)
if err != nil {
return "", err
}

defer stream.Close()

reply := ""

for {
response, err := stream.Recv()
if err != nil {
if errors.Is(err, io.EOF) {
break
}
return reply, err
}
reply += response.Result
}
reply := res.Result

if reply == "" {
return "", errors.New("未得到预期的结果")
Expand Down

0 comments on commit 81053db

Please sign in to comment.