Skip to content

Commit ee76227

Browse files
authored
Update utils.py
some fixes from if-ai#135
1 parent 267379d commit ee76227

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

utils.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,4 +909,83 @@ def format_response(self, response):
909909

910910
formatted_paragraphs.append(para.strip())
911911

912-
return "\n\n".join(formatted_paragraphs)
912+
return "\n\n".join(formatted_paragraphs)
913+
914+
915+
def save_combo_settings(settings, directory):
916+
"""
917+
Save combo settings to a JSON file in the specified directory.
918+
919+
Args:
920+
settings (dict): The settings to save.
921+
directory (str): The directory where the settings file will be saved.
922+
923+
Returns:
924+
str: The path to the saved settings file.
925+
"""
926+
try:
927+
if not os.path.exists(directory):
928+
os.makedirs(directory)
929+
930+
settings_file_path = os.path.join(directory, 'combo_settings.json')
931+
with open(settings_file_path, 'w') as f:
932+
json.dump(settings, f, indent=4) # Save with pretty formatting
933+
934+
logger.info(f"Settings saved to {settings_file_path}")
935+
return settings_file_path
936+
except Exception as e:
937+
logger.error(f"Error saving combo settings: {str(e)}")
938+
return None
939+
940+
def load_combo_settings(directory):
941+
"""
942+
Load combo settings from a JSON file in the specified directory.
943+
944+
Args:
945+
directory (str): The directory where the settings file is located.
946+
947+
Returns:
948+
dict: The loaded settings or an empty dict if the file does not exist.
949+
"""
950+
settings_file_path = os.path.join(directory, 'combo_settings.json')
951+
if not os.path.exists(settings_file_path):
952+
logger.warning(f"No settings file found at {settings_file_path}")
953+
return {} # Return an empty dict if the file does not exist
954+
955+
try:
956+
with open(settings_file_path, 'r') as f:
957+
settings = json.load(f)
958+
logger.info(f"Settings loaded from {settings_file_path}")
959+
return settings
960+
except Exception as e:
961+
logger.error(f"Error loading combo settings: {str(e)}")
962+
return {}
963+
964+
def create_settings_from_ui_IFImagePromptNode(data):
965+
"""
966+
Create settings from the UI input data.
967+
968+
Args:
969+
data (dict): The input data from the UI.
970+
971+
Returns:
972+
dict: The created settings.
973+
"""
974+
settings = {
975+
"llm_provider": data.get("llm_provider", ""),
976+
"llm_model": data.get("llm_model", ""),
977+
"base_ip": data.get("base_ip", "localhost"),
978+
"port": data.get("port", "11434"),
979+
"user_prompt": data.get("user_prompt", ""),
980+
"strategy": data.get("strategy", "normal"),
981+
"max_tokens": data.get("max_tokens", 2048),
982+
"temperature": data.get("temperature", 0.7),
983+
"top_k": data.get("top_k", 40),
984+
"top_p": data.get("top_p", 0.9),
985+
"repeat_penalty": data.get("repeat_penalty", 1.1),
986+
"seed": data.get("seed", 0),
987+
"aspect_ratio": data.get("aspect_ratio", "1:1"),
988+
# Add other settings as needed
989+
}
990+
logger.info("Settings created from UI input")
991+
return settings

0 commit comments

Comments
 (0)