Last active
April 25, 2024 18:00
-
-
Save ohdearquant/419ae597f5568c2ad35473d7d2f9e8ac to your computer and use it in GitHub Desktop.
a coder basing on lionagi and rUv https://gist.github.com/ruvnet/4b41ee8eaabd6e72cf18b6352437c738
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # step 1: design a form template for the coder to work with | |
| from typing import Any | |
| import lionagi as li | |
| class CoderForm(li.Form): | |
| """ | |
| A form template for developing software project | |
| """ | |
| context: str | None= li.Field( | |
| None, | |
| title="Context", | |
| description="TThe context for the current issue to achieve", | |
| ) | |
| code: str | None = li.Field( | |
| None, | |
| title="Code", | |
| description="codes generated by workflow", | |
| ) | |
| plan: str | None = li.Field( | |
| None, | |
| title="Plan", | |
| description=" breaking down the issue to multi-step plan", | |
| ) | |
| human_comments: str | None = li.Field( | |
| None, | |
| title="Human Comments", | |
| description="Human comments work step", | |
| ) | |
| reasoning: str | None = li.Field( | |
| default=None, | |
| title="Reasoning", | |
| description="The reasoning behind building the feature this way", | |
| ) | |
| final_codes: str | None = li.Field( | |
| None, | |
| title="Final Codes", | |
| description="Final deliverable codes to users", | |
| ) | |
| # step 2: define your coder class | |
| from lionagi.lions.coderfrom .util import ( | |
| extract_code_blocks, | |
| install_missing_dependencies, | |
| set_up_interpreter | |
| ) | |
| class Coder(li.Worker): | |
| """ | |
| Guidance from super intelligent code bot: | |
| {guidance_response} | |
| Please generate Python functions that satisfies the prompt and follows the provided guidance, while adhering to these coding standards: | |
| - Use descriptive and meaningful names for variables, functions, and classes. | |
| - Follow the naming conventions: lowercase with underscores for functions and variables, CamelCase for classes. | |
| - Keep functions small and focused, doing one thing well. | |
| - Use 4 spaces for indentation, and avoid mixing spaces and tabs. | |
| - Limit line length to 79 characters for better readability. | |
| - Use docstrings to document functions, classes, and modules, describing their purpose, parameters, and return values. | |
| - Use comments sparingly, and prefer descriptive names and clear code structure over comments. | |
| - Handle exceptions appropriately and raise exceptions with clear error messages. | |
| - Use blank lines to separate logical sections of code, but avoid excessive blank lines. | |
| - Import modules in a specific order: standard library, third-party, and local imports, separated by blank lines. | |
| - Use consistent quotes (single or double) for strings throughout the codebase. | |
| - Follow the PEP 8 style guide for more detailed coding standards and best practices. | |
| """ | |
| default_form = CoderForm | |
| @li.work("gh_issue -> plan", capacity=5, refresh_time=0.5) | |
| async def plan_code(self, context: str, branch_id=None, **kwargs) -> dict | str: | |
| """ | |
| Please design coding instructions for the following prompt and | |
| provide guidance for the coder to follow. | |
| """ | |
| branch = self.session.branches.get(branch_id, None) or li.Branch() | |
| plan_, branch_ = await li.direct.plan( | |
| context, branch=branch, return_branch=True, **kwargs | |
| ) | |
| if branch_.id_ not in self.session.branches: | |
| self.session.branches[branch_.id_] = branch_ | |
| return plan_.plan, branch_.id_ | |
| @li.work("plan -> code", capacity=3, refresh_time=2) | |
| async def write_code(self, plan, branch_id=None, **kwargs): | |
| """ | |
| Please write a Python function that satisfies the prompt and | |
| follows the provided guidance. | |
| """ | |
| branch = self.session.get_branch(branch_id, None) or li.Branch() | |
| if len(branch.messages) > 1: | |
| response = await branch.chat(**kwargs) | |
| return extract_code_blocks(response) | |
| else: | |
| response = await branch.chat(context=plan, **kwargs) | |
| return extract_code_blocks(response) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment