Compare commits

..

No commits in common. "main" and "0.3.3" have entirely different histories.
main ... 0.3.3

4 changed files with 20 additions and 71 deletions

View File

@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "0.3.4"
current_version = "0.3.3"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
replace = "{new_version}"

View File

@ -4,7 +4,7 @@ FROM python:3.11-slim
# Set the working directory in the container
WORKDIR /app
# Set version label
ARG VERSION="0.3.4"
ARG VERSION="0.3.3"
LABEL version=$VERSION
# Copy project files into the container

View File

@ -158,10 +158,7 @@ def load_prompt_models_from_config():
def create_prompt_with_random_model(base_prompt: str, topic: str = "random"):
"""Create a prompt using a randomly selected model from OpenWebUI or OpenRouter.
If OpenWebUI fails, it will retry once. If it fails again, it will fallback to OpenRouter.
"""
"""Create a prompt using a randomly selected model from OpenWebUI or OpenRouter."""
prompt_models = load_prompt_models_from_config()
if not prompt_models:
@ -171,59 +168,16 @@ def create_prompt_with_random_model(base_prompt: str, topic: str = "random"):
# Randomly select a model
service, model = random.choice(prompt_models)
# Import here to avoid circular imports
from libs.openwebui import create_prompt_on_openwebui
from libs.openrouter import create_prompt_on_openrouter
if service == "openwebui":
try:
# First attempt with OpenWebUI
logging.info(f"Attempting to generate prompt with OpenWebUI using model: {model}")
result = create_prompt_on_openwebui(base_prompt, topic, model)
if result:
return result
# If first attempt returns None, try again
logging.warning("First OpenWebUI attempt failed. Retrying...")
result = create_prompt_on_openwebui(base_prompt, topic, model)
if result:
return result
# If second attempt fails, fallback to OpenRouter
logging.warning("Second OpenWebUI attempt failed. Falling back to OpenRouter...")
openrouter_models = [m for m in prompt_models if m[0] == "openrouter"]
if openrouter_models:
_, openrouter_model = random.choice(openrouter_models)
return create_prompt_on_openrouter(base_prompt, topic, openrouter_model)
else:
logging.error("No OpenRouter models configured for fallback.")
return "A colorful abstract composition" # Default fallback prompt
except Exception as e:
logging.error(f"Error with OpenWebUI: {e}")
# Fallback to OpenRouter on exception
logging.warning("OpenWebUI exception. Falling back to OpenRouter...")
openrouter_models = [m for m in prompt_models if m[0] == "openrouter"]
if openrouter_models:
_, openrouter_model = random.choice(openrouter_models)
try:
return create_prompt_on_openrouter(base_prompt, topic, openrouter_model)
except Exception as e2:
logging.error(f"Error with OpenRouter fallback: {e2}")
return "A colorful abstract composition" # Default fallback prompt
else:
logging.error("No OpenRouter models configured for fallback.")
return "A colorful abstract composition" # Default fallback prompt
# Import here to avoid circular imports
from libs.openwebui import create_prompt_on_openwebui
return create_prompt_on_openwebui(base_prompt, topic)
elif service == "openrouter":
try:
# Use OpenRouter
return create_prompt_on_openrouter(base_prompt, topic, model)
except Exception as e:
logging.error(f"Error with OpenRouter: {e}")
return "A colorful abstract composition" # Default fallback prompt
# Import here to avoid circular imports
from libs.openrouter import create_prompt_on_openrouter
return create_prompt_on_openrouter(base_prompt, topic)
return "A colorful abstract composition" # Default fallback prompt
return None
user_config = load_config()
output_folder = user_config["comfyui"]["output_dir"]

View File

@ -73,22 +73,17 @@ def create_prompt_on_openwebui(prompt: str, topic: str = "random", model: str =
]
# Send the chat request
try:
result = client.chat(
question=user_content,
chat_title=datetime.now().strftime("%Y-%m-%d %H:%M"),
folder_name="ai-frame-image-server"
)
result = client.chat(
question=user_content,
chat_title=datetime.now().strftime("%Y-%m-%d %H:%M"),
folder_name="ai-frame-image-server"
)
if result:
prompt = result["response"].strip('"')
else:
# Return None if the request fails
logging.warning(f"OpenWebUI request failed with model: {model}")
return None
except Exception as e:
logging.error(f"Error in OpenWebUI request with model {model}: {e}")
return None
if result:
prompt = result["response"].strip('"')
else:
# Fallback if the request fails
prompt = "A vibrant landscape"
match = re.search(r'"([^"]+)"', prompt)
if not match: