From 8c2b53cffbf8542032a9c43e8528e6393f0a7063 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Sat, 9 Dec 2023 22:17:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20openai>=3D1.0=E6=97=B6=E7=BB=98?= =?UTF-8?q?=E5=9B=BE=E5=91=BD=E4=BB=A4=E4=B8=8D=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 8 ++++++-- pkg/openai/manager.py | 5 +++-- pkg/qqbot/cmds/funcs/draw.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/config-template.py b/config-template.py index 4ddc4135..87234f29 100644 --- a/config-template.py +++ b/config-template.py @@ -260,9 +260,13 @@ } # OpenAI的Image API的参数 -# 具体请查看OpenAI的文档: https://beta.openai.com/docs/api-reference/images/create +# 具体请查看OpenAI的文档: https://platform.openai.com/docs/api-reference/images/create image_api_params = { - "size": "256x256", # 图片尺寸,支持256x256, 512x512, 1024x1024 + "model": "dall-e-2", # 默认使用 dall-e-2 模型,也可以改为 dall-e-3 + # 图片尺寸 + # dall-e-2 模型支持 256x256, 512x512, 1024x1024 + # dall-e-3 模型支持 1024x1024, 1792x1024, 1024x1792 + "size": "256x256", } # 跟踪函数调用 diff --git a/pkg/openai/manager.py b/pkg/openai/manager.py index 0fd008b9..8b2b6145 100644 --- a/pkg/openai/manager.py +++ b/pkg/openai/manager.py @@ -1,6 +1,7 @@ import logging import openai +from openai.types import images_response from ..openai import keymgr from ..utils import context @@ -65,7 +66,7 @@ def request_completion(self, messages: list): yield resp - def request_image(self, prompt) -> dict: + def request_image(self, prompt) -> images_response.ImagesResponse: """请求图片接口回复 Parameters: @@ -77,7 +78,7 @@ def request_image(self, prompt) -> dict: config = context.get_config_manager().data params = config['image_api_params'] - response = openai.Image.create( + response = self.client.images.generate( prompt=prompt, n=1, **params diff --git a/pkg/qqbot/cmds/funcs/draw.py b/pkg/qqbot/cmds/funcs/draw.py index 315c89e3..5ce25ad5 100644 --- a/pkg/qqbot/cmds/funcs/draw.py +++ b/pkg/qqbot/cmds/funcs/draw.py @@ -29,7 +29,7 @@ def process(cls, ctx: aamgr.Context) -> tuple[bool, list]: res = session.draw_image(" ".join(ctx.params)) logging.debug("draw_image result:{}".format(res)) - reply = [mirai.Image(url=res['data'][0]['url'])] + reply = [mirai.Image(url=res.data[0].url)] config = context.get_config_manager().data if config['include_image_description']: reply.append(" ".join(ctx.params)) From 9590718da4b9d61d9e5dbfe2c2a2b4b1ea1d049d Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 9 Dec 2023 14:17:55 +0000 Subject: [PATCH 2/2] Update override-all.json --- override-all.json | 1 + 1 file changed, 1 insertion(+) diff --git a/override-all.json b/override-all.json index 75f65320..1b706c88 100644 --- a/override-all.json +++ b/override-all.json @@ -60,6 +60,7 @@ "temperature": 0.9 }, "image_api_params": { + "model": "dall-e-2", "size": "256x256" }, "trace_function_calls": false,