-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major refactor for readability and maintainability (#36)
* Major refactor for readability and maintainability Moved from confusing toolset/codeset/subkernels structure to more encapsulated form. Better seperation from LLM actions and rest of context. Much improved inheritence structure with clear defaults and boundaries. Seeds for auto-discovery and plugin architecture added. beaker_kernel is now a full python library. Improvements and fixes for existing code flows. Improved dev_ui experience when changing context. * Import flake and sort * Cleanup debug logging * Make git pull success optional * Cleanup subkernel files
- Loading branch information
1 parent
6944f94
commit d8a4e06
Showing
68 changed files
with
759 additions
and
503 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import json | ||
import logging | ||
import re | ||
|
||
from archytas.react import Undefined | ||
from archytas.tool_utils import AgentRef, LoopControllerRef, tool, toolset | ||
|
||
from beaker_kernel.lib.agent import BaseAgent | ||
from beaker_kernel.lib.context import BaseContext | ||
from beaker_kernel.lib.jupyter_kernel_proxy import JupyterMessage | ||
from beaker_kernel.lib.toolset import BaseToolset | ||
|
||
logging.disable(logging.WARNING) # Disable warnings | ||
logger = logging.Logger(__name__) | ||
|
||
@toolset() | ||
class DatasetToolset: | ||
|
||
@tool() | ||
async def generate_code( | ||
self, query: str, agent: AgentRef, loop: LoopControllerRef | ||
) -> None: | ||
""" | ||
Generated code to be run in an interactive Jupyter notebook for the purpose of exploring, modifying and visualizing a Dataframe. | ||
Input is a full grammatically correct question about or request for an action to be performed on the loaded dataframe. | ||
Args: | ||
query (str): A fully grammatically correct question about the current dataset. | ||
""" | ||
# set up the agent | ||
# str: Valid and correct python code that fulfills the user's request. | ||
var_sections = [] | ||
for var_name, dataset_obj in agent.context.dataset_map.items(): | ||
df_info = await agent.context.describe_dataset(var_name) | ||
var_sections.append(f""" | ||
You have access to a variable name `{var_name}` that is a {agent.context.metadata.get("df_lib_name", "Pandas")} Dataframe with the following structure: | ||
{df_info} | ||
--- End description of variable `{var_name}` | ||
""") | ||
prompt = f""" | ||
You are a programmer writing code to help with scientific data analysis and manipulation in {agent.context.metadata.get("name", "a Jupyter notebook")}. | ||
Please write code that satisfies the user's request below. | ||
{"".join(var_sections)} | ||
If you are asked to modify or update the dataframe, modify the dataframe in place, keeping the updated variable the same unless specifically specified otherwise. | ||
You also have access to the libraries {agent.context.metadata.get("libraries", "that are common for these tasks")}. | ||
Please generate the code as if you were programming inside a Jupyter Notebook and the code is to be executed inside a cell. | ||
You MUST wrap the code with a line containing three backticks (```) before and after the generated code. | ||
No addtional text is needed in the response, just the code block. | ||
""" | ||
|
||
llm_response = await agent.oneshot(prompt=prompt, query=query) | ||
loop.set_state(loop.STOP_SUCCESS) | ||
preamble, code, coda = re.split("```\w*", llm_response) | ||
result = json.dumps( | ||
{ | ||
"action": "code_cell", | ||
"language": agent.context.lang, | ||
"content": code.strip(), | ||
} | ||
) | ||
return result | ||
|
||
|
||
class DatasetAgent(BaseAgent): | ||
|
||
def __init__(self, context: BaseContext = None, tools: list = None, **kwargs): | ||
tools = [DatasetToolset] | ||
super().__init__(context, tools, **kwargs) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion
1
...s/codesets/dataset/python3/df_download.py → ...texts/dataset/code/python3/df_download.py
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import json | ||
import logging | ||
import re | ||
|
||
from archytas.tool_utils import AgentRef, LoopControllerRef, tool, toolset | ||
|
||
from beaker_kernel.lib.agent import BaseAgent | ||
from beaker_kernel.lib.context import BaseContext | ||
|
||
logging.disable(logging.WARNING) # Disable warnings | ||
logger = logging.Logger(__name__) | ||
|
||
|
||
@toolset() | ||
class DecapodesToolset: | ||
""" | ||
Toolset used for working with the Julia package Decacpodes, a framework for doing descrete exterior calculus based modeling. | ||
""" | ||
|
||
@tool() | ||
async def generate_code( | ||
self, query: str, agent: AgentRef, loop: LoopControllerRef | ||
) -> None: | ||
""" | ||
Generated Julia code to be run in an interactive Jupyter notebook for the purpose of exploring and modifying systems the DecaExpr. | ||
Input is a full grammatically correct question about or request for an action to be performed on the loaded model. | ||
Assume that the expression is already loaded and has the variable named `_expr`. | ||
Information about the dataframe can be loaded with the `model_structure` tool. | ||
Args: | ||
query (str): A fully grammatically correct queistion about the current model. | ||
""" | ||
prompt = f""" | ||
You are a programmer writing code to help with scientific data analysis and manipulation in Julia. | ||
Please write code that satisfies the user's request below. | ||
You have access to a variable name `_expr` that is a Decapodes SyntacticModel model with the following structure: | ||
{await agent.context.model_structure()} | ||
Your generated will be in the form `_expr = parse_decapode(quote ...modified object.. end)` | ||
Please generate the code as if you were programming inside a Jupyter Notebook and the code is to be executed inside a cell. | ||
You MUST wrap the code with a line containing three backticks (```) before and after the generated code. | ||
No addtional text is needed in the response, just the code block. | ||
""" | ||
|
||
llm_response = await agent.oneshot(prompt=prompt, query=query) | ||
loop.set_state(loop.STOP_SUCCESS) | ||
preamble, code, coda = re.split("```\w*", llm_response) | ||
result = json.dumps( | ||
{ | ||
"action": "code_cell", | ||
"language": "julia-1.9", | ||
"content": code.strip(), | ||
} | ||
) | ||
return result | ||
|
||
|
||
class DecapodesAgent(BaseAgent): | ||
|
||
def __init__(self, context: BaseContext = None, tools: list = None, **kwargs): | ||
tools = [DecapodesToolset] | ||
super().__init__(context, tools, **kwargs) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.