mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-17 05:33:42 +08:00
✨ feat: Support stream_options
This commit is contained in:
@@ -40,6 +40,16 @@ func (p *GroqProvider) CreateChatCompletion(request *types.ChatCompletionRequest
|
||||
}
|
||||
|
||||
func (p *GroqProvider) CreateChatCompletionStream(request *types.ChatCompletionRequest) (requester.StreamReaderInterface[string], *types.OpenAIErrorWithStatusCode) {
|
||||
streamOptions := request.StreamOptions
|
||||
// 如果支持流式返回Usage 则需要更改配置:
|
||||
if p.SupportStreamOptions {
|
||||
request.StreamOptions = &types.StreamOptions{
|
||||
IncludeUsage: true,
|
||||
}
|
||||
} else {
|
||||
// 避免误传导致报错
|
||||
request.StreamOptions = nil
|
||||
}
|
||||
p.getChatRequestBody(request)
|
||||
req, errWithCode := p.GetRequestTextBody(common.RelayModeChatCompletions, request.Model, request)
|
||||
if errWithCode != nil {
|
||||
@@ -47,6 +57,9 @@ func (p *GroqProvider) CreateChatCompletionStream(request *types.ChatCompletionR
|
||||
}
|
||||
defer req.Body.Close()
|
||||
|
||||
// 恢复原来的配置
|
||||
request.StreamOptions = streamOptions
|
||||
|
||||
// 发送请求
|
||||
resp, errWithCode := p.Requester.SendRequestRaw(req)
|
||||
if errWithCode != nil {
|
||||
|
||||
Reference in New Issue
Block a user