diff --git a/Cargo.lock b/Cargo.lock index 550c4df..38b396f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1366,6 +1366,9 @@ version = "0.1.0" dependencies = [ "async-openai", "quickform", + "serde", + "serde_json", + "tokio", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7e948f2..76ffc54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ members = [ [workspace.dependencies] thiserror = "1.0.68" serde = { version = "1.0.215", features = ["derive"] } -serde_json = "1.0.132" \ No newline at end of file +serde_json = "1.0.132" +tokio = { version = "1.41.1", features = ["full"] } \ No newline at end of file diff --git a/quickform/src/lib.rs b/quickform/src/lib.rs index 75181a7..7881135 100644 --- a/quickform/src/lib.rs +++ b/quickform/src/lib.rs @@ -49,8 +49,8 @@ mod error; mod fs; mod loader; mod operation; -mod state; mod template; +pub mod state; use std::future::Future; use std::path::Path; diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 3e1a17d..db402d3 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -5,4 +5,7 @@ edition = "2021" [dependencies] quickform = { path = "../quickform" } -async-openai = "0.25.0" \ No newline at end of file +async-openai = "0.25.0" +serde = { workspace = true } +serde_json = { workspace = true } +tokio = { workspace = true } \ No newline at end of file diff --git a/tests/src/main.rs b/tests/src/main.rs index cb1d5ae..a3f84e4 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -1,6 +1,3 @@ -use crate::generator::prompts::{entities, SYSTEM_PROMPT}; -use crate::generator::schema; -use crate::generator::{GenerationContext, GenerationError}; use async_openai::{ types::{ ChatCompletionRequestSystemMessageArgs, ChatCompletionRequestUserMessageArgs, @@ -8,20 +5,33 @@ use async_openai::{ }, Client, }; -use boil_codegen::template; +mod schemas; +mod prompts; -#[template("templates/express/src/models/modelv3.ts.jinja")] -pub async fn entities(context: &mut GenerationContext) -> Result { +use prompts::{SYSTEM_PROMPT, entities}; +use quickform::{App, state::Data}; + +#[derive(Debug, serde::Serialize, Clone)] +pub struct GenerationContext { + pub user_prompt: String, +} + +// #[template("templates/express/src/models/modelv3.ts.jinja")] +pub async fn entities(context: Data) -> Vec { let client = Client::new(); + let context = context.clone_inner().await; + let messages = vec![ ChatCompletionRequestSystemMessageArgs::default() .content(SYSTEM_PROMPT) - .build()? + .build() + .unwrap() .into(), ChatCompletionRequestUserMessageArgs::default() .content(entities::PROMPT.replace("{user_prompt}", &context.user_prompt)) - .build()? + .build() + .unwrap() .into(), ]; @@ -29,9 +39,9 @@ pub async fn entities(context: &mut GenerationContext) -> Result Result = serde_json::from_str(&entities)?; + let entities: Vec = serde_json::from_str(&entities).unwrap(); entities } -fn main() { - println!("Hello, world!"); +#[tokio::main] +async fn main() { + let cwd = std::env::current_dir().unwrap(); + let app = App::from_dir(cwd.join("../../templates/express")) + .with_state(GenerationContext { + user_prompt: "I need an e-commerce platform for selling electronics".to_string(), + }) + .render_operation("entities.jinja", entities); + + let output_dir = std::path::Path::new("output"); + app.run(output_dir).await.unwrap(); } diff --git a/tests/src/schemas/mod.rs b/tests/src/schemas/mod.rs index e8c3d6a..713ef76 100644 --- a/tests/src/schemas/mod.rs +++ b/tests/src/schemas/mod.rs @@ -1 +1,2 @@ pub mod entity; +// pub mod context; \ No newline at end of file