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