-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python interpreter #617
Python interpreter #617
Conversation
@@ -10,6 +10,7 @@ import { LinkCard } from '@astrojs/starlight/components'; | |||
<LinkCard title="fs_read_file" description="Reads a file as text from the file system." href="/genaiscript/reference/scripts/system#systemfs_read_file" /> | |||
<LinkCard title="fs_read_summary" description="Reads a summary of a file from the file system." href="/genaiscript/reference/scripts/system#systemfs_read_summary" /> | |||
<LinkCard title="math_eval" description="Evaluates a math expression" href="/genaiscript/reference/scripts/system#systemmath" /> | |||
<LinkCard title="python_interpreter" description="Executes python 3.12 code in a docker container. The process output is returned. Use 'print' to output data." href="/genaiscript/reference/scripts/system#systempython_interpreter" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link provided for the 'python_interpreter' tool should be consistent with other links, using 'system' as the prefix in the href attribute.
generated by pr-docs-review-commit
link_format
type: "string", | ||
description: `list of pip packages to install using pip. should be using the pip install format: | ||
<package1> | ||
<package2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code block for the 'requirements' description should be formatted as a code snippet for clarity.
generated by pr-docs-review-commit
code_format
console.log(`installing: ` + requirements) | ||
await container.writeText( | ||
"requirements.txt", | ||
requirements.replace(/[ ,]\s*/g, "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regular expression pattern used in the 'requirements.txt' replacement should escape the period to match a literal period, not any character.
generated by pr-docs-review-commit
regex_pattern
await container.writeText("main.py", main) | ||
const res = await container.exec("python", ["main.py"]) | ||
return res | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'defTool' function is defined as an async function but does not use 'await' with the 'host.container' call, which is likely an asynchronous operation.
generated by pr-docs-review-commit
async_function
} | ||
this.containers.splice(i, 1) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling in the stopContainer
method. There are empty catch blocks which could swallow errors and make debugging difficult.
generated by pr-review-commit
missing_error_handling
@@ -130,7 +124,7 @@ export async function runScript( | |||
const ffs = await host.findFiles(arg, { | |||
applyGitIgnore: excludeGitIgnore, | |||
}) | |||
if (!ffs.length) { | |||
if (!ffs?.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference exception. The ffs
variable is not checked for null before accessing its length
property.
generated by pr-review-commit
missing_null_check
: undefined | ||
trace.itemValue(`args`, callArgs ?? call.arguments) | ||
trace.fence(call.arguments, "json") | ||
if (callArgs === undefined) trace.error("arguments failed to parse") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling. If callArgs
is undefined
, an error is logged but execution continues which could lead to unexpected behavior.
generated by pr-review-commit
missing_error_handling
The pull request contains several changes:
However, there seems to be a potential issue:
Overall, these changes seem to be beneficial in improving the debugging experience and test coverage. The removal of the spinning progress indicator in favor of logs might make the output less visually appealing, but it should be more useful in an automated environment, such as CI/CD pipelines. The addition of verbose logging should also assist with debugging. Without further context, it's hard to say if the potential issue would cause any real problems. The changes seem well-implemented and should be positive overall. Thus, my response is: LGTM 🚀 Please consider reviewing the potential issue in
|
description: `list of pip packages to install using pip. should be using the pip install format: | ||
<package1> | ||
<package2> | ||
`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description for 'requirements' property in the 'python_interpreter' tool is incorrectly formatted. It should be a single line description without line breaks.
generated by pr-docs-review-commit
description_format
await container.writeText("main.py", main) | ||
const res = await container.exec("python", ["main.py"]) | ||
return res | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'defTool' function is defined as 'async' but does not use 'await' within its body, which is likely an error.
generated by pr-docs-review-commit
async_usage
title: "Python Dockerized code execution", | ||
}) | ||
|
||
const image = env.vars.pythonImage ?? "python:3.12" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of 'env.vars.pythonImage' is not explained or documented, which could lead to confusion about where this variable is set or how to use it.
generated by pr-docs-review-commit
env_usage
@@ -130,7 +124,7 @@ export async function runScript( | |||
const ffs = await host.findFiles(arg, { | |||
applyGitIgnore: excludeGitIgnore, | |||
}) | |||
if (!ffs.length) { | |||
if (!ffs?.length) { | |||
return fail( | |||
`no files matching ${arg}`, | |||
FILES_NOT_FOUND_ERROR_CODE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for the case when ffs
is undefined. It's recommended to handle this case to prevent potential runtime errors.
generated by pr-review-commit
missing_error_handling
await writeFile(hostFilename, content, { encoding: "utf8" }) | ||
await writeFile(hostFilename, content ?? "", { | ||
encoding: "utf8", | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference error. The content
parameter is not checked for null or undefined before being used in writeFile
.
generated by pr-review-commit
missing_null_check
BuiltinTools.mdx
andsystem.mdx
to add documentation for a new featurepython_interpreter
. This tool allows execution of Python 3.12 code in a docker container. 🐍cli/src/docker.ts
andcli/src/run.ts
for improved management of Docker containers. The changes include functions to stop Docker containers, better error handling, and verbose logging. 🐳core/src/chat.ts
.python_interpreter
incore/src/genaisrc/system.python_interpreter.genai.js
that allows executing Python code in a Docker container.CSVToMarkdown
function incore/src/csv.ts
to generate more compact markdown that improves LLM performance. 📈core/src/liner.test.ts
for more comprehensive testing.core/src/fetch.ts
.sample/genaisrc/data-analyst.genai.mjs
andsample/genaisrc/pandas.genai.mjs
.core/src/prompt_template.d.ts
for a new functionstop
to stop and clean Docker containers. 👨💻