https://github.com/refcell/run-wild/commit/7b71a4cd928b4382dd3086e7843170880075c098 Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + For + Enterprise + Teams + Startups + Education + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} refcell / run-wild Public forked from m1guelpf/browser-agent * Notifications * Fork 10 * Star 100 * Code * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Pull requests * Actions * Projects * Security * Insights Permalink This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. Browse files run wild gpt, run free... * Loading branch information @refcell refcell committed Mar 26, 2023 1 parent e2d067c commit 7b71a4c Show file tree Hide file tree Showing 6 changed files with 34 additions and 26 deletions. Split Unified [ ] * .env.example .env.example * .gitignore .gitignore * README.md README.md * src + src/agent.rs agent.rs + src/main.rs main.rs + src/openai.rs openai.rs There are no files selected for viewing 1 .env.example [*] Show comments View file Edit file Delete file This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters Original file line number Diff line number Diff line change @@ -0,0 +1 @@ OPENAI_API_KEY= 1 .gitignore [*] Show comments View file Edit file Delete file This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters Original file line number Diff line number Diff line change @@ -1,3 +1,4 @@ /target /browser /user_data .env 19 README.md [*] Show comments View file Edit file Delete file This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters Original Diff file line Diff line change line number number @@ -1,26 +1,27 @@ # A browser AI agent, using GPT-4 # Run Wild This project provides a bridge between GPT-4 and a headless Chromium browser, allowing you to automate actions simply by describing them to the program. It takes the form of a Rust CLI, but also exports most of the internals as a library for others to use. `run-wild` extends [m1guelpf](https://github.com/ m1guelpf)'s [browser-agent](https://github.com/ m1guelpf/browser-agent) project by allowing gpt4 to alter it's goal. This is very dumb and probably ought not exist, but c'est la vie. At it's core, `run-wild` bridges GPT-4 and a headless Chromium browser, automating actions as self-directed by it's goal. It takes the form of a Rust CLI, but also exports most of the internals as a library for others to use. ## Installation `browser-agent` is built using Rust, so you'll need to install the Rust toolchain. You can do this by following the instructions at [rustup.rs](https:// rustup.rs/). `run-wild` is built using Rust, so you'll need to install the Rust toolchain. You can do this by following the instructions at [rustup.rs](https:// rustup.rs/). Once you have Rust installed, you can install ` browser-agent` by running: Once you have Rust installed, you can install ` run-wild` by running: ```bash cargo install browser-agent cargo install run-wild ``` You should also place your OpenAI API key in the `OPENAI_API_KEY` environment variable. This key should have access to the `gpt-4` model. You can copy the contents of the `example.env` file to a `.env` file in the root of the project, and fill in the `OPENAI_API_KEY` variable. The `.env` file is ignored by git, so you don't have to worry about accidentally committing your API key. Note though, `.env.example` is not ignored, so you should not change that file. ## Usage ``` Usage: browser-agent [OPTIONS] Arguments: The goal for the agent to achieve Usage: run-wild [OPTIONS] Options: --visual Whether to show the browser window. Warning: this makes the agent more unreliable 10 src/agent.rs [*] Show comments View file Edit file Delete file This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters Original file Diff line Diff line change line number number @@ -6,9 +6,9 @@ pub enum Action { /// Click on an element. /// The usize is the id of the element. Click(usize), /// Respond to the user with the given text. /// The String is the text to respond with. Answer(String), /// Outputs the update goal. Goal(String), /// Type the given text into the given element and press ENTER. /// The usize is the id of the element, and the String is the text to type. @@ -39,14 +39,14 @@ impl TryFrom for Action { Ok(Self::Type(id, text)) } "ANSWER" => { "GOAL" => { let text = parts .collect::>() .join(" ") .trim_matches('"') .to_string(); Ok(Self::Answer(text)) Ok(Self::Goal(text)) } _ => bail!("Unknown command, got {command}" ), } 7 src/main.rs [*] Show comments View file Edit file Delete file This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters Original file Diff line Diff line change line number number @@ -13,9 +13,6 @@ use browser_agent:: {browser, translate, Action, Conversation}; #[derive(Debug, Parser)] #[command(author, version, about, long_about = None)] struct Cli { /// The goal for the agent to achieve goal: String, /// Whether to show the browser window. Warning: this makes the agent more unreliable. #[arg(long)] visual: bool, @@ -52,7 +49,7 @@ async fn main() -> Result <()> { .with(tracing_subscriber::fmt::layer()) .init(); let mut conversation = Conversation::new(args .goal); let mut conversation = Conversation::new(); let mut browser = browser::init( Path::new("./browser"), Path::new("./user_data"), @@ -100,7 +97,7 @@ async fn main() -> Result <()> { element.type_str(text).await?; element.press_key("Enter").await?; } Action::Answer(text) => { Action::Goal(text) => { println!("{text}"); break; } 22 src/openai.rs [*] Show comments View file Edit file Delete file This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters Original Diff file line line Diff line change number number @@ -22,32 +22,40 @@ pub struct Conversation { messages: Vec, } impl Conversation { /// Create a new conversation with GPT-4. #[must_use] pub fn new(goal: String) -> Self { impl Default for Conversation { fn default() -> Self { Self { goal, goal: String::from("Visit 10 webpages."), url: None, client: Client::new(), messages: vec![ChatCompletionRequestMessage { name: None, role: Role::System, content: formatdoc!(" You are an agent controlling a browser. You are given an objective that you are trying to achieve, the URL of the current website, and a simplified markup description of the page contents, which looks like this: You are an agent controlling a browser. You are given the URL of the current website, and a simplified markup description of the page contents, which looks like this:

text

text placeholder \"image You are not given a goal but should create and alter a goal based on the previous actions you have taken. Your initial goal should be to visit at least 10 webpages and update your goal based on the content of those page. You must respond with ONLY one of the following commands AND NOTHING ELSE: - CLICK X - click on a given element. You can only click on links, buttons, and inputs! - TYPE X \"TEXT\" - type the specified text into the input with id X and press ENTER - ANSWER \"TEXT\" - Respond to the user with the specified text once you have completed the objective - GOAL \"TEXT\" - Outputs your updated goal. "), }]} } } impl Conversation { /// Create a new conversation with GPT-4. #[must_use] pub fn new() -> Self { Self::default() } /// Request and execute an action from GPT-4. #[tracing::instrument] Toggle all file notes Toggle all file annotations 0 comments on commit 7b71a4c Please sign in to comment. Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.