Skip to content

Commit

Permalink
change image_gen tool about lora,fix modelscope#455
Browse files Browse the repository at this point in the history
  • Loading branch information
mushenL committed May 24, 2024
1 parent 8593404 commit 0993bb6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions modelscope_agent/tools/dashscope_tools/image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class TextToImageTool(BaseTool):
'格式是 数字*数字,表示希望生成的图像的分辨率大小,选项有[1024*1024, 720*1280, 1280*720]',
'required': True,
'type': 'string'
}, {
'name': 'lora_index',
'description':
'如果用户指定使用lora则使用该参数,通过选择的lora层来决定生成的图像的风格,如果用户没有制定,则默认为wanxlite1.4.5_lora_huibenlite1_20240519',
'required': False,
'type': 'string'
}]

def call(self, params: str, **kwargs) -> str:
Expand All @@ -38,7 +44,12 @@ def call(self, params: str, **kwargs) -> str:
if prompt is None:
return None
seed = kwargs.get('seed', None)
model = kwargs.get('model', 'wanx-v1')
model = kwargs.get('model', 'wanx-lora-lite')
lora_index = params.get('lora_index', None)
if lora_index:
extra_input = {'lora_index': lora_index}
else:
extra_input = None
try:
dashscope.api_key = get_api_key(ApiNames.dashscope_api_key,
**kwargs)
Expand All @@ -51,6 +62,7 @@ def call(self, params: str, **kwargs) -> str:
n=1,
size=resolution,
steps=10,
seed=seed)
seed=seed,
extra_input=extra_input)
image_url = response.output['results'][0]['url']
return f'![IMAGEGEN]({image_url})'

0 comments on commit 0993bb6

Please sign in to comment.