From 6126024f2c94e6e56accd013736d4c0427e9596e Mon Sep 17 00:00:00 2001 From: Skyzayre <120616113+Skyzayre@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:36:59 +0800 Subject: [PATCH] =?UTF-8?q?dall-e-3=E6=B7=BB=E5=8A=A0=20'style'=20?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dall-e-3添加 'style' 风格参数(参考 platform.openai.com/doc/api-reference),修改dall-e-3作图时的参数判断逻辑 --- crazy_functions/图片生成.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/crazy_functions/图片生成.py b/crazy_functions/图片生成.py index 642a9e2..104d403 100644 --- a/crazy_functions/图片生成.py +++ b/crazy_functions/图片生成.py @@ -2,7 +2,7 @@ from toolbox import CatchException, update_ui, get_conf, select_api_key, get_log from crazy_functions.multi_stage.multi_stage_utils import GptAcademicState -def gen_image(llm_kwargs, prompt, resolution="1024x1024", model="dall-e-2", quality=None): +def gen_image(llm_kwargs, prompt, resolution="1024x1024", model="dall-e-2", quality=None, style=None): import requests, json, time, os from request_llms.bridge_all import model_info @@ -25,7 +25,10 @@ def gen_image(llm_kwargs, prompt, resolution="1024x1024", model="dall-e-2", qual 'model': model, 'response_format': 'url' } - if quality is not None: data.update({'quality': quality}) + if quality is not None: + data['quality'] = quality + if style is not None: + data['style'] = style response = requests.post(url, headers=headers, json=data, proxies=proxies) print(response.content) try: @@ -115,13 +118,18 @@ def 图片生成_DALLE3(prompt, llm_kwargs, plugin_kwargs, chatbot, history, sys chatbot.append(("您正在调用“图像生成”插件。", "[Local Message] 生成图像, 请先把模型切换至gpt-*或者api2d-*。如果中文Prompt效果不理想, 请尝试英文Prompt。正在处理中 .....")) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 由于请求gpt需要一段时间,我们先及时地做一次界面更新 if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg") - resolution = plugin_kwargs.get("advanced_arg", '1024x1024').lower() - if resolution.endswith('-hd'): - resolution = resolution.replace('-hd', '') - quality = 'hd' - else: - quality = 'standard' - image_url, image_path = gen_image(llm_kwargs, prompt, resolution, model="dall-e-3", quality=quality) + resolution_arg = plugin_kwargs.get("advanced_arg", '1024x1024-standard-vivid').lower() + parts = resolution_arg.split('-') + resolution = parts[0] # 解析分辨率 + quality = 'standard' # 质量与风格默认值 + style = 'vivid' + # 遍历检查是否有额外参数 + for part in parts[1:]: + if part in ['hd', 'standard']: + quality = part + elif part in ['vivid', 'natural']: + style = part + image_url, image_path = gen_image(llm_kwargs, prompt, resolution, model="dall-e-3", quality=quality, style=style) chatbot.append([prompt, f'图像中转网址:
`{image_url}`
'+ f'中转网址预览:
' @@ -201,4 +209,3 @@ def 图片修改_DALLE2(prompt, llm_kwargs, plugin_kwargs, chatbot, history, sys f'本地文件预览:
' ]) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 界面更新 -