diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index 5dc395ad..6946e402 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -75,6 +75,13 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.G if request == nil { return nil, errors.New("request is nil") } + if request.Stream { + // always return usage in stream mode + if request.StreamOptions == nil { + request.StreamOptions = &model.StreamOptions{} + } + request.StreamOptions.IncludeUsage = true + } return request, nil } diff --git a/relay/model/constant.go b/relay/model/constant.go index f6cf1924..c9d6d645 100644 --- a/relay/model/constant.go +++ b/relay/model/constant.go @@ -1,6 +1,7 @@ package model const ( - ContentTypeText = "text" - ContentTypeImageURL = "image_url" + ContentTypeText = "text" + ContentTypeImageURL = "image_url" + ContentTypeInputAudio = "input_audio" ) diff --git a/relay/model/general.go b/relay/model/general.go index aacc8467..fe73779e 100644 --- a/relay/model/general.go +++ b/relay/model/general.go @@ -12,9 +12,20 @@ type JSONSchema struct { Strict *bool `json:"strict,omitempty"` } +type Audio struct { + Voice string `json:"voice,omitempty"` + Format string `json:"format,omitempty"` +} + +type StreamOptions struct { + IncludeUsage bool `json:"include_usage,omitempty"` +} + type GeneralOpenAIRequest struct { Messages []Message `json:"messages,omitempty"` Model string `json:"model,omitempty"` + Modalities []string `json:"modalities,omitempty"` + Audio *Audio `json:"audio,omitempty"` FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` MaxTokens int `json:"max_tokens,omitempty"` N int `json:"n,omitempty"` @@ -23,6 +34,7 @@ type GeneralOpenAIRequest struct { Seed float64 `json:"seed,omitempty"` Stop any `json:"stop,omitempty"` Stream bool `json:"stream,omitempty"` + StreamOptions *StreamOptions `json:"stream_options,omitempty"` Temperature float64 `json:"temperature,omitempty"` TopP float64 `json:"top_p,omitempty"` TopK int `json:"top_k,omitempty"` @@ -37,7 +49,7 @@ type GeneralOpenAIRequest struct { Dimensions int `json:"dimensions,omitempty"` Instruction string `json:"instruction,omitempty"` Size string `json:"size,omitempty"` - NumCtx int `json:"num_ctx,omitempty"` + NumCtx int `json:"num_ctx,omitempty"` } func (r GeneralOpenAIRequest) ParseInput() []string {