planets.rs

 1use agent::{AgentTool, OpenTool, TerminalTool};
 2use agent_settings::AgentProfileId;
 3use anyhow::Result;
 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            profile_id: AgentProfileId::default(),
20            existing_thread_json: None,
21            max_turns: None,
22        }
23    }
24
25    async fn conversation(&self, cx: &mut ExampleContext) -> Result<()> {
26        let response = cx
27            .prompt(
28                r#"
29            Make a plain JavaScript web page which renders an animated 3D solar system.
30            Let me drag to rotate the camera around.
31            Do not use npm.
32            "#,
33            )
34            .await?;
35        let mut open_tool_uses = 0;
36        let mut terminal_tool_uses = 0;
37
38        for tool_use in response.tool_calls() {
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}