Skip to content

Commit 00bcd80

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

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
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='1024*1024',
26+
option_list=[
27+
{'value': '1024*1024', 'label': '1024*1024'},
28+
{'value': '720*1280', 'label': '720*1280'},
29+
{'value': '768*1152', 'label': '768*1152'},
30+
{'value': '1280*720', 'label': '1280*720'},
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: 2 additions & 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': '1024*1024', '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
@@ -50,6 +50,7 @@ def generate_image(self, prompt: str, negative_prompt: str = None):
5050
prompt=prompt,
5151
negative_prompt=negative_prompt,
5252
**self.params)
53+
print(rsp)
5354
file_urls = []
5455
if rsp.status_code == HTTPStatus.OK:
5556
for result in rsp.output.results:

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@
88

99

1010
class ZhiPuTTIModelParams(BaseForm):
11-
size = forms.TextInputField(
11+
size = forms.SingleSelect(
1212
TooltipLabel('图片尺寸',
1313
'图片尺寸,仅 cogview-3-plus 支持该参数。可选范围:[1024x1024,768x1344,864x1152,1344x768,1152x864,1440x720,720x1440],默认是1024x1024。'),
14-
required=True, default_value='1024x1024')
14+
required=True,
15+
default_value='1024x1024',
16+
option_list=[
17+
{'value': '1024x1024', 'label': '1024x1024'},
18+
{'value': '768x1344', 'label': '768x1344'},
19+
{'value': '864x1152', 'label': '864x1152'},
20+
{'value': '1344x768', 'label': '1344x768'},
21+
{'value': '1152x864', 'label': '1152x864'},
22+
{'value': '1440x720', 'label': '1440x720'},
23+
{'value': '720x1440', 'label': '720x1440'},
24+
],
25+
text_field='label',
26+
value_field='value')
1527

1628

1729
class ZhiPuTextToImageModelCredential(BaseForm, BaseModelCredential):

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)