Skip to content

Commit eaf750d

Browse files
committed
add ai_functions
1 parent 0cbbb08 commit eaf750d

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed

src/ai_functions/ai_func_architect.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use auto_gpt_agent::function_to_string as ai;
2+
3+
4+
#[ai]
5+
pub fn print_project_scope(_project_description: &str) {
6+
/// Input: Takes in a user request to build a website project description
7+
/// Function: Converts user request into JSON response of information items required for a website build.
8+
/// Important: At least one of the bool results must be true
9+
/// Output: Prints an object response in the following format:
10+
/// {
11+
/// "is_crud_required": bool, // true if site needs CRUD functionality
12+
/// "is_user_login_and_logout": bool // true if site needs users to be able to log in and log out
13+
/// "is_external_urls_required": bool // true if site needs to fetch data from third part providers
14+
/// }
15+
/// Example 1:
16+
/// user_request = "I need a full stack website that accepts users and gets stock price data"
17+
/// prints:
18+
/// {
19+
/// "is_crud_required": true
20+
/// "is_user_login_and_logout": true
21+
/// "is_external_urls_required": bool true
22+
/// }
23+
/// Example 2:
24+
/// user_request = "I need a simple TODO app"
25+
/// prints:
26+
/// {
27+
/// "is_crud_required": true
28+
/// "is_user_login_and_logout": false
29+
/// "is_external_urls_required": bool false
30+
/// }
31+
println!(OUTPUT);
32+
}
33+
34+
#[ai]
35+
pub fn print_site_urls(_project_description: &str) {
36+
/// Input: Takes in a project description of a website build
37+
/// Function: Outputs a list of external public API endpoints that should be used in the building of the website
38+
/// Important: Only selects url endpoint(s) which do not require any API Keys at all
39+
/// Output: Prints a list response of external urls in the following format:
40+
/// ["url1", "url2", "url3", ...]
41+
/// Example:
42+
/// website_team_spec = "website_purpose: Some("\"Provides Crypto Price Data from Binance and Kraken\"",)"
43+
/// prints:
44+
/// ["https://api.binance.com/api/v3/exchangeInfo", "https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1d"]
45+
println!(OUTPUT);
46+
}

src/ai_functions/ai_func_backend.rs

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
use auto_gpt_agent::function_to_string as ai;
2+
3+
#[ai]
4+
pub fn print_backend_webserver_code(_project_description: &str) {
5+
/// INPUT: Takes in a PROJECT_DESCRIPTION and CODE_TEMPLATE for a website backend build
6+
/// IMPORTANT: The backend code is ONLY an example. If the Project Description requires it, make as many changes as you like.
7+
/// IMPORTANT: You do not need to follow the backend code exactly. Write functions that make sense for the users request if required.
8+
/// FUNCTION: Takes an existing set of code marked as CODE_TEMPLATE and updates or re-writes it to work for the purpose in the PROJECT_DESCRIPTION
9+
/// IMPORTANT: The following libraries are already installed
10+
/// reqwest, serde, serde_json, tokio, actix-web, async-trait, actix_cors
11+
/// No other external libraries should be used. Write functions that fit with the description from the PROJECT_DESCRIPTION
12+
/// OUTPUT: Print ONLY the code, nothing else. This function ONLY prints code.
13+
println!(OUTPUT);
14+
}
15+
16+
#[ai]
17+
pub fn print_improved_webserver_code(_project_description: &str) {
18+
/// INPUT: Takes in a PROJECT_DESCRIPTION and CODE_TEMPLATE for a website backend build
19+
/// FUNCTION: Performs the following tasks:
20+
/// 1. Removes any bugs in the code and adds minor additional functionality
21+
/// 2. Makes sure everything requested in the spec from a backend standpoint was followed. If not, add the feature. No code should be implemented later. Everything should be written now.
22+
/// 3. ONLY writes the code. No commentary.
23+
/// IMPORTANT: The following libraries are already installed. Does not use ANY libraries other than what was provided in the template
24+
/// reqwest, serde, serde_json, tokio, actix-web, async-trait
25+
26+
println!(OUTPUT);
27+
}
28+
29+
#[ai]
30+
pub fn print_fixed_code(_project_description: &str) {
31+
/// INPUT: Takes in Rust BROKEN_CODE and the ERROR_BUGS found
32+
/// FUNCTION: Removes bugs from code
33+
/// IMPORTANT: Only prints out the new and improved code. No commentary or anything else
34+
println!(OUTPUT);
35+
}
36+
37+
38+
#[ai]
39+
pub fn print_rest_api_endpoints(_project_description: &str) {
40+
/// INPUT: Takes in Rust webserver CODE_INPUT based on actix-web
41+
/// FUNCTION: Prints out the JSON schema for url endpoints and their respective types
42+
/// LOGIC: Script analyses all code and can categorize into the following object keys:
43+
/// "route": This represents the url path of the endpoint
44+
/// "is_route_dynamic": if a route has curly braces in it such as {symbol} or {id} as an example, then this will be set to true
45+
/// "method": This represents the method being called
46+
/// "request_body": This represents the body of a post method request
47+
/// "response": This represents the output based upon the structs in the code and understanding the functions
48+
/// IMPORTANT: Only prints out the JSON schema. No commentary or anything else.
49+
/// MUST READ: All keys are strings. Even bool should be wrapped in double quotes as "bool"
50+
/// EXAMPLE:
51+
/// INPUT_CODE:
52+
/// ...
53+
/// pub struct Item {
54+
/// pub id: u64,
55+
/// pub name: String,
56+
/// pub completed: bool,
57+
/// }
58+
/// pub struct User {
59+
/// pub id: u64,
60+
/// pub username: String,
61+
/// pub password: String,
62+
/// }
63+
/// ...
64+
/// HttpServer::new(move || {
65+
/// App::new()
66+
/// .app_data(data.clone())
67+
/// .route("/item", web::post().to(create_item))
68+
/// .route("/item/{id}", web::get().to(read_item))
69+
/// .route("/item/{id}", web::put().to(update_item))
70+
/// .route("/item/{id}", web::delete().to(delete_item))
71+
/// .route("/signup", web::post().to(signup))
72+
/// .route("/crypto", web::get().to(crypto))
73+
/// PRINTS JSON FORMATTED OUTPUT:
74+
/// [
75+
/// {
76+
/// "route": "/item/{id}",
77+
/// "is_route_dynamic": "true",
78+
/// "method": "get"
79+
/// "request_body": "None",
80+
/// "response": {
81+
/// "id": "number",
82+
/// "name": "string",
83+
/// "completed": "bool",
84+
/// }
85+
/// },
86+
/// {
87+
/// "route": "/item",
88+
/// "is_route_dynamic": "false",
89+
/// "method": "post",
90+
/// "request_body": {
91+
/// "id": "number",
92+
/// "name": "string",
93+
/// "completed": "bool",
94+
/// },
95+
/// "response": "None"
96+
/// },
97+
/// {
98+
/// "route": "/item/{id}",
99+
/// "is_route_dynamic": "true",
100+
/// "method": "delete",
101+
/// "request_body": "None",
102+
/// "response": "None"
103+
/// },
104+
/// {
105+
/// "route": "/crypto",
106+
/// "is_route_dynamic": "false",
107+
/// "method": "get",
108+
/// "request_body": "None",
109+
/// "response": "not_provided"
110+
/// },
111+
/// ... // etc
112+
/// ]
113+
println!(OUTPUT);
114+
}

src/ai_functions/ai_func_manager.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use auto_gpt_agent::function_to_string as ai;
2+
3+
#[ai]
4+
pub fn convert_user_input_to_goal(_user_request: &str) {
5+
/// Input: Takes in a user request
6+
/// Function: Converts user request into a short summarized goal
7+
/// Output: Prints goal. All outputs start with "build a website that ..."
8+
/// Example 1:
9+
/// user_request = "I need a website that lets users login and logout. It needs to look fancy and accept payments."
10+
/// OUTPUT = "build a website that handles users logging in and logging out and accepts payments"
11+
/// Example 2:
12+
/// user_request = "Create something that stores crypto price data in a database using supabase and retrieves prices on the frontend."
13+
/// OUTPUT = "build a website that fetches and stores crypto price data within a supabase setup including a frontend UI to fetch the data."
14+
println!(OUTPUT)
15+
}

src/ai_functions/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod ai_func_architect;
2+
pub mod ai_func_backend;
3+
pub mod ai_func_manager;

0 commit comments

Comments
 (0)