diff --git a/README.md b/README.md index 94e6054..11f5858 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # ComfyUI-YCYY-API -Call API in ComfyUI +Freely call APIs in ComfyUI + diff --git a/gemini_image_node.py b/gemini_image_node.py index 17f7e22..6adf11b 100644 --- a/gemini_image_node.py +++ b/gemini_image_node.py @@ -206,7 +206,7 @@ class GeminiImage(io.ComfyNode): return cls._parse_response(resp) except Exception as e: empty_image = cls._create_empty_image() - return io.NodeOutput(empty_image,"API请求失败,请检查接口地址和 KEY 是否正确") + return io.NodeOutput(empty_image,f'{{"success":false,"message":"The API request failed. Please check if the interface address and key are correct."}}') # 将图像张量输入转换为与 Gemini API 兼容的格式。 @classmethod def _create_image_parts(cls,image_input): @@ -257,24 +257,24 @@ class GeminiImage(io.ComfyNode): return cls._parse_response(resp) except Exception as e: empty_image = cls._create_empty_image() - return io.NodeOutput(empty_image,"API请求失败,请检查接口地址和 KEY 是否正确") + return io.NodeOutput(empty_image,f'{{"success":false,"message":"The API request failed. Please check if the interface address and key are correct."}}') # 解析response 返回内容 @classmethod def _parse_response(cls,resp): # 检查HTTP状态码 if resp.status_code != 200: empty_image = cls._create_empty_image() - return (empty_image,f"API请求返回错误 (状态码: {resp.status_code}):(错误原因:{resp.text})") + return (empty_image,f'{{"success":false,"message":"API request returns an error.status_code:{resp.status_code}.error_reason:{resp.text}"}}') # 检查返回内容是否为空 if not resp.text.strip(): empty_image = cls._create_empty_image() - return (empty_image,"API返回内容为空") + return (empty_image,f'{{"success":false,"message":"The API returns an empty content"}}') try: data = resp.json() except Exception as json_exception: # print(f"JSON解析失败:{json_exception}") empty_image = cls._create_empty_image() - return (empty_image,"API返回JSON解析失败") + return (empty_image,f'{{"success":false,"message":"The API returned a JSON parsing failure"}}') # 解析响应数据 if "candidates" in data and data["candidates"]: candidate = data["candidates"][0] @@ -295,7 +295,7 @@ class GeminiImage(io.ComfyNode): else: # print(f"未找到imag数据") empty_image = cls._create_empty_image() - return (empty_image,"未找到imag数据") + return (empty_image,f'{{"success":false,"message":"Imag data not found"}}') # 将返回的图像数据解析为 comfyui 格式的 image @classmethod def _image_data_to_comfyui_image(cls,image_date): @@ -307,14 +307,14 @@ class GeminiImage(io.ComfyNode): return image_tensor except Exception as e: empty_image = cls._create_empty_image() - return io.NodeOutput(empty_image,"返回图像数据解析异常") + return io.NodeOutput(empty_image,f'{{"success":false,"message":"Return image data parsing exception"}}') # 获取token用量 @classmethod def _format_tokens_usage(cls,usageMetadata): if not usageMetadata: return "" total_tokens = usageMetadata.get('totalTokenCount', '-') - return f"{{\"success\":true,\"total_tokens\":{total_tokens}}}" + return f'{{"success":true,"message":"total_tokens:{total_tokens}"}}' # 创建空图像 @classmethod def _create_empty_image(cls): diff --git a/locales/en/nodeDefs.json b/locales/en/nodeDefs.json new file mode 100644 index 0000000..47043dd --- /dev/null +++ b/locales/en/nodeDefs.json @@ -0,0 +1,33 @@ +{ + "YCYY_Gemini_Image_API": { + "display_name": "YCYY Gemini Image API", + "inputs": { + "images": { + "name": "image", + "tooltip": "Optional image(s) to use as context for the model" + }, + "prompt": { + "name": "prompt" + }, + "model": { + "name": "model" + }, + "aspectRatio": { + "name": "aspectRatio", + "tooltip": "The model defaults to matching the output image size to that of your input image, or otherwise generates 1:1 squares. You can control the aspect ratio of the output image using the aspect ratio" + }, + "seed": { + "name": "seed", + "tooltip": "Seed to use for generation" + } + }, + "outputs": { + "0": { + "name": "Image" + }, + "1": { + "name": "String" + } + } + } +} \ No newline at end of file diff --git a/locales/zh/nodeDefs.json b/locales/zh/nodeDefs.json new file mode 100644 index 0000000..0500ce2 --- /dev/null +++ b/locales/zh/nodeDefs.json @@ -0,0 +1,33 @@ +{ + "YCYY_Gemini_Image_API": { + "display_name": "浥尘 Gemini 图像 API", + "inputs": { + "images": { + "name": "图像", + "tooltip": "可选的图像,用作模型的上下文" + }, + "prompt": { + "name": "prompt" + }, + "model": { + "name": "模型" + }, + "aspectRatio": { + "name": "图像宽高比", + "tooltip": "该模型默认将输出图像大小与输入图像大小匹配,否则生成 1:1 正方形。您可以使用宽高比来控制输出图像的宽高比。" + }, + "seed": { + "name": "种子", + "tooltip": "用于生成噪声的随机种子。" + } + }, + "outputs": { + "0": { + "name": "图像" + }, + "1": { + "name": "字符串" + } + } + } +} \ No newline at end of file