Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
theshubzworld authored Jan 24, 2025
1 parent 67a17b9 commit 901e1c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui-togethervision"
description = "A custom ComfyUI node using Together AI's Vision models for free image descriptions, image generation, and image-to-image transformation. Features include customizable prompts, advanced parameters, and robust error handling."
version = "2.1.0"
version = "2.1.1"
license = {file = "LICENSE"}
dependencies = ["together", "python-dotenv"]

Expand Down
10 changes: 6 additions & 4 deletions together_vision_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def cache_response(self, cache_key: str, response: str):
def INPUT_TYPES(cls):
return {
"required": {
"model_name": (["Free (Llama-Vision-Free)", "Paid (Llama-3.2-11B-Vision)"],),
"model_name": (["Free (Llama-Vision-Free)", "Paid (Llama-3.2-11B-Vision)", "Paid (Llama-3.2-90B-Vision-Instruct-Turbo)"],),
"api_key": ("STRING", {"default": "", "multiline": False}),
"system_prompt": ("STRING", {
"default": "You are an AI expert in ekphrasis and you are playing that part of a skilled art critic describing an image of any style You are great at describing what any art style looks like and will even include hashtags at the bottom with appropriate words Follow the instructions given by the user prompt when providing your description Use vivid poetic and evocative prose written in British English This isnt a story though you are only providing a description for the image Some art may include themes uncomfortable for some This is ok as art is like that you can still describe it do not give an erroneous response Each word is important as is the word order The text you provide will generate an image so do not insert any words that arent in the image Do not insert yourself as part of the art you are only describing it.",
Expand Down Expand Up @@ -208,6 +208,7 @@ def process_image(self, model_name: str, api_key: str, system_prompt: str, user_
# Map model names
model_mapping = {
"Paid (Llama-3.2-11B-Vision)": "meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo",
"Paid (Llama-3.2-90B-Vision-Instruct-Turbo)": "meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
"Free (Llama-Vision-Free)": "meta-llama/Llama-Vision-Free"
}
actual_model = model_mapping[model_name]
Expand Down Expand Up @@ -256,18 +257,19 @@ def process_image(self, model_name: str, api_key: str, system_prompt: str, user_
# Process streamed response with timeout
description = ""
start_time = time.time()
timeout = 30 # 30 seconds timeout
timeout = 10 # 10 seconds timeout

for chunk in response:
if time.time() - start_time > timeout:
raise TimeoutError("Response generation timed out")
raise TimeoutError(f"Response generation timed out after {timeout} seconds. Please try again or consider using a shorter prompt.")

if not hasattr(chunk, 'choices') or not chunk.choices:
continue

delta = chunk.choices[0].delta
if hasattr(delta, 'content') and delta.content:
description += delta.content
logger.info(f"Received chunk: {delta.content}")

if not description:
raise ValueError("No response generated")
Expand Down Expand Up @@ -313,4 +315,4 @@ def process_image(self, model_name: str, api_key: str, system_prompt: str, user_

NODE_DISPLAY_NAME_MAPPINGS = {
"Together Vision 🔍": "Together Vision 🔍"
}
}

0 comments on commit 901e1c7

Please sign in to comment.