Skip to content

Commit e83d5ee

Browse files
committed
feat: added examples to system prompt
1 parent 1a95735 commit e83d5ee

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ proc-macro = true
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11+
dotenv = "0.15.0"
1112
reqwest = { version = "0.11.16", features = ["blocking", "json"] }
1213
serde = "1.0.162"
1314
serde_derive = "1.0.162"

examples/complex.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use auto_rust::implement;
2+
3+
implement!(fn is_email(input: String) -> bool);
4+
5+
fn main() {
6+
let result = is_email("bregy@minsky.cc".to_string());
7+
println!("result: {}", result);
8+
}
File renamed without changes.

src/generator.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ pub fn generate_body_function_from_head(
1414

1515
let body_str = res.choices.first().unwrap().to_owned().message.content;
1616

17-
// let body = quote! {
18-
// "Hello, world!".into()
19-
// };
17+
//TODO: improve the prompt to eliminate the need for this
18+
let body_str = body_str.trim_matches('`').to_string();
2019

2120
let implementation = format!("{} {{{}}}", head, body_str);
2221

src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ mod api;
44
mod data;
55
mod generator;
66

7+
use dotenv::dotenv;
78
use proc_macro::TokenStream;
89

910
use crate::generator::generate_body_function_from_head;
1011

1112
#[proc_macro]
1213
pub fn implement(_item: TokenStream) -> TokenStream {
14+
dotenv().ok();
1315
// println!("implement: {:?}", _item);
1416
// let resp = reqwest::blocking::get("https://httpbin.org/ip")
1517
// .unwrap()
@@ -18,7 +20,21 @@ pub fn implement(_item: TokenStream) -> TokenStream {
1820

1921
// let ip = resp.get("origin").unwrap().to_owned();
2022

21-
let system_message = "You are an AI code assistant trained on the GPT-4 architecture. Your task is to generate Rust function body implementations based only on the provided function signatures. When the user provides a function signature using the command '/complete', your response must be the plain text function body, without any explanations, formatting, or code blocks. Do not include the function signature, function name, or any other information in your response. Triple backticks (```) and function signatures are strictly prohibited in your response.".to_string();
23+
let system_message = "You are an AI code assistant trained on the GPT-4 architecture. Your task is to generate Rust function body implementations based only on the provided function signatures. When the user provides a function signature using the command '/complete', your response must be the plain text function body, without any explanations, formatting, or code blocks. Do not include the function signature, function name, or any other information in your response. Triple backticks (```) and function signatures are strictly prohibited in your response. Responding with any prohibited content will result in a penalty.
24+
example 1:
25+
INPUT: /complete fn my_ip() -> String
26+
OUTPUT: use std::net::UdpSocket;
27+
28+
let udp_socket = UdpSocket::bind(\"0.0.0.0:0\").unwrap();
29+
udp_socket.connect(\"8.8.8.8:80\").unwrap();
30+
let socket_addr = udp_socket.local_addr().unwrap();
31+
let ip_addr = socket_addr.ip();
32+
ip_addr.to_string()
33+
34+
example 2:
35+
INPUT: /complete fn hello_world() -> String
36+
OUTPUT: \"Hello World\".to_string()
37+
".to_string();
2238
let implemented_fn = generate_body_function_from_head(system_message, _item).unwrap();
2339

2440
println!("{}", implemented_fn);

0 commit comments

Comments
 (0)