embed.go 659 B

1234567891011121314151617181920212223242526
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/labring/aiproxy/core/model"
  5. "github.com/labring/aiproxy/core/relay/adaptor/openai"
  6. "github.com/labring/aiproxy/core/relay/utils"
  7. )
  8. func GetEmbedRequestPrice(_ *gin.Context, mc model.ModelConfig) (model.Price, error) {
  9. return mc.Price, nil
  10. }
  11. func GetEmbedRequestUsage(c *gin.Context, _ model.ModelConfig) (model.Usage, error) {
  12. textRequest, err := utils.UnmarshalGeneralOpenAIRequest(c.Request)
  13. if err != nil {
  14. return model.Usage{}, err
  15. }
  16. return model.Usage{
  17. InputTokens: model.ZeroNullInt64(openai.CountTokenInput(
  18. textRequest.Input,
  19. textRequest.Model,
  20. )),
  21. }, nil
  22. }