image_wan.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package ali
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/QuantumNous/new-api/common"
  6. "github.com/QuantumNous/new-api/dto"
  7. relaycommon "github.com/QuantumNous/new-api/relay/common"
  8. "github.com/gin-gonic/gin"
  9. "github.com/samber/lo"
  10. )
  11. func oaiFormEdit2WanxImageEdit(c *gin.Context, info *relaycommon.RelayInfo, request dto.ImageRequest) (*AliImageRequest, error) {
  12. var err error
  13. var imageRequest AliImageRequest
  14. imageRequest.Model = request.Model
  15. imageRequest.ResponseFormat = request.ResponseFormat
  16. wanInput := WanImageInput{
  17. Prompt: request.Prompt,
  18. }
  19. if err := common.UnmarshalBodyReusable(c, &wanInput); err != nil {
  20. return nil, err
  21. }
  22. if wanInput.Images, err = getImageBase64sFromForm(c, "image"); err != nil {
  23. return nil, fmt.Errorf("get image base64s from form failed: %w", err)
  24. }
  25. //wanParams := WanImageParameters{
  26. // N: int(request.N),
  27. //}
  28. imageRequest.Input = wanInput
  29. imageRequest.Parameters = AliImageParameters{
  30. N: int(lo.FromPtrOr(request.N, uint(1))),
  31. }
  32. info.PriceData.AddOtherRatio("n", float64(imageRequest.Parameters.N))
  33. return &imageRequest, nil
  34. }
  35. func isOldWanModel(modelName string) bool {
  36. return strings.Contains(modelName, "wan") && !strings.Contains(modelName, "wan2.6")
  37. }
  38. func isWanModel(modelName string) bool {
  39. return strings.Contains(modelName, "wan")
  40. }