MCPcopy Index your code
hub / github.com/HisMax/RedInk / generate_image

Method generate_image

backend/generators/image_api.py:51–89  ·  view source on GitHub ↗

生成图片 Args: prompt: 图片描述 aspect_ratio: 宽高比 temperature: 创意度(未使用,保留接口兼容) model: 模型名称 reference_image: 单张参考图片数据(向后兼容) reference_images: 多张参考图片数据列表 Returns: 生成的图片二进制数据

(
        self,
        prompt: str,
        aspect_ratio: str = None,
        temperature: float = 1.0,
        model: str = None,
        reference_image: Optional[bytes] = None,
        reference_images: Optional[List[bytes]] = None,
        **kwargs
    )

Source from the content-addressed store, hash-verified

49 return ["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"]
50
51 def generate_image(
52 self,
53 prompt: str,
54 aspect_ratio: str = None,
55 temperature: float = 1.0,
56 model: str = None,
57 reference_image: Optional[bytes] = None,
58 reference_images: Optional[List[bytes]] = None,
59 **kwargs
60 ) -> bytes:
61 """
62 生成图片
63
64 Args:
65 prompt: 图片描述
66 aspect_ratio: 宽高比
67 temperature: 创意度(未使用,保留接口兼容)
68 model: 模型名称
69 reference_image: 单张参考图片数据(向后兼容)
70 reference_images: 多张参考图片数据列表
71
72 Returns:
73 生成的图片二进制数据
74 """
75 self.validate_config()
76
77 if aspect_ratio is None:
78 aspect_ratio = self.default_aspect_ratio
79
80 if model is None:
81 model = self.model
82
83 logger.info(f"Image API 生成图片: model={model}, aspect_ratio={aspect_ratio}, endpoint={self.endpoint_type}")
84
85 # 根据端点类型选择不同的生成方式
86 if 'chat' in self.endpoint_type or 'completions' in self.endpoint_type:
87 return self._generate_via_chat_api(prompt, aspect_ratio, model, reference_image, reference_images)
88 else:
89 return self._generate_via_images_api(prompt, aspect_ratio, model, reference_image, reference_images)
90
91 def _generate_via_images_api(
92 self,

Callers

nothing calls this directly

Calls 3

validate_configMethod · 0.95

Tested by

no test coverage detected