image_wan.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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") &&
  37. !lo.SomeBy([]string{"wan2.6", "wan2.7"}, func(v string) bool { return strings.Contains(modelName, v) })
  38. }
  39. func isWanModel(modelName string) bool {
  40. return strings.Contains(modelName, "wan")
  41. }