Skip to content

Commit 02aff0c

Browse files
authored
Update the docs to the correct API output
Signed-off-by: Michael Yuan <[email protected]>
1 parent 965c177 commit 02aff0c

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

README.md

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,21 @@ The API provides the following endpoints:
113113

114114
#### 📤 Response:
115115

116-
```
117-
[filename: Cargo.toml]
118-
[package]
119-
name = "calculator"
120-
version = "0.1.0"
121-
edition = "2021"
122-
123-
[dependencies]
124-
... ...
116+
The `combined_text` field contains the flat text output of Rust project files that can be used as input for `/compile` and `/compile-and-fix` API calls.
125117

126-
[filename: src/main.rs]
127-
fn main() {
128-
// Calculator implementation
118+
```
119+
{
120+
"success": true,
121+
"message":"Project generated successfully",
122+
"combined_text":"[filename: Cargo.toml]\n[package]\nname = \"calculator\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html\n\n[dependencies]\nclap = { version = \"4.5\", features = [\"derive\"] }\n\n[filename: src/main.rs]\nuse std::io;\nuse clap::Parser;\n\n#[derive(Parser, Debug)]\n#[command(author, version, about, long_about = None)]\nstruct Args {\n /// The first number\n #[arg(required = true)]\n num1: f64,\n /// Operator (+, -, *, /)\n #[arg(required = true, value_parser = clap::value_parser!(f64))]\n operator: String,\n /// The second number\n #[arg(required = true)]\n num2: f64,\n}\n\nfn main() -> Result<(), Box<dyn std::error::Error>> {\n let args = Args::parse();\n\n match args.operator.as_str() {\n \"+\" => {\n println!(\"{}\", args.num1 + args.num2);\n }\n \"-\" => {\n println!(\"{}\", args.num1 - args.num2);\n }\n \"*\" => {\n println!(\"{}\", args.num1 * args.num2);\n }\n \"/\" => {\n if args.num2 == 0.0 {\n eprintln!(\"Error: Cannot divide by zero.\");\n std::process::exit(1);\n }\n println!(\"{}\", args.num1 / args.num2);\n }\n _ => {\n eprintln!(\"Error: Invalid operator. Use +, -, *, or /\");\n std::process::exit(1);\n }\n }\n\n Ok(())\n}\n\n[filename: README.md]\n# Calculator\n\nA simple command-line calculator written in Rust. Supports addition, subtraction, multiplication, and division.\n\n## Usage\n\nRun the program with two numbers and an operator as arguments:\n\n```bash\ncargo run <num1> <operator> <num2>\n```\n\nWhere `<operator>` is one of `+`, `-`, `*`, or `/`.\n\n**Example:**\n\n```bash\ncargo run 5 + 3\n# Output: 8\n\ncargo run 10 / 2\n# Output: 5\n\ncargo run 7 * 4\n# Output: 28\n```\n\n## Error Handling\n\nThe calculator handles division by zero and invalid operator inputs. Error messages are printed to standard error, and the program exits with a non-zero exit code in case of an error.\n\n\n# Build succeeded",
123+
"files":{
124+
"Cargo.toml":"[package]\nname = \"calculator\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html\n\n[dependencies]\nclap = { version = \"4.5\", features = [\"derive\"] }",
125+
"src/main.rs":"use std::io;\nuse clap::Parser;\n\n#[derive(Parser, Debug)]\n#[command(author, version, about, long_about = None)]\nstruct Args {\n /// The first number\n #[arg(required = true)]\n num1: f64,\n /// Operator (+, -, *, /)\n #[arg(required = true, value_parser = clap::value_parser!(f64))]\n operator: String,\n /// The second number\n #[arg(required = true)]\n num2: f64,\n}\n\nfn main() -> Result<(), Box<dyn std::error::Error>> {\n let args = Args::parse();\n\n match args.operator.as_str() {\n \"+\" => {\n println!(\"{}\", args.num1 + args.num2);\n }\n \"-\" => {\n println!(\"{}\", args.num1 - args.num2);\n }\n \"*\" => {\n println!(\"{}\", args.num1 * args.num2);\n }\n \"/\" => {\n if args.num2 == 0.0 {\n eprintln!(\"Error: Cannot divide by zero.\");\n std::process::exit(1);\n }\n println!(\"{}\", args.num1 / args.num2);\n }\n _ => {\n eprintln!(\"Error: Invalid operator. Use +, -, *, or /\");\n std::process::exit(1);\n }\n }\n\n Ok(())\n}",
126+
"README.md":"# Calculator\n\nA simple command-line calculator written in Rust. Supports addition, subtraction, multiplication, and division.\n\n## Usage\n\nRun the program with two numbers and an operator as arguments:\n\n```bash\ncargo run <num1> <operator> <num2>\n```\n\nWhere `<operator>` is one of `+`, `-`, `*`, or `/`.\n\n**Example:**\n\n```bash\ncargo run 5 + 3\n# Output: 8\n\ncargo run 10 / 2\n# Output: 5\n\ncargo run 7 * 4\n# Output: 28\n```\n\n## Error Handling\n\nThe calculator handles division by zero and invalid operator inputs. Error messages are printed to standard error, and the program exits with a non-zero exit code in case of an error."
127+
},
128+
"build_output":null,
129+
"build_success":true
129130
}
130-
... ...
131131
```
132132

133133
### 🛠 Compile a Project
@@ -176,7 +176,7 @@ curl -X POST http://localhost:8000/compile \
176176
curl -X POST http://localhost:8000/compile-and-fix \
177177
-H "Content-Type: application/json" \
178178
-d '{
179-
"code": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\" // Missing closing parenthesis\n}",
179+
"code": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n print \"Hello, World!\" \n}",
180180
"description": "A simple hello world program",
181181
"max_attempts": 3
182182
}'
@@ -186,37 +186,41 @@ curl -X POST http://localhost:8000/compile-and-fix \
186186

187187
```
188188
{
189-
"code": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\" // Missing closing parenthesis\n}",
189+
"code": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n print \"Hello, World!\" \n}",
190190
"description": "A simple hello world program",
191191
"max_attempts": 3
192192
}
193193
```
194194
195195
#### 📤 Response:
196196

197+
The `combined_text` field contains the flat text output of Rust project files that is in the same format as the input `code` field.
198+
197199
```
198200
{
199-
"success": true,
200-
"attempts": [
201-
{
202-
"attempt": 1,
203-
"success": false,
204-
"output": " Compiling hello_world v0.1.0 (/tmp/tmpk_0n65md)\nerror: mismatched closing delimiter: `}`\n --> src/main.rs:2:13\n |\n1 | fn main() {\n | - closing delimiter possibly meant for this\n2 | println!(\"Hello, World!\" // Missing closing parenthesis\n | ^ unclosed delimiter\n3 | }\n | ^ mismatched closing delimiter\n\nerror: could not compile `hello_world` (bin \"hello_world\") due to 1 previous error\n"
205-
},
206-
{
207-
"attempt": 2,
208-
"success": true,
209-
"output": null
210-
}
211-
],
212-
"final_files": {
213-
"Cargo.toml": "[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]",
214-
"src/main.rs": "fn main() {\n println!(\"Hello, World!\");\n}"
215-
},
216-
"build_output": "Build successful",
217-
"run_output": "Hello, World!\n",
218-
"similar_project_used": false,
219-
"combined_text": "[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\");\n}"
201+
"success": true,
202+
"message":"Code fixed and compiled successfully",
203+
"attempts":[
204+
{
205+
"attempt":1,
206+
"success":false,
207+
"output":" Compiling hello_world v0.1.0 (/tmp/tmpbgeg4x_e)\nerror: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `\"Hello, World!\"`\n --> src/main.rs:2:11\n |\n2 | print \"Hello, World!\" \n | ^^^^^^^^^^^^^^^ expected one of 8 possible tokens\n\nerror: could not compile `hello_world` (bin \"hello_world\") due to 1 previous error\n"
208+
},
209+
{
210+
"attempt":2,
211+
"success":true,
212+
"output":null
213+
}
214+
],
215+
"combined_text":"[filename: Cargo.toml]\n[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html\n\n[dependencies]\n\n[filename: src/main.rs]\nfn main() {\n println!(\"Hello, World!\");\n}\n\n[filename: README.md]\n# Hello World\n\nThis is a simple \"Hello, World!\" program in Rust. It prints the message \"Hello, World!\" to the console.\n\nTo run it:\n\n1. Make sure you have Rust installed ([https://www.rust-lang.org/](https://www.rust-lang.org/)).\n2. Save the code as `src/main.rs`.\n3. Run `cargo run` in the terminal from the project directory.",
216+
"files":{
217+
"Cargo.toml":"[package]\nname = \"hello_world\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html\n\n[dependencies]",
218+
"src/main.rs":"fn main() {\n println!(\"Hello, World!\");\n}",
219+
"README.md":"# Hello World\n\nThis is a simple \"Hello, World!\" program in Rust. It prints the message \"Hello, World!\" to the console.\n\nTo run it:\n\n1. Make sure you have Rust installed ([https://www.rust-lang.org/](https://www.rust-lang.org/)).\n2. Save the code as `src/main.rs`.\n3. Run `cargo run` in the terminal from the project directory."
220+
},
221+
"build_output":"Build successful",
222+
"run_output":"Hello, World!\n",
223+
"build_success":true
220224
}
221225
```
222226

0 commit comments

Comments
 (0)