Skip to content

Commit 5ab5975

Browse files
authored
Add files via upload
1 parent f373f60 commit 5ab5975

12 files changed

+429
-267
lines changed

IFChatPromptNode.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,9 @@ async def process_chat(
777777
else:
778778
image_tensor, default_mask_tensor = process_images_for_comfy(
779779
retrieved_image,
780-
self.placeholder_image_path
780+
self.placeholder_image_path,
781+
response_key=None,
782+
field_name=None
781783
)
782784
mask_tensor = default_mask_tensor
783785

IFDisplayTextWildcardNode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self):
1919
self.wildcard_lock = threading.Lock()
2020

2121
# Initialize paths
22-
self.base_path = folder_paths.base_path
22+
#self.base_path = folder_paths.base_path
2323
self.presets_dir = os.path.join(folder_paths.base_path, "custom_nodes", "ComfyUI-IF_AI_tools", "IF_AI", "presets")
2424
self.wildcards_dir = os.path.join(self.presets_dir, "wildcards")
2525

IFImagePromptNode.py

Lines changed: 219 additions & 95 deletions
Large diffs are not rendered by default.

IFStepCounterNode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# IFStepCounterNode.py
12
class IFCounter:
23
def __init__(self):
34
self.counters = {}

IF_AI/presets/neg_prompts.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"None": "",
33
"AI_Fill": "lowres, lowquality, bad,",
4-
"SD3x_q1": "deformed and malformed with worst qualities. distortions and artifacts, low quality, bad ratings ☆☆☆☆☆, 0/10 review, 0/5 review ↓",
4+
"SD3x_q1": "deformed and malformed with worst qualities. distortions and artifacts, low quality, bad ratings, 0/10 review, 0/5 review ↓",
55
"AtomeaseNoWaifus": "(3D, Adorable, Anime, CGI, Cartoon, Cartoonish, Childish, Computer Generated, Manga, Rendered)",
66
"BadChill": "ng_deepnegative_v1_75t, bad-picture-chill-75v, bad_prompt, bad anatomy",
77
"BadChill2": "bad-picture-chill-75v, ng_deepnegative_v1_75t, easynegative, verybadimagenegative_v1.3, negative_hand-neg",

IF_AI/rag/settings.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ base_ip: localhost
44
port: '11434'
55
llm_provider: openai
66
llm_model: gpt-4o-mini
7-
temperature: 1.2000000000000002
8-
max_tokens: 2048
7+
temperature: 0.0
8+
max_tokens: 2061
99
stop: null
1010
keep_alive: false
1111
top_k: 40
1212
top_p: 0.9
1313
repeat_penalty: 1.2
14-
seed: 558413258089916
15-
rag_folder_name: safiro1
16-
query_type: local
14+
seed: 197464410746652
15+
rag_folder_name: Safiro2
16+
query_type: global
1717
community_level: 2
1818
preset: Default
1919
external_llm_api_key: ''

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
ComfyUI-IF_AI_tools is a set of custom nodes to Run Local and API LLMs and LMMs, Features OCR-RAG (Bialdy), nanoGraphRAG, Supervision Object Detection, supports Ollama, LlamaCPP LMstudio, Koboldcpp, TextGen, Transformers or via APIs Anthropic, Groq, OpenAI, Google Gemini, Mistral, xAI and create your own charcters assistants (SystemPrompts) with custom presets and muchmore
66

7+
################# ATENTION ####################
78

9+
*COPY THE IF_AI FOLDER TO YOUR USER FOLDER*
10+
11+
###############################################
812
# Prerequisite Installation (Poppler)
913

1014
To ensure compatibility and functionality with all tools, you may need `poppler` for PDF-related operations. Use `scoop` to install `poppler` on Windows:

__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
current_dir = os.path.dirname(os.path.abspath(__file__))
2626
if current_dir not in sys.path:
2727
sys.path.insert(0, current_dir)
28-
#print(f"Current directory: {current_dir}")
29-
#print(f"Files in current directory: {os.listdir(current_dir)}")
28+
3029
try:
3130
from .omost import omost_function
3231
print("Successfully imported omost_function from omost.py in the current directory")

openai_api.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,25 @@ async def generate_image(
208208

209209
async with aiohttp.ClientSession() as session:
210210
async with session.post(api_url, headers=headers, json=payload) as response:
211-
response.raise_for_status()
211+
if response.status != 200:
212+
error_text = await response.text()
213+
logger.error(f"OpenAI generate_image error {response.status}: {error_text}")
214+
response.raise_for_status()
212215
data = await response.json()
213-
images = [item["b64_json"] for item in data.get("data", [])]
214-
return images
216+
217+
# Handle different response structures
218+
if "data" in data and isinstance(data["data"], list):
219+
images = []
220+
for item in data["data"]:
221+
if "b64_json" in item:
222+
images.append(item["b64_json"])
223+
elif "url" in item:
224+
# If response_format was changed or API returned URLs
225+
images.append(item["url"])
226+
return images
227+
else:
228+
logger.error("Unexpected response format in generate_image")
229+
raise ValueError("Unexpected response format")
215230

216231
async def edit_image(
217232
image_base64: str,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-if_ai_tools"
33
description = "Run Local and API LLMs, Features OCR-RAG (Bialdy), nanoGraphRAG, Supervision Object Detection, Conditioning manipulation via Omost, supports Ollama, LlamaCPP LMstudio, Koboldcpp, TextGen, Transformers or via APIs Anthropic, Groq, OpenAI, Google Gemini, Mistral, xAI and create your own charcters assistants (SystemPrompts) with custom presets and muchmore"
4-
version = "1.0.7"
4+
version = "1.0.6"
55
license = { file = "LICENSE.txt" }
66
dependencies = ["anthropic",
77
"groq",

send_request.py

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from .vllm_api import send_vllm_request
2121
from .gemini_api import send_gemini_request
2222
from .transformers_api import TransformersModelManager # Import the manager
23-
from .utils import format_images_for_provider, convert_images_for_api, format_response
23+
from .utils import convert_images_for_api, format_response
2424
# Set up logging
2525
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
2626
logger = logging.getLogger(__name__)
@@ -101,8 +101,6 @@ async def send_request(
101101
Union[str, Dict[str, Any]]: Unified response format.
102102
"""
103103
try:
104-
#formatted_images = format_images_for_provider(images, llm_provider) if images is not None else None
105-
#formatted_mask = format_images_for_provider(mask, llm_provider) if mask is not None else None
106104
# Define aspect ratio to size mapping
107105
aspect_ratio_mapping = {
108106
"1:1": "1024x1024",
@@ -141,7 +139,7 @@ async def send_request(
141139
else:
142140
# For other providers, convert to base64 only if images exist
143141
formatted_images = convert_images_for_api(images, target_format='base64') if images is not None and len(images) > 0 else None
144-
formatted_mask = convert_images_for_api(mask, target_format='base64') if mask is not None and len(mask) > 0 else None
142+
#formatted_masks = convert_images_for_api(mask, target_format='base64') if mask is not None and len(mask) > 0 else None
145143

146144
api_functions = {
147145
"groq": send_groq_request,
@@ -233,39 +231,60 @@ async def send_request(
233231
}
234232
elif llm_provider == "openai":
235233
if llm_model.startswith("dall-e"):
236-
if strategy == "create":
237-
# Generate image
238-
generated_images = await generate_image(
239-
prompt=user_message,
240-
model=llm_model,
241-
n=batch_count,
242-
size=size,
243-
api_key=llm_api_key
244-
)
245-
return {"images": generated_images}
246-
elif strategy == "edit":
234+
try:
235+
# Handle image formatting for edit/variations
236+
formatted_image = None
237+
formatted_mask = None
238+
239+
if images is not None and (strategy == "edit" or strategy == "variations"):
240+
# Convert to base64 and take first image only
241+
formatted_images = convert_images_for_api(images[0:1], target_format='base64')
242+
if formatted_images:
243+
formatted_image = formatted_images[0]
247244

248-
# Edit image
249-
edited_images = await edit_image(
250-
image_base64=formatted_images[0],
251-
mask_base64=formatted_mask,
252-
prompt=user_message,
253-
model=llm_model,
254-
n=batch_count,
255-
size=size,
256-
api_key=llm_api_key
257-
)
258-
return {"images": edited_images}
259-
elif strategy == "variations":
260-
# Generate variations
261-
variations_images = await generate_image_variations(
262-
image_base64=formatted_images[0],
263-
model=llm_model,
264-
n=batch_count,
265-
size=size,
266-
api_key=llm_api_key
267-
)
268-
return {"images": variations_images}
245+
# Handle mask for edit strategy
246+
if strategy == "edit" and mask is not None:
247+
formatted_masks = convert_images_for_api(mask[0:1], target_format='base64')
248+
if formatted_masks:
249+
formatted_mask = formatted_masks[0]
250+
251+
# Make appropriate API call based on strategy
252+
if strategy == "create":
253+
response = await generate_image(
254+
prompt=user_message,
255+
model=llm_model,
256+
n=batch_count,
257+
size=size,
258+
api_key=llm_api_key
259+
)
260+
elif strategy == "edit":
261+
response = await edit_image(
262+
image_base64=formatted_image,
263+
mask_base64=formatted_mask,
264+
prompt=user_message,
265+
model=llm_model,
266+
n=batch_count,
267+
size=size,
268+
api_key=llm_api_key
269+
)
270+
elif strategy == "variations":
271+
response = await generate_image_variations(
272+
image_base64=formatted_image,
273+
model=llm_model,
274+
n=batch_count,
275+
size=size,
276+
api_key=llm_api_key
277+
)
278+
else:
279+
raise ValueError(f"Invalid strategy: {strategy}")
280+
281+
# Return the response directly - it will be a list of base64 strings
282+
return {"images": response}
283+
284+
except Exception as e:
285+
error_msg = f"Error in DALL·E {strategy}: {str(e)}"
286+
logger.error(error_msg)
287+
return {"error": error_msg}
269288
else:
270289
api_url = f"https://api.openai.com/v1/chat/completions"
271290
kwargs = {

0 commit comments

Comments
 (0)