MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / execute_patterns

Function execute_patterns

scripts/python_ui/streamlit.py:800–913  ·  view source on GitHub ↗

Execute the selected patterns and capture their outputs.

(
    patterns_to_run: List[str],
    chain_mode: bool = False,
    initial_input: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

798
799
800def execute_patterns(
801 patterns_to_run: List[str],
802 chain_mode: bool = False,
803 initial_input: Optional[str] = None,
804) -> List[str]:
805 """Execute the selected patterns and capture their outputs."""
806 logger.info(f"Executing {len(patterns_to_run)} patterns")
807
808 st.session_state.chat_output = []
809 all_outputs = []
810 current_input = initial_input or st.session_state.input_content
811 timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
812
813 # Validate configuration
814 current_provider = st.session_state.config.get("vendor")
815 current_model = st.session_state.config.get("model")
816
817 if not current_provider or not current_model:
818 error_msg = "Please select a provider and model first."
819 logger.error(error_msg)
820 st.error(error_msg)
821 return all_outputs
822
823 # Validate input content
824 is_valid, error_message = validate_input_content(current_input)
825 if not is_valid:
826 logger.error(f"Input validation failed: {error_message}")
827 st.error(f"Input validation failed: {error_message}")
828 return all_outputs
829
830 # Sanitize input content
831 try:
832 sanitized_input = sanitize_input_content(current_input)
833 if sanitized_input != current_input:
834 logger.info("Input content was sanitized")
835 st.warning(
836 "Input content was automatically sanitized for better compatibility."
837 )
838
839 current_input = sanitized_input
840 except Exception as e:
841 logger.error(f"Error sanitizing input: {str(e)}")
842 st.error(f"Error processing input: {str(e)}")
843 return all_outputs
844
845 execution_info = f"**Using Model:** {current_provider} - {current_model}"
846 all_outputs.append(execution_info)
847 logger.info(f"Using model: {current_model} from provider: {current_provider}")
848
849 try:
850 for pattern in patterns_to_run:
851 logger.info(f"Running pattern: {pattern}")
852 try:
853 cmd = ["fabric", "--pattern", pattern]
854 logger.debug(f"Executing command: {' '.join(cmd)}")
855
856 message = (
857 current_input if chain_mode else st.session_state.input_content

Callers 1

mainFunction · 0.85

Calls 4

validate_input_contentFunction · 0.85
sanitize_input_contentFunction · 0.85
runFunction · 0.85
save_output_logFunction · 0.85

Tested by

no test coverage detected