mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-11-12 21:09:41 +00:00
Merge branch 'secondtopic'
This commit is contained in:
commit
854732b1c2
@ -187,6 +187,45 @@ def load_prompt_models_from_config():
|
||||
return prompt_models
|
||||
|
||||
|
||||
def build_user_content(topic: str = "random") -> str:
|
||||
"""Build the user content string for prompt generation, including topic instructions and recent prompts avoidance."""
|
||||
config = load_config()
|
||||
topic_instruction = ""
|
||||
selected_topic = ""
|
||||
secondary_topic_instruction = ""
|
||||
# Unique list of recent prompts
|
||||
recent_prompts = list(set(load_recent_prompts()))
|
||||
|
||||
if topic == "random":
|
||||
topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
|
||||
selected_topic = random.choice(topics) if topics else ""
|
||||
elif topic != "":
|
||||
selected_topic = topic
|
||||
else:
|
||||
# Decide on whether to include a topic (e.g., 30% chance to include)
|
||||
topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
|
||||
if random.random() < 0.3 and topics:
|
||||
selected_topic = random.choice(topics)
|
||||
|
||||
if selected_topic != "":
|
||||
topic_instruction = f" Incorporate the theme of '{selected_topic}' into the new prompt."
|
||||
|
||||
# Add secondary topic if configured and not empty
|
||||
secondary_topic = config["comfyui"].get("secondary_topic", "").strip()
|
||||
if secondary_topic:
|
||||
secondary_topic_instruction = f" Additionally incorporate the theme of '{secondary_topic}' into the new prompt."
|
||||
|
||||
user_content = (
|
||||
"Can you generate me a really random image idea, Do not exceed 20 words. Use clear language, not poetic metaphors."
|
||||
+ topic_instruction
|
||||
+ secondary_topic_instruction
|
||||
+ "Avoid prompts similar to the following:"
|
||||
+ "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts))
|
||||
)
|
||||
|
||||
return user_content
|
||||
|
||||
|
||||
def create_prompt_with_random_model(base_prompt: str, topic: str = "random"):
|
||||
"""Create a prompt using a randomly selected model from OpenWebUI or OpenRouter.
|
||||
|
||||
|
||||
@ -40,36 +40,7 @@ def create_prompt_on_openrouter(prompt: str, topic: str = "random", model: str =
|
||||
logging.warning("OpenRouter is not enabled in the configuration.")
|
||||
return ""
|
||||
|
||||
topic_instruction = ""
|
||||
selected_topic = ""
|
||||
secondary_topic_instruction = ""
|
||||
# Unique list of recent prompts
|
||||
recent_prompts = list(set(load_recent_prompts()))
|
||||
if topic == "random":
|
||||
topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
|
||||
selected_topic = random.choice(topics) if topics else ""
|
||||
elif topic != "":
|
||||
selected_topic = topic
|
||||
else:
|
||||
# Decide on whether to include a topic (e.g., 30% chance to include)
|
||||
topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
|
||||
if random.random() < 0.3 and topics:
|
||||
selected_topic = random.choice(topics)
|
||||
if selected_topic != "":
|
||||
topic_instruction = f" Incorporate the theme of '{selected_topic}' into the new prompt."
|
||||
|
||||
# Add secondary topic if configured and not empty
|
||||
secondary_topic = config["comfyui"].get("secondary_topic", "").strip()
|
||||
if secondary_topic:
|
||||
secondary_topic_instruction = f" Additionally incorporate the theme of '{secondary_topic}' into the new prompt, in the style of."
|
||||
|
||||
user_content = (
|
||||
"Can you generate me a really random image idea, Do not exceed 20 words. Use clear language, not poetic metaphors."
|
||||
+ topic_instruction
|
||||
+ secondary_topic_instruction
|
||||
+ "Avoid prompts similar to the following:"
|
||||
+ "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts))
|
||||
)
|
||||
user_content = build_user_content(topic)
|
||||
|
||||
# Load configured models
|
||||
configured_models = [m.strip() for m in user_config["openrouter"]["models"].split(",") if m.strip()]
|
||||
|
||||
@ -19,36 +19,7 @@ def create_prompt_on_openwebui(prompt: str, topic: str = "random", model: str =
|
||||
"""Sends prompt to OpenWebui and returns the generated response."""
|
||||
# Reload config to get latest values
|
||||
config = load_config()
|
||||
topic_instruction = ""
|
||||
selected_topic = ""
|
||||
secondary_topic_instruction = ""
|
||||
# Unique list of recent prompts
|
||||
recent_prompts = list(set(load_recent_prompts()))
|
||||
if topic == "random":
|
||||
topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
|
||||
selected_topic = random.choice(topics)
|
||||
elif topic != "":
|
||||
selected_topic = topic
|
||||
else:
|
||||
# Decide on whether to include a topic (e.g., 30% chance to include)
|
||||
topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
|
||||
if random.random() < 0.3 and topics:
|
||||
selected_topic = random.choice(topics)
|
||||
if selected_topic != "":
|
||||
topic_instruction = f" Incorporate the theme of '{selected_topic}' into the new prompt."
|
||||
|
||||
# Add secondary topic if configured and not empty
|
||||
secondary_topic = config["comfyui"].get("secondary_topic", "").strip()
|
||||
if secondary_topic:
|
||||
secondary_topic_instruction = f" Additionally incorporate the theme of '{secondary_topic}' into the new prompt, in the style of."
|
||||
|
||||
user_content = (
|
||||
"Can you generate me a really random image idea, Do not exceed 20 words. Use clear language, not poetic metaphors."
|
||||
+ topic_instruction
|
||||
+ secondary_topic_instruction
|
||||
+ "Avoid prompts similar to the following:"
|
||||
+ "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts))
|
||||
)
|
||||
user_content = build_user_content(topic)
|
||||
|
||||
if model:
|
||||
# Use the specified model
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user