{"id":13478198,"url":"https://github.com/retrage/gpt-macro","last_synced_at":"2025-03-27T07:30:52.098Z","repository":{"id":142365076,"uuid":"609860840","full_name":"retrage/gpt-macro","owner":"retrage","description":"ChatGPT powered Rust proc macro that generates code at compile-time.","archived":false,"fork":false,"pushed_at":"2025-03-03T03:31:06.000Z","size":54,"stargazers_count":622,"open_issues_count":0,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-03T04:27:18.700Z","etag":null,"topics":["chatgpt","rust","test"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/retrage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-05T13:14:11.000Z","updated_at":"2025-03-03T03:31:04.000Z","dependencies_parsed_at":"2024-01-14T10:02:28.784Z","dependency_job_id":"dfe0f24c-f6c7-4177-8f1f-2c35a605e1a3","html_url":"https://github.com/retrage/gpt-macro","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retrage%2Fgpt-macro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retrage%2Fgpt-macro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retrage%2Fgpt-macro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retrage%2Fgpt-macro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/retrage","download_url":"https://codeload.github.com/retrage/gpt-macro/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245802268,"owners_count":20674623,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","rust","test"],"created_at":"2024-07-31T16:01:53.832Z","updated_at":"2025-03-27T07:30:51.647Z","avatar_url":"https://github.com/retrage.png","language":"Rust","funding_links":[],"categories":["Rust","Others"],"sub_categories":[],"readme":"# gpt-macro\n\nChatGPT powered Rust proc macro that generates code at compile-time.\n\n## Implemented Macros\n\n* `auto_impl!{}`\n* `#[auto_test(...)]`\n\n## Usage\n\nGet ChatGPT API key and set it to your environment variable `OPENAI_API_KEY` before run.\n\n### `auto_impl!{}`\n\nSyntax:\n\n```rust\nauto_impl! {\n    $STR_LIT\n    $TOKEN_STREAM\n}\n```\n\nwhere `$STR_LIT` is a prompt string literal, and `$TOKEN_STREAM` is target code.\n\nExample:\n\n```rust\nuse gpt_macro::auto_impl;\n\nauto_impl! {\n    \"Return fizz if the number is divisible by 3, buzz if the number is divisible by 5, and fizzbuzz if the number is divisible by both 3 and 5.\"\n    fn fizzbuzz(n: u32) -\u003e String {\n    }\n\n    #[test]\n    fn test_fizzbuzz() {\n        assert_eq!(fizzbuzz(3), \"fizz\");\n        assert_eq!(fizzbuzz(5), \"buzz\");\n        assert_eq!(fizzbuzz(15), \"fizzbuzz\");\n        assert_eq!(fizzbuzz(1), \"1\");\n    }\n}\n```\n\nAs you can see, the `fizzbuzz()` implementation is incomplete, so the build fails without `auto_impl!{}`. The macro parses given prompt and target code, and asks ChatGPT to fill the code when expanding the macro. It replaces the target with code extracted from ChatGPT response. Then Rust compiler continues compiling the code.\n\nResponse Example:\n\n```rust\nfn fizzbuzz(n: u32) -\u003e String {\n    if n % 3 == 0 \u0026\u0026 n % 5 == 0 {\n        return String::from(\"fizzbuzz\");\n    } else if n % 3 == 0 {\n        return String::from(\"fizz\");\n    } else if n % 5 == 0 {\n        return String::from(\"buzz\");\n    } else {\n        return n.to_string();\n    }\n}\n\n#[test]\nfn test_fizzbuzz() {\n    assert_eq!(fizzbuzz(3), \"fizz\");\n    assert_eq!(fizzbuzz(5), \"buzz\");\n    assert_eq!(fizzbuzz(15), \"fizzbuzz\");\n    assert_eq!(fizzbuzz(1), \"1\");\n}\n```\n\n### `#[auto_test]`\n\nSee this example:\n\n```rust\nuse gpt_macro::auto_test;\n\n#[auto_test(test_valid, test_div_by_zero)]\nfn div_u32(a: u32, b: u32) -\u003e u32 {\n    if b == 0 {\n        panic!(\"attempt to divide by zero\");\n    }\n    a / b\n}\n```\n\n## License\n\ngpt-macro is released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fretrage%2Fgpt-macro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fretrage%2Fgpt-macro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fretrage%2Fgpt-macro/lists"}