From 5d7335db2bef92a25becb7ecac5d891012201bd1 Mon Sep 17 00:00:00 2001 From: aimfordeb <133010426+aimfordeb@users.noreply.github.com> Date: Fri, 23 Jan 2026 22:28:43 +0200 Subject: [PATCH] Will this work? --- funpack.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/funpack.py b/funpack.py index bdc96a15..ca727366 100644 --- a/funpack.py +++ b/funpack.py @@ -616,8 +616,8 @@ class FunPackStoryWriter: } } - RETURN_TYPES = ("STRING","STRING","STRING","STRING","STRING",) - RETURN_NAMES = ("prompt1","prompt2","prompt3","prompt4","prompt5",) + RETURN_TYPES = ("STRING","STRING","STRING","STRING","STRING","STRING") + RETURN_NAMES = ("prompt1","prompt2","prompt3","prompt4","prompt5","recommended_loras") FUNCTION = "write_story" CATEGORY = "FunPack" @@ -765,7 +765,33 @@ class FunPackStoryWriter: # Append generated sequence — this is what chains everything messages.append({"role": "assistant", "content": seq_text}) - return tuple(outputs) + lora_list = folder_paths.get_filename_list('loras') + lora_messages = [ + {"role": "system", "content": "Analyze the given array of sequences and the list of LoRAs and decide which LoRAs out of user's list are recommended to use for each sequence, based on the content of those sequences and the names of LoRAs. Output only list of recommended LoRAs in the format:\nSequence 1: lora name, lora name\nSequence 2: lora name, lora name\nSequence N: lora name, lora name"}, + {"role": "user", "content": lora_list,outputs[]} + ] + + # Generate hidden story + llm_tokens = llm_tokenizer.apply_chat_template( + lora_messages, add_generation_prompt=True, return_tensors="pt", tokenize=True + ).to(llm_model_device) + + print("[FunPackStoryWriter] Generating LoRA recommendations...") + with torch.no_grad(): + generated_ids = llm_model.generate( + input_ids=llm_tokens, + do_sample=True, + top_p=top_p, top_k=top_k, temperature=temperature, + max_new_tokens=max_new_tokens, + repetition_penalty=repetition_penalty, + pad_token_id=llm_tokenizer.pad_token_id, + eos_token_id=llm_tokenizer.eos_token_id, + ) + + recommended_loras = llm_tokenizer.decode(generated_ids[0][llm_tokens.shape[1]:], skip_special_tokens=True).strip() + print(f"[FunPackStoryWriter] LLM recommended to use this list of LoRAs: {recommended_loras}") + + return tuple(outputs),recommended_loras except Exception as e: print(f"[FunPackStoryWriter] Error during prompt enhancement: {e}") @@ -1406,5 +1432,6 @@ NODE_DISPLAY_NAME_MAPPINGS = { +