planets.rs

 1use anyhow::Result;
 2use assistant_tool::Tool;
 3use assistant_tools::{OpenTool, TerminalTool};
 4use async_trait::async_trait;
 5
 6use crate::example::{Example, ExampleContext, ExampleMetadata, JudgeAssertion};
 7
 8pub struct Planets;
 9
10#[async_trait(?Send)]
11impl Example for Planets {
12    fn meta(&self) -> ExampleMetadata {
13        ExampleMetadata {
14            name: "planets".to_string(),
15            url: "https://github.com/roc-lang/roc".to_string(), // This commit in this repo is just the Apache2 license,
16            revision: "59e49c75214f60b4dc4a45092292061c8c26ce27".to_string(), // so effectively a blank project.
17            language_server: None,
18            max_assertions: None,
19        }
20    }
21
22    async fn conversation(&self, cx: &mut ExampleContext) -> Result<()> {
23        cx.push_user_message(
24            r#"
25            Make a plain JavaScript web page which renders an animated 3D solar system.
26            Let me drag to rotate the camera around.
27            Do not use npm.
28            "#
29            .to_string(),
30        );
31
32        let response = cx.run_to_end().await?;
33        let mut open_tool_uses = 0;
34        let mut terminal_tool_uses = 0;
35
36        for tool_use in response.tool_uses() {
37            if tool_use.name == OpenTool.name() {
38                open_tool_uses += 1;
39            } else if tool_use.name == TerminalTool.name() {
40                terminal_tool_uses += 1;
41            }
42        }
43
44        // The open tool should only be used when requested, which it was not.
45        cx.assert_eq(open_tool_uses, 0, "`open` tool was not used")
46            .ok();
47        // No reason to use the terminal if not using npm.
48        cx.assert_eq(terminal_tool_uses, 0, "`terminal` tool was not used")
49            .ok();
50
51        Ok(())
52    }
53
54    fn diff_assertions(&self) -> Vec<JudgeAssertion> {
55        vec![
56            JudgeAssertion {
57                id: "animated solar system".to_string(),
58                description: "This page should render a solar system, and it should be animated."
59                    .to_string(),
60            },
61            JudgeAssertion {
62                id: "drag to rotate camera".to_string(),
63                description: "The user can drag to rotate the camera around.".to_string(),
64            },
65            JudgeAssertion {
66                id: "plain JavaScript".to_string(),
67                description:
68                    "The code base uses plain JavaScript and no npm, along with HTML and CSS."
69                        .to_string(),
70            },
71        ]
72    }
73}