โ† Writing

๐Ÿค– Actix-web AI Agent

2025-01-26 rust ยท actix_web ยท open_ai ยท project


Actix-web AI Agent. Built with ๐ŸคŽ in Rust
Effortless Backend Prototyping with Rust
Documentation


โ€ƒโ€ƒโ€ƒ RestOn

๐Ÿ“š rest_on

RestOn is an advanced tool that leverages the power of OpenAIโ€™s GPT to automate the generation of backend code for your projects and prototypes. It aims to streamline your development process, enabling the automatic creation of full-stack web applications and more complex systems. Whether you need a simple CRUD app or a sophisticated SAAS platform, Auto GPT Agent has you covered.

โ€ƒโ€ƒโ€ƒ Features

โ€ƒโ€ƒโ€ƒ Tools

Rust Version Actix-web Version Tokio Version reqwest Version Serde Version Actix-cors Version dotenv Version Crossterm Version async-trait Version Webbrowser Version AI_functions Version

โ€ƒโ€ƒโ€ƒ Installation

โ€ƒโ€ƒโ€ƒ 1. Clone the Repository

git clone https://github.com/chemyl/auto_gpt_agent.git
cd auto_gpt_agent

โ€ƒโ€ƒโ€ƒ 2. Install Rust (if not already installed)

To install Rust, use the following command:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

โ€ƒโ€ƒโ€ƒ 3. Install Dependencies

Run the following command to install project dependencies:

cargo build

โ€ƒโ€ƒโ€ƒ 4.Add OPEN_AI Keys

    OPEN_AI_ORG
    OPEN_AI_KEY
.env

โ€ƒโ€ƒโ€ƒ 5. Run the Project

Start the project with:

cargo run

โ€ƒโ€ƒโ€ƒ Usage

โ€ƒโ€ƒโ€ƒ 1. Generate Backend Code

Simply send a text query to the system, and it will generate backend code for you.

Example query:

Create a webserver that shows today viral news in the US

โ€ƒโ€ƒโ€ƒ 3. Confirmation

After generating the backend code, you can

โ€ƒโ€ƒโ€ƒ Example Usage

โ€ƒโ€ƒโ€ƒ 1. Console Output

โ€ƒโ€ƒโ€ƒ 2. Generated [main] Example

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let db: Database = Database::load_from_file().unwrap_or_else(|_| Database::new());
    let data: web::Data<AppState> = web::Data::new(AppState {
        db: Mutex::new(db)
    });

    HttpServer::new(move || {
        App::new()
            .wrap(
                Cors::permissive()
                    .allowed_origin_fn(|origin, _req_head| {
                        origin.as_bytes().starts_with(b"http://localhost") || origin == "null"
                    })
                    .allowed_methods(vec!["GET", "POST", "PUT", "DELETE"])
                    .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
                    .allowed_header(header::CONTENT_TYPE)
                    .supports_credentials()
                    .max_age(3600)
            )
            .app_data(data.clone())
            .route("/news", web::post().to(create_news))
            .route("/news", web::get().to(read_all_news))
            .route("/news", web::put().to(update_news))
            .route("/news/{id}", web::get().to(read_news))
            .route("/news/{id}", web::delete().to(delete_news))
    })
        .bind("127.0.0.1:8080")?
        .run()
        .await
}

โ€ƒโ€ƒโ€ƒ How It Works

  1. The project uses GPT API to process text queries and generate code.
  2. Queries are sent to the system, which then generates backend code based on the input.
  3. The code generation includes:
    • Creating new HTTP server.
    • Route creation for handling requests.
    • Json Database setup.
  4. The generated code can be directly run on your server or further customized to fit your needs.

โ€ƒโ€ƒโ€ƒ Future Plans

โ€ƒโ€ƒโ€ƒ Contributing

Welcome contributions! If you have ideas to improve the project, please create an issue or submit a pull request.

โ€ƒโ€ƒโ€ƒ How to Contribute

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to your branch (git push origin feature-branch).
  5. Open a Pull Request.

โ€ƒโ€ƒโ€ƒ License

This project is licensed under the MIT License - see the LICENSE file for details.