Skip to content

Commit

Permalink
release v0.3.15
Browse files Browse the repository at this point in the history
  • Loading branch information
aisi-inspect committed Jun 16, 2024
1 parent bca3ac8 commit 51551b1
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 111 deletions.
22 changes: 22 additions & 0 deletions src/inspect_ai/_view/www/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,20 @@ pre[class*=language-] {
margin-bottom: 0.75em;
}


.sample-answer .markdown-content h1,
.sample-answer .markdown-content h2,
.sample-answer .markdown-content h3,
.sample-answer .markdown-content h4,
.sample-answer .markdown-content h5,
.sample-answer .markdown-content h6 {
font-size: 1em;
font-weight: 400;
margin-top: 0em;
margin-bottom: 0em;
}


.accordion-item:not(.no-highlight) .collapse.show.highlight-when-expanded,
.accordion-item:not(.no-highlight) .collapsing.highlight-when-expanded,
.accordion-item:not(.no-highlight) .accordion-button[aria-expanded="true"].highlight-when-expanded {
Expand Down Expand Up @@ -604,4 +618,12 @@ table.table.table-sm td {

.expandable-panel pre {
overflow: unset;
}

.tool-output {
background-color: #f8f8f8;
}

.vscode-dark .tool-output {
background-color: #333333;
}
17 changes: 10 additions & 7 deletions src/inspect_ai/_view/www/App.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { html } from "htm/preact";
import { useCallback, useState, useEffect, useRef } from "preact/hooks";
import { useCallback, useState, useEffect, useMemo, useRef } from "preact/hooks";

// Registration component
import "./src/Register.mjs";
Expand Down Expand Up @@ -267,13 +267,15 @@ export function App() {
/>
`;

const progress = () => {
const progress = useMemo(() => {
if (status.loading) {
return html`<${ProgressBar}/>`;
} else {
return undefined;
}
}
}, [status]);

const workspace = () => {
const workspace = useMemo(() => {
if (status.error) {
return html`<${ErrorPanel}
title="An error occurred while loading this task."
Expand All @@ -289,13 +291,14 @@ export function App() {
offcanvas=${offcanvas}
/>`
}
}
}, [logs, currentLog, selected, fullScreen, offcanvas, status]);

return html`
<${AppErrorBoundary}>
<div>
${appEnvelope}
${progress()}
${workspace()}
${progress}
${workspace}
</div>
</${AppErrorBoundary}>
`;
Expand Down
108 changes: 107 additions & 1 deletion src/inspect_ai/_view/www/libs/prism/prism-dark.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
/* PrismJS 1.29.0
https://prismjs.com/download.html#themes=prism-dark&languages=markup+css+clike+javascript+bash+python */
code[class*=language-],pre[class*=language-]{color:#fff;background:0 0;text-shadow:0 -.1em .2em #000;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}:not(pre)>code[class*=language-],pre[class*=language-]{background:#4c3f33}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border:.3em solid #7a6651;border-radius:.5em;box-shadow:1px 1px .5em #000 inset}:not(pre)>code[class*=language-]{padding:.15em .2em .05em;border-radius:.3em;border:.13em solid #7a6651;box-shadow:1px 1px .3em -.1em #000 inset;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#997f66}.token.punctuation{opacity:.7}.token.namespace{opacity:.7}.token.boolean,.token.constant,.token.number,.token.property,.token.symbol,.token.tag{color:#d1939e}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#bce051}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url,.token.variable{color:#f4b73d}.token.atrule,.token.attr-value,.token.keyword{color:#d1939e}.token.important,.token.regex{color:#e90}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}.token.deleted{color:red}
/* DO NOT SIMPLY REPLACE - NOTE the '.vscode-dark' preview on selectors
which is used to target this at vscode dark mode. Be sure to replace this
when updating */
.vscode-dark code[class*="language-"],
.vscode-dark pre[class*="language-"] {
color: #fff;
background: 0 0;
text-shadow: 0 -0.1em 0.2em #000;
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
font-size: 1em;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
@media print {
.vscode-dark code[class*="language-"],
.vscode-dark pre[class*="language-"] {
text-shadow: none;
}
}
.vscode-dark :not(pre) > code[class*="language-"],
.vscode-dark pre[class*="language-"] {
background: #4c3f33;
}
.vscode-dark pre[class*="language-"] {
padding: 1em;
margin: 0.5em 0;
overflow: auto;
border: 0.3em solid #7a6651;
border-radius: 0.5em;
box-shadow: 1px 1px 0.5em #000 inset;
}
.vscode-dark :not(pre) > code[class*="language-"] {
padding: 0.15em 0.2em 0.05em;
border-radius: 0.3em;
border: 0.13em solid #7a6651;
box-shadow: 1px 1px 0.3em -0.1em #000 inset;
white-space: normal;
}
.vscode-dark .token.cdata,
.vscode-dark .token.comment,
.vscode-dark .token.doctype,
.vscode-dark .token.prolog {
color: #997f66;
}
.vscode-dark .token.punctuation {
opacity: 0.7;
}
.vscode-dark .token.namespace {
opacity: 0.7;
}
.vscode-dark .token.boolean,
.vscode-dark .token.constant,
.vscode-dark .token.number,
.vscode-dark .token.property,
.vscode-dark .token.symbol,
.vscode-dark .token.tag {
color: #d1939e;
}
.vscode-dark .token.attr-name,
.vscode-dark .token.builtin,
.vscode-dark .token.char,
.vscode-dark .token.inserted,
.vscode-dark .token.selector,
.vscode-dark .token.string {
color: #bce051;
}
.vscode-dark .language-css .token.string,
.vscode-dark .style .token.string,
.vscode-dark .token.entity,
.vscode-dark .token.operator,
.vscode-dark .token.url,
.vscode-dark .token.variable {
color: #f4b73d;
}
.vscode-dark .token.atrule,
.vscode-dark .token.attr-value,
.vscode-dark .token.keyword {
color: #d1939e;
}
.vscode-dark .token.important,
.vscode-dark .token.regex {
color: #e90;
}
.vscode-dark .token.bold,
.vscode-dark .token.important {
font-weight: 700;
}
.vscode-dark .token.italic {
font-style: italic;
}
.vscode-dark .token.entity {
cursor: help;
}
.vscode-dark .token.deleted {
color: red;
}
2 changes: 1 addition & 1 deletion src/inspect_ai/_view/www/src/components/ChatView.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ export const ToolInput = ({ type, contents }) => {
}, [toolInputRef.current, type, contents]);

return html` <pre
class="tool-output"
style=${{
padding: "0.5em",
backgroundColor: "#f8f8f8",
marginTop: "0.25em",
marginBottom: "1rem",
}}
Expand Down
16 changes: 2 additions & 14 deletions src/inspect_ai/_view/www/src/samples/SampleDisplay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ChatView } from "../components/ChatView.mjs";
import { MetaDataView } from "../components/MetaDataView.mjs";
import { TabSet, TabPanel } from "../components/TabSet.mjs";

import { inputString } from "../utils/Format.mjs"

import { sharedStyles } from "../Constants.mjs";
import {
arrayToString,
Expand Down Expand Up @@ -143,20 +145,6 @@ const metadataViewsForSample = (id, sample, context) => {
return sampleMetadatas;
};

const inputString = (input) => {
if (typeof input === "string") {
return input;
} else {
return input.map((inp) => {
if (typeof inp === "string") {
return inp;
} else {
return inp.content;
}
});
}
};

const SampleSummary = ({ id, sample, sampleDescriptor }) => {
const input =
sampleDescriptor?.messageShape.input > 0
Expand Down
3 changes: 2 additions & 1 deletion src/inspect_ai/_view/www/src/samples/SampleList.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "../utils/Format.mjs";
import { EmptyPanel } from "../components/EmptyPanel.mjs";
import { VirtualList } from "../components/VirtualList.mjs";
import { inputString } from "../utils/Format.mjs"

const kSampleHeight = 82;
const kSeparatorHeight = 20;
Expand Down Expand Up @@ -240,7 +241,7 @@ const SampleRow = ({
...cellStyle,
}}
>
${sample.input}
${inputString(sample.input)}
</div>
<div
class="sample-target"
Expand Down
7 changes: 4 additions & 3 deletions src/inspect_ai/solver/_tool/environment/docker/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from inspect_ai._util.error import exception_message

from .compose import compose_down
from .config import auto_config_cleanup
from .util import ComposeProject


Expand All @@ -22,9 +23,6 @@ async def project_cleanup(project: ComposeProject, quiet: bool = True) -> None:
# bring down services
await compose_down(project=project, quiet=quiet)

# remove temp dir
project.temp_dir.cleanup()

# remove the project from the list of running projects
running_projects().remove(project)

Expand Down Expand Up @@ -53,6 +51,9 @@ async def project_cleanup_shutdown() -> None:
f"Error cleaning up compose containers: {exception_message(result)}"
)

# cleanup auto config
auto_config_cleanup()


def running_projects() -> list[ComposeProject]:
return _running_projects.get()
Expand Down
8 changes: 5 additions & 3 deletions src/inspect_ai/solver/_tool/environment/docker/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from inspect_ai.util._context.subprocess import ExecResult, subprocess

from .config import auto_config
from .util import ComposeProject, tools_log

logger = getLogger(__name__)
Expand Down Expand Up @@ -129,7 +130,7 @@ async def compose_exec(
async def compose_services(project: ComposeProject) -> dict[str, ComposeService]:
result = await compose_command(["config"], project=project)
if not result.success:
raise RuntimeError("Error reading docker config: {result.stderr}")
raise RuntimeError(f"Error reading docker config: {result.stderr}")
return cast(dict[str, ComposeService], yaml.safe_load(result.stdout)["services"])


Expand Down Expand Up @@ -193,8 +194,9 @@ async def compose_command(
compose_command = compose_command + ["--project-name", project.name]

# add config file if specified
if project.config:
compose_command = compose_command + ["-f", project.config]
config = project.config if project.config else await auto_config()
if config:
compose_command = compose_command + ["-f", config]

# build final command
compose_command = compose_command + command
Expand Down
60 changes: 32 additions & 28 deletions src/inspect_ai/solver/_tool/environment/docker/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import tempfile
from logging import getLogger
from pathlib import Path

Expand All @@ -8,18 +7,28 @@
logger = getLogger(__name__)


async def auto_config(temp_dir: str) -> str | None:
async def auto_config() -> str | None:
# compose file provides all the config we need
if has_compose_file():
return None

# temporary auto-compose
if has_auto_compose_file():
return AUTO_COMPOSE_YAML

# dockerfile just needs a compose.yaml synthesized
elif has_dockerfile():
return await dockerfile_compose(Path(), temp_dir)
return await auto_compose_file(COMPOSE_DOCKERFILE_YAML)

# otherwise provide a generic python container
else:
return await generic_container_compose(temp_dir)
return await auto_compose_file(COMPOSE_GENERIC_YAML)


def auto_config_cleanup() -> None:
# if we have an auto-generated .compose.yaml then clean it up
if has_auto_compose_file():
Path(AUTO_COMPOSE_YAML).unlink(True)


def has_compose_file() -> bool:
Expand All @@ -39,37 +48,32 @@ def has_dockerfile() -> bool:
return os.path.isfile("Dockerfile")


# Our default compose.yaml
COMPOSE_GENERIC_YAML = """
def has_auto_compose_file() -> bool:
return os.path.isfile(AUTO_COMPOSE_YAML)


AUTO_COMPOSE_YAML = ".compose.yaml"

COMPOSE_COMMENT = """# inspect auto-generated docker compose file
# (will be removed when task is complete)"""

COMPOSE_GENERIC_YAML = f"""{COMPOSE_COMMENT}
services:
default:
image: "python:3.12-bookworm"
command: tail -f /dev/null
command: "tail -f /dev/null"
"""


async def generic_container_compose(directory: str) -> str:
return await default_compose_file(directory, COMPOSE_GENERIC_YAML)


async def dockerfile_compose(context: Path, directory: str) -> str:
# Template for a DockerFile
compose_dockerfile_yaml = f"""
COMPOSE_DOCKERFILE_YAML = f"""{COMPOSE_COMMENT}
services:
default:
build:
context: {context.resolve().as_posix()}
command: tail -f /dev/null
"""

return await default_compose_file(directory, compose_dockerfile_yaml)
context: "."
command: "tail -f /dev/null"
"""


# Provide the path to a default compose file
async def default_compose_file(directory: str, contents: str) -> str:
with tempfile.NamedTemporaryFile(
dir=directory, suffix=".yaml", delete=False
) as compose_file:
async with aiofiles.open(compose_file.name, "w", encoding="utf-8") as f:
await f.write(contents)
return compose_file.name
async def auto_compose_file(contents: str) -> str:
async with aiofiles.open(AUTO_COMPOSE_YAML, "w", encoding="utf-8") as f:
await f.write(contents)
return AUTO_COMPOSE_YAML
Loading

0 comments on commit 51551b1

Please sign in to comment.