Spaces:
Paused
Paused
| # | |
| # SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org> | |
| # SPDX-License-Identifier: Apache-2.0 | |
| # | |
| from config import restrictions # Load predefined restriction settings for instruction building | |
| # Define a function to set system instructions | |
| def set_instructions(mode: str, date: str) -> str: | |
| """ | |
| This function constructs a comprehensive system instruction string that integrates several key components needed | |
| to guide the behavior of an AI model or system during interaction. It takes two inputs: 'mode' and 'date', and | |
| returns a single formatted string that combines these inputs with a predefined set of restrictions loaded from | |
| the configuration. | |
| The purpose of this instruction string is to provide contextual and operational directives to the AI system. | |
| The 'mode' parameter typically represents the current operational mode or state, which may influence how the AI | |
| processes inputs or generates outputs. This could include modes such as normal operation, restricted mode, or | |
| specialized behavior modes. | |
| The 'restrictions' component, imported from the configuration, contains predefined rules, limitations, or guidelines | |
| that the AI should adhere to during its operation. These restrictions might include content filters, ethical | |
| guidelines, or other constraints necessary to ensure safe and appropriate AI behavior. | |
| The 'date' parameter represents the current date or timestamp, providing temporal context that may be relevant | |
| for time-sensitive instructions or for logging and auditing purposes. | |
| The function formats these three components into a single string with clear separation using multiple newline | |
| characters. This spacing improves readability and ensures that each section is distinctly identifiable when the | |
| instruction string is parsed or displayed. The resulting string looks like this: | |
| <mode> | |
| <restrictions> | |
| Today: <date> | |
| This structured format allows downstream systems or models to easily extract and interpret each part of the | |
| instruction, facilitating consistent and context-aware AI responses. | |
| Parameters: | |
| - mode (str): A string indicating the current operational mode or context for the AI system. | |
| - date (str): A string representing the current date or timestamp to provide temporal context. | |
| Returns: | |
| - str: A formatted instruction string combining the mode, restrictions, and date sections with spacing. | |
| Usage: | |
| This function is typically called before sending prompts or requests to the AI model to ensure that all necessary | |
| contextual information and operational constraints are included in the system instructions. | |
| """ | |
| # Combine mode, restrictions, and date into a formatted instruction block | |
| return f"{mode}\n\n\n{restrictions}\n\n\nToday: {date}\n\n\n" | |
| # Return the composed string with spacing between sections |