image.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package model
  2. import "github.com/labring/aiproxy/core/model"
  3. // https://platform.openai.com/docs/api-reference/images/create
  4. type ImageRequest struct {
  5. Model string `json:"model"`
  6. Prompt string `json:"prompt"`
  7. Background string `json:"background,omitempty"`
  8. Moderation string `json:"moderation,omitempty"`
  9. OutputCompression int `json:"output_compression,omitempty"`
  10. OutputFormat string `json:"output_format,omitempty"` // png, jpeg, webp
  11. Size string `json:"size,omitempty"` // 1024x1024, 1536x1024, 1024x1536, auto, 256x256, 512x512, 1792x1024, 1024x1792
  12. Quality string `json:"quality,omitempty"` // auto, high, medium, low, hd, standard
  13. ResponseFormat string `json:"response_format,omitempty"` // url, b64_json
  14. Style string `json:"style,omitempty"` // vivid, natural
  15. User string `json:"user,omitempty"`
  16. N int `json:"n,omitempty"`
  17. }
  18. type ImageData struct {
  19. URL string `json:"url,omitempty"`
  20. B64Json string `json:"b64_json,omitempty"`
  21. RevisedPrompt string `json:"revised_prompt,omitempty"`
  22. }
  23. type ImageResponse struct {
  24. Created int64 `json:"created"`
  25. Data []*ImageData `json:"data"`
  26. // For gpt-image-1 only, the token usage information for the image generation.
  27. Usage *ImageUsage `json:"usage"`
  28. }
  29. type ImageUsage struct {
  30. // The number of tokens (images and text) in the input prompt.
  31. InputTokens int64 `json:"input_tokens"`
  32. // The number of image tokens in the output image.
  33. OutputTokens int64 `json:"output_tokens"`
  34. // The total number of tokens (images and text) used for the image generation.
  35. TotalTokens int64 `json:"total_tokens"`
  36. // The input tokens detailed information for the image generation.
  37. InputTokensDetails ImageInputTokensDetails `json:"input_tokens_details"`
  38. }
  39. func (i *ImageUsage) ToModelUsage() model.Usage {
  40. return model.Usage{
  41. InputTokens: model.ZeroNullInt64(i.InputTokens),
  42. ImageInputTokens: model.ZeroNullInt64(i.InputTokensDetails.ImageTokens),
  43. OutputTokens: model.ZeroNullInt64(i.OutputTokens),
  44. TotalTokens: model.ZeroNullInt64(i.TotalTokens),
  45. }
  46. }
  47. type ImageInputTokensDetails struct {
  48. // The number of text tokens in the input prompt.
  49. TextTokens int64 `json:"text_tokens"`
  50. // The number of image tokens in the input prompt.
  51. ImageTokens int64 `json:"image_tokens"`
  52. }