Skip to content

Commit

Permalink
fix system parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Aug 14, 2024
1 parent 254ddb6 commit 64732cc
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 30 deletions.
3 changes: 2 additions & 1 deletion docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/src/components/BuiltinTools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Check failure on line 12 in docs/src/components/BuiltinTools.mdx

View workflow job for this annotation

GitHub Actions / build

The link for the `python_code_interpreter` tool needs to be updated to reflect the new tool name.
<LinkCard title="python_code_interpreter" description="Executes python 3.12 code for Data Analysis tasks in a docker container. The process output is returned. Do not generate visualizations. The only packages available are numpy, pandas, scipy. There is NO network connectivity. Do not attempt to install other packages or make web requests." href="/genaiscript/reference/scripts/system#systempython_code_interpreter" />
<LinkCard title="retrieval_fuzz_search" description="Search for keywords using the full text of files and a fuzzy distance." href="/genaiscript/reference/scripts/system#systemretrieval_fuzz_search" />
<LinkCard title="retrieval_vector_search" description="Search files using embeddings and similarity distance." href="/genaiscript/reference/scripts/system#systemretrieval_vector_search" />
<LinkCard title="retrieval_web_search" description="Search the web for a user query using Bing Search." href="/genaiscript/reference/scripts/system#systemretrieval_web_search" />
Expand Down
8 changes: 2 additions & 6 deletions docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ Python Dockerized code execution for data analysis

Check failure on line 598 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

The description of the tool should be updated to "Executes python 3.12 code for Data Analysis tasks in a docker container."
- tool `python_code_interpreter`: Executes python 3.12 code for Data Analysis tasks in a docker container. The process output is returned. Do not generate visualizations. The only packages available are numpy, pandas, scipy. There is NO network connectivity. Do not attempt to install other packages or make web requests.
`````js wrap title="system.python_code_interpreter"
system({
Expand All @@ -610,11 +610,7 @@ let container = null

defTool(

Check failure on line 611 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

The tool name in the definition should be updated to `python_code_interpreter`.
"python_code_interpreter",
`Executes python 3.12 code for Data Analysis tasks in a docker container.
- The process output is returned.
- Do not generate visualizations.
- The only packages available are ${packages.join(", ")}.
- There is NO network connectivity. Do not attempt to install other packages or make web requests.`,
"Executes python 3.12 code for Data Analysis tasks in a docker container. The process output is returned. Do not generate visualizations. The only packages available are numpy, pandas, scipy. There is NO network connectivity. Do not attempt to install other packages or make web requests.",
{
type: "object",
properties: {
Expand Down
3 changes: 2 additions & 1 deletion genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions packages/cli/src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,16 @@ export class DockerManager {
const disconnect = async () => {
const networks = await this._docker.listNetworks()
for (const network of networks.filter(
(n) => n.Name !== "bridge"
({ Name }) => Name === "bridge"
)) {
console.log(`container: disconnect ${network.Name}`)
const n = await this._docker.getNetwork(network.Id)
if (n) await n.disconnect({ Container: container.id })
if (n) {
const state = await n.inspect()
if (state?.Containers?.[container.id]) {
console.log(`container: disconnect ${network.Name}`)

Check failure on line 311 in packages/cli/src/docker.ts

View workflow job for this annotation

GitHub Actions / build

There is a `console.log` statement on line 311. This could potentially leak sensitive information in a production environment. Consider using a proper logging mechanism that respects different log levels. 😊
await n.disconnect({ Container: container.id })
}
}
}

Check failure on line 315 in packages/cli/src/docker.ts

View workflow job for this annotation

GitHub Actions / build

There is no error handling for the async operations within the `disconnect` function. If any of these operations fail, it could lead to unexpected behavior. Consider adding try-catch blocks to handle potential errors. 😊
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ let container = null

defTool(
"python_code_interpreter",
`Executes python 3.12 code for Data Analysis tasks in a docker container.
- The process output is returned.
- Do not generate visualizations.
- The only packages available are ${packages.join(", ")}.
- There is NO network connectivity. Do not attempt to install other packages or make web requests.`,
"Executes python 3.12 code for Data Analysis tasks in a docker container. The process output is returned. Do not generate visualizations. The only packages available are numpy, pandas, scipy. There is NO network connectivity. Do not attempt to install other packages or make web requests.",
{
type: "object",
properties: {
Expand All @@ -30,7 +26,6 @@ defTool(
if (!container) {
console.log(`python: preparing container...`)
container = await host.container({ image, networkEnabled: true })
await container.disconnect()
const res = await container.exec("pip", [
"install",
"--root-user-action",
Expand Down
8 changes: 6 additions & 2 deletions packages/sample/genaisrc/container.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ script({
})

const disablePurge = env.vars.purge === "no"
const container = await host.container({ disablePurge })
const container = await host.container({ disablePurge, networkEnabled: true })
const version = await container.exec("python", ["--version"])
if (!/^python \d/i.test(version.stdout))
throw new Error("python --version failed")
await container.disconnect()
const pipfailed = await container.exec("pip", ["install", "pandas"])
if (!pipfailed.failed) throw new Error("network not disconnected")
await container.writeText("pythonversion.txt", version.stdout)
const fversion = await container.readText("pythonversion.txt")
if (version.stdout !== fversion)
throw new Error(
`writetext/readtext error, expected '${version.stdout}', got '${fversion}'`
)
await container.copyTo("src/rag/*", "copied")
if (!await container.readText("copied/src/rag/markdown.md")) throw new Error("copy failed")
if (!(await container.readText("copied/src/rag/markdown.md")))
throw new Error("copy failed")
await container.writeText("main.py", 'print("hello")')
const hello = await container.exec("python", ["main.py"])
if (hello.exitCode) throw new Error("python script failed")
Expand Down
3 changes: 2 additions & 1 deletion packages/sample/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/sample/genaisrc/node/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/sample/genaisrc/python/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/sample/genaisrc/style/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 64732cc

Please sign in to comment.