Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ComfyUI/comfy_api_nodes/apis/request_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import logging
import folder_paths

from typing import Optional, Any
# Get the logger instance
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -40,13 +40,13 @@ def log_request_response(
operation_id: str,
request_method: str,
request_url: str,
request_headers: dict | None = None,
request_params: dict | None = None,
request_data: any = None,
response_status_code: int | None = None,
response_headers: dict | None = None,
response_content: any = None,
error_message: str | None = None
request_headers: Optional[dict] = None,
request_params: Optional[dict] = None,
request_data: Any = None,
response_status_code: Optional[int] = None,
response_headers: Optional[dict] = None,
response_content: Any = None,
error_message: Optional[str] = None
):
"""
Logs API request and response details to a file in the temp/api_logs directory.
Expand Down
95 changes: 39 additions & 56 deletions ComfyUI/comfy_api_nodes/nodes_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,51 +312,41 @@ def api_call(
unique_id: Optional[str] = None,
**kwargs,
) -> tuple[str]:
try:
# Validate inputs
validate_string(prompt, strip_whitespace=False)

# Create parts list with text prompt as the first part
parts: list[GeminiPart] = [self.create_text_part(prompt)]

# Add other modal parts
if images is not None:
image_parts = self.create_image_parts(images)
parts.extend(image_parts)
if audio is not None:
parts.extend(self.create_audio_parts(audio))
if video is not None:
parts.extend(self.create_video_parts(video))
if files is not None:
parts.extend(files)

# Create response
response = SynchronousOperation(
endpoint=get_gemini_endpoint(model),
request=GeminiGenerateContentRequest(
contents=[
GeminiContent(
role="user",
parts=parts,
)
]
),
auth_kwargs=kwargs,
).execute()

# Get result output
output_text = self.get_text_from_response(response)
if unique_id and output_text:
PromptServer.instance.send_progress_text(output_text, node_id=unique_id)

except Exception as e:
# Handle API errors, network issues, and validation failures gracefully
error_message = f"Gemini API Error: {str(e)}"
print(f"[GeminiNode] {error_message}") # Log full error for debugging
sanitized_message = "An error occurred while processing your request. Please try again later."
if unique_id:
PromptServer.instance.send_progress_text(sanitized_message, node_id=unique_id)
output_text = sanitized_message
# Validate inputs
validate_string(prompt, strip_whitespace=False)

# Create parts list with text prompt as the first part
parts: list[GeminiPart] = [self.create_text_part(prompt)]

# Add other modal parts
if images is not None:
image_parts = self.create_image_parts(images)
parts.extend(image_parts)
if audio is not None:
parts.extend(self.create_audio_parts(audio))
if video is not None:
parts.extend(self.create_video_parts(video))
if files is not None:
parts.extend(files)

# Create response
response = SynchronousOperation(
endpoint=get_gemini_endpoint(model),
request=GeminiGenerateContentRequest(
contents=[
GeminiContent(
role="user",
parts=parts,
)
]
),
auth_kwargs=kwargs,
).execute()

# Get result output
output_text = self.get_text_from_response(response)
if unique_id and output_text:
PromptServer.instance.send_progress_text(output_text, node_id=unique_id)

return (output_text or "Empty response from Gemini model...",)

Expand Down Expand Up @@ -439,17 +429,10 @@ def prepare_files(
"""
Loads and formats input files for Gemini API.
"""
try:
file_path = folder_paths.get_annotated_filepath(file)
input_file_content = self.create_file_part(file_path)
files = [input_file_content] + GEMINI_INPUT_FILES
return (files,)
except Exception as e:
# Handle file processing errors gracefully
error_message = f"File processing error: {str(e)}"
print(f"[GeminiInputFiles] {error_message}")
# Return empty list on error
return ([],)
file_path = folder_paths.get_annotated_filepath(file)
input_file_content = self.create_file_part(file_path)
files = [input_file_content] + GEMINI_INPUT_FILES
return (files,)


NODE_CLASS_MAPPINGS = {
Expand Down
Loading