Parcourir la source

fix: missing response relay price (#332)

zijiren il y a 4 mois
Parent
commit
648afe902e

+ 8 - 9
core/controller/relay-controller.go

@@ -114,12 +114,18 @@ func relayHandler(c *gin.Context, meta *meta.Meta, mc *model.ModelCaches) *contr
 	return controller.Handle(adaptor, c, meta, adaptorStore)
 }
 
+func defaultPriceFunc(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
+	return mc.Price, nil
+}
+
 func relayController(m mode.Mode) RelayController {
 	c := RelayController{
 		Handler: func(c *gin.Context, meta *meta.Meta) *controller.HandleResult {
 			return relayHandler(c, meta, middleware.GetModelCaches(c))
 		},
+		GetRequestPrice: defaultPriceFunc,
 	}
+
 	switch m {
 	case mode.ImagesGenerations:
 		c.GetRequestPrice = controller.GetImagesRequestPrice
@@ -128,32 +134,25 @@ func relayController(m mode.Mode) RelayController {
 		c.GetRequestPrice = controller.GetImagesEditsRequestPrice
 		c.GetRequestUsage = controller.GetImagesEditsRequestUsage
 	case mode.AudioSpeech:
-		c.GetRequestPrice = controller.GetTTSRequestPrice
 		c.GetRequestUsage = controller.GetTTSRequestUsage
 	case mode.AudioTranslation, mode.AudioTranscription:
-		c.GetRequestPrice = controller.GetSTTRequestPrice
 		c.GetRequestUsage = controller.GetSTTRequestUsage
 	case mode.ParsePdf:
-		c.GetRequestPrice = controller.GetPdfRequestPrice
 		c.GetRequestUsage = controller.GetPdfRequestUsage
 	case mode.Rerank:
-		c.GetRequestPrice = controller.GetRerankRequestPrice
 		c.GetRequestUsage = controller.GetRerankRequestUsage
 	case mode.Anthropic:
-		c.GetRequestPrice = controller.GetAnthropicRequestPrice
 		c.GetRequestUsage = controller.GetAnthropicRequestUsage
 	case mode.ChatCompletions:
-		c.GetRequestPrice = controller.GetChatRequestPrice
 		c.GetRequestUsage = controller.GetChatRequestUsage
 	case mode.Embeddings:
-		c.GetRequestPrice = controller.GetEmbedRequestPrice
 		c.GetRequestUsage = controller.GetEmbedRequestUsage
 	case mode.Completions:
-		c.GetRequestPrice = controller.GetCompletionsRequestPrice
 		c.GetRequestUsage = controller.GetCompletionsRequestUsage
 	case mode.VideoGenerationsJobs:
-		c.GetRequestPrice = controller.GetVideoGenerationJobRequestPrice
 		c.GetRequestUsage = controller.GetVideoGenerationJobRequestUsage
+	case mode.Responses:
+		c.GetRequestUsage = controller.GetResponsesRequestUsage
 	}
 
 	return c

+ 0 - 4
core/relay/controller/anthropic.go

@@ -7,10 +7,6 @@ import (
 	"github.com/labring/aiproxy/core/relay/utils"
 )
 
-func GetAnthropicRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
-	return mc.Price, nil
-}
-
 func GetAnthropicRequestUsage(c *gin.Context, _ model.ModelConfig) (model.Usage, error) {
 	textRequest, err := utils.UnmarshalAnthropicMessageRequest(c.Request)
 	if err != nil {

+ 0 - 4
core/relay/controller/chat.go

@@ -7,10 +7,6 @@ import (
 	"github.com/labring/aiproxy/core/relay/utils"
 )
 
-func GetChatRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
-	return mc.Price, nil
-}
-
 func GetChatRequestUsage(c *gin.Context, _ model.ModelConfig) (model.Usage, error) {
 	textRequest, err := utils.UnmarshalGeneralOpenAIRequest(c.Request)
 	if err != nil {

+ 0 - 4
core/relay/controller/completions.go

@@ -7,10 +7,6 @@ import (
 	"github.com/labring/aiproxy/core/relay/utils"
 )
 
-func GetCompletionsRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
-	return mc.Price, nil
-}
-
 func GetCompletionsRequestUsage(c *gin.Context, _ model.ModelConfig) (model.Usage, error) {
 	textRequest, err := utils.UnmarshalGeneralOpenAIRequest(c.Request)
 	if err != nil {

+ 0 - 4
core/relay/controller/embed.go

@@ -7,10 +7,6 @@ import (
 	"github.com/labring/aiproxy/core/relay/utils"
 )
 
-func GetEmbedRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
-	return mc.Price, nil
-}
-
 func GetEmbedRequestUsage(c *gin.Context, _ model.ModelConfig) (model.Usage, error) {
 	textRequest, err := utils.UnmarshalGeneralOpenAIRequest(c.Request)
 	if err != nil {

+ 0 - 4
core/relay/controller/pdf.go

@@ -5,10 +5,6 @@ import (
 	"github.com/labring/aiproxy/core/model"
 )
 
-func GetPdfRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
-	return mc.Price, nil
-}
-
 func GetPdfRequestUsage(_ *gin.Context, _ model.ModelConfig) (model.Usage, error) {
 	return model.Usage{}, nil
 }

+ 0 - 4
core/relay/controller/rerank.go

@@ -40,10 +40,6 @@ func rerankPromptTokens(rerankRequest *relaymodel.RerankRequest) int64 {
 	return tokens
 }
 
-func GetRerankRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
-	return mc.Price, nil
-}
-
 func GetRerankRequestUsage(c *gin.Context, _ model.ModelConfig) (model.Usage, error) {
 	rerankRequest, err := getRerankRequest(c)
 	if err != nil {

+ 10 - 0
core/relay/controller/responses.go

@@ -0,0 +1,10 @@
+package controller
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/labring/aiproxy/core/model"
+)
+
+func GetResponsesRequestUsage(c *gin.Context, _ model.ModelConfig) (model.Usage, error) {
+	return model.Usage{}, nil
+}

+ 0 - 4
core/relay/controller/stt.go

@@ -14,10 +14,6 @@ import (
 	"github.com/labring/aiproxy/core/relay/adaptor/openai"
 )
 
-func GetSTTRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
-	return mc.Price, nil
-}
-
 func GetSTTRequestUsage(c *gin.Context, mc model.ModelConfig) (model.Usage, error) {
 	audioFile, err := c.FormFile("file")
 	if err != nil {

+ 0 - 4
core/relay/controller/tts.go

@@ -8,10 +8,6 @@ import (
 	"github.com/labring/aiproxy/core/relay/utils"
 )
 
-func GetTTSRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
-	return mc.Price, nil
-}
-
 func GetTTSRequestUsage(c *gin.Context, _ model.ModelConfig) (model.Usage, error) {
 	ttsRequest, err := utils.UnmarshalTTSRequest(c.Request)
 	if err != nil {

+ 0 - 4
core/relay/controller/video.go

@@ -6,10 +6,6 @@ import (
 	"github.com/labring/aiproxy/core/relay/utils"
 )
 
-func GetVideoGenerationJobRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
-	return mc.Price, nil
-}
-
 func GetVideoGenerationJobRequestUsage(c *gin.Context, _ model.ModelConfig) (model.Usage, error) {
 	_, err := utils.UnmarshalVideoGenerationJobRequest(c.Request)
 	if err != nil {