feat: Refactor Qwen stream event processing workflow (#939)

This commit is contained in:
Kent Dong
2024-05-15 11:43:45 +08:00
committed by GitHub
parent 8043780de0
commit 559a109ae5
4 changed files with 98 additions and 52 deletions

View File

@@ -1,5 +1,20 @@
package provider
import "strings"
const (
streamEventIdItemKey = "id:"
streamEventNameItemKey = "event:"
streamBuiltInItemKey = ":"
streamHttpStatusValuePrefix = "HTTP_STATUS/"
streamDataItemKey = "data:"
streamEndDataValue = "[DONE]"
eventResult = "result"
httpStatus200 = "200"
)
type chatCompletionRequest struct {
Model string `json:"model"`
Messages []chatMessage `json:"messages"`
@@ -42,3 +57,25 @@ type chatMessage struct {
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
}
type streamEvent struct {
Id string `json:"id"`
Event string `json:"event"`
Data string `json:"data"`
HttpStatus string `json:"http_status"`
}
func (e *streamEvent) setValue(key, value string) {
switch key {
case streamEventIdItemKey:
e.Id = value
case streamEventNameItemKey:
e.Event = value
case streamDataItemKey:
e.Data = value
case streamBuiltInItemKey:
if strings.HasPrefix(value, streamHttpStatusValuePrefix) {
e.HttpStatus = value[len(streamHttpStatusValuePrefix):]
}
}
}