planets.rs

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