Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagomed committed Dec 21, 2024
1 parent e496fee commit f3926cc
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ members = [
[workspace.dependencies]
thiserror = "1.0.68"
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.132"
serde_json = "1.0.132"
tokio = { version = "1.41.1", features = ["full"] }
2 changes: 1 addition & 1 deletion quickform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ edition = "2021"

[dependencies]
quickform = { path = "../quickform" }
async-openai = "0.25.0"
async-openai = "0.25.0"
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
47 changes: 33 additions & 14 deletions tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
use crate::generator::prompts::{entities, SYSTEM_PROMPT};
use crate::generator::schema;
use crate::generator::{GenerationContext, GenerationError};
use async_openai::{
types::{
ChatCompletionRequestSystemMessageArgs, ChatCompletionRequestUserMessageArgs,
CreateChatCompletionRequestArgs, ResponseFormat,
},
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<String, GenerationError> {
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<GenerationContext>) -> Vec<schemas::entity::Entity> {
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(),
];

let request = CreateChatCompletionRequestArgs::default()
.model("gpt-4o-mini")
.response_format(ResponseFormat::JsonObject)
.messages(messages)
.build()?;

let response = client.chat().create(request).await?;
.build()
.unwrap();
let response = client.chat().create(request).await.unwrap();
let entities = response.choices[0]
.message
.content
Expand All @@ -40,10 +50,19 @@ pub async fn entities(context: &mut GenerationContext) -> Result<String, Generat

println!("Entities: {}", entities);

let entities: Vec<schema::entity::Entity> = serde_json::from_str(&entities)?;
let entities: Vec<schemas::entity::Entity> = 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();
}
1 change: 1 addition & 0 deletions tests/src/schemas/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod entity;
// pub mod context;

0 comments on commit f3926cc

Please sign in to comment.