Skip to content

Commit cb04b7b

Browse files
committed
feat: 支持添加图片生成模型(WIP)
1 parent 592a9fd commit cb04b7b

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

apps/setting/models_provider/impl/openai_model_provider/credential/tti.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@
1010
from common.forms import BaseForm, TooltipLabel
1111
from setting.models_provider.base_model_provider import BaseModelCredential, ValidCode
1212

13+
1314
class OpenAITTIModelParams(BaseForm):
14-
size = forms.TextInputField(
15+
size = forms.SingleSelect(
1516
TooltipLabel('图片尺寸', '指定生成图片的尺寸, 如: 1024x1024'),
16-
required=True, default_value='1024x1024')
17+
required=True,
18+
default_value='1024x1024',
19+
option_list=[
20+
{'value': '1024x1024', 'label': '1024x1024'},
21+
{'value': '1024x1792', 'label': '1024x1792'},
22+
{'value': '1792x1024', 'label': '1792x1024'},
23+
],
24+
text_field='label',
25+
value_field='value'
26+
)
1727

1828
quality = forms.TextInputField(
1929
TooltipLabel('图片质量', ''),

apps/setting/models_provider/impl/openai_model_provider/model/tti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, **kwargs):
3232

3333
@staticmethod
3434
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
35-
optional_params = {'params': {}}
35+
optional_params = {'params': {'size': '1024x1024', 'quality': 'standard', 'n': 1}}
3636
for key, value in model_kwargs.items():
3737
if key not in ['model_id', 'use_local', 'streaming']:
3838
optional_params['params'][key] = value

apps/setting/models_provider/impl/qwen_model_provider/credential/tti.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,18 @@
1919

2020

2121
class QwenModelParams(BaseForm):
22-
size = forms.TextInputField(
22+
size = forms.SingleSelect(
2323
TooltipLabel('图片尺寸', '指定生成图片的尺寸, 如: 1024x1024'),
24-
required=True, default_value='1024x1024')
24+
required=True,
25+
default_value='1024x1024',
26+
option_list=[
27+
{'value': '1024x1024', 'label': '1024x1024'},
28+
{'value': '720x1280', 'label': '720x1280'},
29+
{'value': '768x1152', 'label': '768x1152'},
30+
{'value': '1280x720', 'label': '1280x720'},
31+
],
32+
text_field='label',
33+
value_field='value')
2534
n = forms.SliderField(
2635
TooltipLabel('图片数量', '指定生成图片的数量'),
2736
required=True, default_value=1,

apps/setting/models_provider/impl/qwen_model_provider/model/tti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, **kwargs):
2828

2929
@staticmethod
3030
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
31-
optional_params = {'params': {}}
31+
optional_params = {'params': {'size': '1024x1024', 'style': '<auto>', 'n': 1}}
3232
for key, value in model_kwargs.items():
3333
if key not in ['model_id', 'use_local', 'streaming']:
3434
optional_params['params'][key] = value

apps/setting/models_provider/impl/zhipu_model_provider/credential/tti.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ class ZhiPuTTIModelParams(BaseForm):
1313
'图片尺寸,仅 cogview-3-plus 支持该参数。可选范围:[1024x1024,768x1344,864x1152,1344x768,1152x864,1440x720,720x1440],默认是1024x1024。'),
1414
required=True, default_value='1024x1024')
1515

16+
size = forms.SingleSelect(
17+
TooltipLabel('图片尺寸',
18+
'图片尺寸,仅 cogview-3-plus 支持该参数。可选范围:[1024x1024,768x1344,864x1152,1344x768,1152x864,1440x720,720x1440],默认是1024x1024。'),
19+
required=True,
20+
default_value='1024x1024',
21+
option_list=[
22+
{'value': '1024x1024', 'label': '1024x1024'},
23+
{'value': '768x1344', 'label': '768x1344'},
24+
{'value': '864x1152', 'label': '864x1152'},
25+
{'value': '1344x768', 'label': '1344x768'},
26+
{'value': '1152x864', 'label': '1152x864'},
27+
{'value': '1440x720', 'label': '1440x720'},
28+
{'value': '720x1440', 'label': '720x1440'},
29+
],
30+
text_field='label',
31+
value_field='value')
32+
1633

1734
class ZhiPuTextToImageModelCredential(BaseForm, BaseModelCredential):
1835
api_key = forms.PasswordInputField('API Key', required=True)

apps/setting/models_provider/impl/zhipu_model_provider/model/tti.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, **kwargs):
3030

3131
@staticmethod
3232
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
33-
optional_params = {'params': {}}
33+
optional_params = {'params': {'size': '1024x1024'}}
3434
for key, value in model_kwargs.items():
3535
if key not in ['model_id', 'use_local', 'streaming']:
3636
optional_params['params'][key] = value
@@ -62,7 +62,7 @@ def generate_image(self, prompt: str, negative_prompt: str = None):
6262
)
6363
file_urls = []
6464
for content in response.data:
65-
url = content['url']
65+
url = content.url
6666
print(url)
6767
file_name = url.split('/')[-1]
6868
file = bytes_to_uploaded_file(requests.get(url).content, file_name)

0 commit comments

Comments
 (0)