XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

fix(ImageGenerationConfig): add size="WxH" support - Parse `size` string (e.g., "256x256") to auto-set `width` and `height` - Keep explicit `width`/`height` priority if both provided

Fixes xtekky#2902

2fd5d773
BuT9l3b <artiom.lazukov2017@yandex.ru>
提交于

代码差异

1 个文件 +15 -1
Modified g4f/api/stubs.py +15 -1
@@ -1,6 +1,6 @@
1 1 from __future__ import annotations
2 2
3 from pydantic import BaseModel, Field
3 from pydantic import BaseModel, Field, model_validator
4 4 from typing import Union, Optional
5 5 try:
6 6 from typing import Annotated
@@ -70,6 +70,20 @@ class ImageGenerationConfig(BaseModel):
70 70 negative_prompt: Optional[str] = None
71 71 resolution: Optional[str] = None
72 72
73 @model_validator(mode='before')
74 def parse_size(cls, values):
75 if values.get('width') is not None and values.get('height') is not None:
76 return values
77
78 size = values.get('size')
79 if size:
80 try:
81 width, height = map(int, size.split('x'))
82 values['width'] = width
83 values['height'] = height
84 except (ValueError, AttributeError): pass # If the format is incorrect, we simply ignore it.
85 return values
86
73 87 class ProviderResponseModel(BaseModel):
74 88 id: str
75 89 object: str = "provider"