refactor: simplify optional parameters and update image generation base URL

This commit is contained in:
wxg0103 2025-07-09 15:45:35 +08:00
parent a5cd50fdf2
commit eceb8f8375

View File

@ -30,7 +30,7 @@ class QwenTextToImageModel(MaxKBBaseModel, BaseTextToImage):
@staticmethod @staticmethod
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs): def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
optional_params = {'params': {'size': '1024*1024', 'style': '<auto>', 'n': 1}} optional_params = {'params': {'size': '1024*1024', 'n': 1}}
for key, value in model_kwargs.items(): for key, value in model_kwargs.items():
if key not in ['model_id', 'use_local', 'streaming']: if key not in ['model_id', 'use_local', 'streaming']:
optional_params['params'][key] = value optional_params['params'][key] = value
@ -41,17 +41,14 @@ class QwenTextToImageModel(MaxKBBaseModel, BaseTextToImage):
) )
return chat_tong_yi return chat_tong_yi
def is_cache_model(self):
return False
def check_auth(self): def check_auth(self):
chat = ChatTongyi(api_key=self.api_key, model_name='qwen-max') chat = ChatTongyi(api_key=self.api_key, model_name='qwen-max')
chat.invoke([HumanMessage([{"type": "text", "text": gettext('Hello')}])]) chat.invoke([HumanMessage([{"type": "text", "text": gettext('Hello')}])])
def generate_image(self, prompt: str, negative_prompt: str = None): def generate_image(self, prompt: str, negative_prompt: str = None):
# api_base='https://dashscope.aliyuncs.com/compatible-mode/v1',
rsp = ImageSynthesis.call(api_key=self.api_key, rsp = ImageSynthesis.call(api_key=self.api_key,
model=self.model_name, model=self.model_name,
base_url='https://dashscope.aliyuncs.com/compatible-mode/v1',
prompt=prompt, prompt=prompt,
negative_prompt=negative_prompt, negative_prompt=negative_prompt,
**self.params) **self.params)