diff --git a/comfy_api_nodes/nodes_vertex_gemini.py b/comfy_api_nodes/nodes_vertex_gemini.py new file mode 100644 index 000000000..2349ac445 --- /dev/null +++ b/comfy_api_nodes/nodes_vertex_gemini.py @@ -0,0 +1,71 @@ +from inspect import cleandoc +from google import genai +from google.genai.types import HttpOptions + +from comfy.comfy_types.node_typing import IO, ComfyNodeABC, InputTypeDict +from comfy_api_nodes.apinode_utils import validate_string +from server import PromptServer + + +class VertexGeminiAPI(ComfyNodeABC): + """ + Generates images synchronously via OpenAI's GPT Image 1 endpoint. + """ + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls) -> InputTypeDict: + return { + "required": { + "prompt": ( + IO.STRING, + { + "multiline": True, + "default": "", + "tooltip": "Text prompt for GPT Image 1", + }, + ), + "model": ( + IO.STRING, + { + "default": "gemini-2.0-flash-001", + "tooltip": "The gemini model to use" + } + ) + }, + } + + RETURN_TYPES = (IO.STRING,) + FUNCTION = "api_call" + CATEGORY = "api node/text/gemini/vertex" + DESCRIPTION = cleandoc(__doc__ or "") + API_NODE = True + + def api_call( + self, + prompt, + model="gemini-2.0-flash-001", + **kwargs + ): + validate_string(prompt, strip_whitespace=False) + client = genai.Client(http_options=HttpOptions(api_version="v1")) + response = client.models.generate_content( + model=model, + contents=prompt, + ) + print(response.text) + PromptServer.instance.send_progress_text(response.text) + return response.text + +# A dictionary that contains all nodes you want to export with their names +# NOTE: names should be globally unique +NODE_CLASS_MAPPINGS = { + "VertexGeminiAPI": VertexGeminiAPI, +} + +# A dictionary that contains the friendly/humanly readable titles for the nodes +NODE_DISPLAY_NAME_MAPPINGS = { + "VertexGeminiAPI": "VertexGeminiAPI", +} \ No newline at end of file diff --git a/nodes.py b/nodes.py index 54e3886a3..33c911207 100644 --- a/nodes.py +++ b/nodes.py @@ -2280,6 +2280,7 @@ def init_builtin_api_nodes(): api_nodes_files = [ "nodes_ideogram.py", "nodes_openai.py", + "nodes_vertex_gemini.py", "nodes_minimax.py", "nodes_veo2.py", "nodes_kling.py", diff --git a/requirements.txt b/requirements.txt index 8f7a78984..ef3dbc9f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,6 +17,7 @@ Pillow scipy tqdm psutil +google-genai #non essential dependencies: kornia>=0.7.1