Python Code Verification Skill#
- class council.skills.python.PythonCodeVerificationSkill(code_template: str = '')[source]#
Bases:
SkillBase
Skill that verifies a given python code. It verifies: - the code is parseable using ast.parse - the code follows an optional code template.
The python code is retrieved from the message content from context.try_last_message, looking for a markdown python code block.
Below is an example of code template:
def say_hi() -> str: # COUNCIL NO EDIT BEFORE THIS LINE pass # COUNCIL NO EDIT AFTER THIS LINE print(say_hi())
The two magic comments # COUNCIL … are used to identify the reference code, respectively above and below each magic comment.
The verification process will fail if any non-empty lines of the reference code are missing in the given code.
The verification process relies on ast.parse and ast.unparse to standardize the code. As such, the reference code must be formatted in such a way it is not impacted by the standardization process, a.k.a the reference code must be stable.
Below is a non-exhaustive list for good practices for the reference code:
no comments, other than the magic comments
empty lines are ok as they will be ignored
- __init__(code_template: str = '') None [source]#
initialize a new instance
- Parameters:
code_template – a code template use to validate the python code retrieved from the context.
- build_success_message(message: str, data: Any | None = None) ChatMessage #
Builds a success message for the skill with the provided message and optional data.
- Parameters:
message (str) – The success message.
data (Any, optional) – Additional data to include in the message. Defaults to None.
- Returns:
The success message.
- Return type:
- Raises:
None –
- execute(context: SkillContext) ChatMessage [source]#
Executes the skill on the provided chain context and budget.
- Parameters:
context (SkillContext) – The context for executing the skill.
- Returns:
The result of skill execution.
- Return type:
- Raises:
None –
- execute_skill(context: SkillContext) ChatMessage #
Skill execution
- property name#
Property getter for the skill name.
- Returns:
The name of the skill.
- Return type:
str
- Raises:
None –
- render_as_dict(include_children: bool = True) Dict[str, Any] #
returns the graph of operation as a dictionary
- render_as_json() str #
returns the graph of operation as a JSON string
- run_in_current_thread(context: ChainContext, iteration_context: Option[IterationContext]) None #
Run the skill in the current thread
- run_skill(context: ChainContext, executor: ThreadPoolExecutor) None #
Run the skill in a different thread, and await for completion