Skip to content
代码片段 群组 项目

deepseek

已合并 振 黄请求将dev/hz_v1.0.12合并到main
比较
6 文件
+ 41
10
偏好设置
比较变更
文件
6
@@ -10,12 +10,15 @@ import (
"github.com/volcengine/volcengine-go-sdk/service/arkruntime/utils"
"github.com/volcengine/volcengine-go-sdk/volcengine"
"io"
"resp.kaopuai.com/lib/kpllms"
"strings"
)
func CreateChat(ctxReq context.Context, r *arkruntime.Client, req model.ChatCompletionRequest, streamFunc func(ctx context.Context, chunk []byte, innerErr error) error) (response model.ChatCompletionResponse, err error) {
func CreateChat(ctxReq context.Context, r *arkruntime.Client, req model.ChatCompletionRequest,
streamFunc func(ctx context.Context, chunk []byte, innerErr error) error,
reasonStreamFunc func(ctx context.Context, content kpllms.ReasonContent, innerErr error) error) (response model.ChatCompletionResponse, err error) {
if streamFunc != nil {
if streamFunc != nil || reasonStreamFunc != nil {
req.Stream = true
var ch *utils.ChatCompletionStreamReader
ch, err = r.CreateChatCompletionStream(ctxReq, req)
@@ -44,6 +47,7 @@ func CreateChat(ctxReq context.Context, r *arkruntime.Client, req model.ChatComp
},
}
content := strings.Builder{}
reasoncontent := strings.Builder{}
defer ch.Close()
@@ -70,9 +74,26 @@ func CreateChat(ctxReq context.Context, r *arkruntime.Client, req model.ChatComp
response.ID = recv.ID
if recv.Choices[0].Delta.ToolCalls == nil {
b := recv.Choices[0].Delta.Content
content.WriteString(b)
err = streamFunc(ctxReq, []byte(b), nil)
if reasonStreamFunc != nil {
rb := kpllms.ReasonContent{}
if recv.Choices[0].Delta.ReasoningContent != nil {
b := *recv.Choices[0].Delta.ReasoningContent
reasoncontent.WriteString(b)
rb.Type = kpllms.ContentTypeReason
rb.Content = b
} else {
b := recv.Choices[0].Delta.Content
content.WriteString(b)
rb.Type = kpllms.ContentTypeResult
rb.Content = b
}
err = reasonStreamFunc(ctxReq, rb, nil)
} else {
b := recv.Choices[0].Delta.Content
content.WriteString(b)
err = streamFunc(ctxReq, []byte(b), nil)
}
if err != nil {
return
}
@@ -89,6 +110,7 @@ func CreateChat(ctxReq context.Context, r *arkruntime.Client, req model.ChatComp
}
response.Choices[0].Message.Content.StringValue = volcengine.String(content.String())
response.Choices[0].Message.ReasoningContent = volcengine.String(reasoncontent.String())
return
} else {
req.Stream = false