Skip to content

Commit

Permalink
chore: updated project structure for monorepo development
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudbridgeuy committed Mar 15, 2023
1 parent 3e0ce4e commit 7319514
Show file tree
Hide file tree
Showing 18 changed files with 222 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
xtask = "run --package xtask --bin xtask --"

[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }
50 changes: 48 additions & 2 deletions Cargo.lock

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

48 changes: 13 additions & 35 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
[package]
name = "gpt"
description = "A CLI tool to generate and pretty-print code snippets from GPT3"
repository = "https://github.com/guzmonne/gpt"
license = "MIT"
version = "0.1.0"
edition = "2021"
create-type = "bin"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bat = "0.22.1"
copypasta-ext = "0.4.4"
reqwest = { version = "0.11.14", features = ["blocking"] }
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"
env_logger = "0.10.0"
log = "0.4.17"
chrono = "0.4.23"
clap = { version = "4.1.8", features = ["derive"] }
[workspace]
members = ["xtask/", "lib/*", "crates/*"]

[[bin]]
name = "a"
path = "src/main.rs"

[[bin]]
name = "v2"
path = "v2/main.rs"

[lib]
name = "a"
path = "src/lib.rs"
[workspace.package]
edition = "2021"
license = "MIT"
authors = ["Guzmán Monné"]

[features]
clipboard = []
[profile.dev]
# Disabling debug info speeds up builds.
debug = 0

default = ["clipboard"]
[profile.release]
incremental = true
# Set this to 1 or 2 to get more useful backtraces in debugger.
debug = 0
32 changes: 32 additions & 0 deletions crates/a/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "gpt"
version = "0.0.0"
homepage = "https://github.com/cloudbridgeuy/a"
description = "A CLI tool to interact with ChatGPT as a Software Engineer"
autobins = false

authors.workspace = true
edition.workspace = true
license.workspace = true

[[bin]]
name = "a"
path = "src/main.rs"

[lib]
name = "a"
path = "src/lib.rs"

[dependencies]
bat = "0.22.1"
copypasta-ext = "0.4.4"
reqwest = { version = "0.11.14", features = ["blocking"] }
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"
env_logger = "0.10.0"
log = "0.4.17"
chrono = "0.4.23"

[features]
clipboard = []
default = ["clipboard"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions crates/b/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "b"
version = "0.0.0"
homepage = "https://github.com/cloudbridgeuy/a"
description = "A CLI tool to interact with ChatGPT as a Software Engineer"
autobins = false

authors.workspace = true
edition.workspace = true
license.workspace = true

[[bin]]
name = "b"
path = "src/main.rs"

[lib]
name = "b"
path = "src/lib.rs"

[dependencies]
clap = { version = "4.1.8", features = ["derive"] }
1 change: 1 addition & 0 deletions crates/b/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

26 changes: 19 additions & 7 deletions v2/main.rs → crates/b/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,35 @@ struct Cli {
#[command(subcommand)]
command: Option<Commands>,

/// Name of the chat session.
#[arg(short, long)]
session: Option<String>,

/// URL endpoint of the OpenAI ChatGPT API.
#[arg(short, long, default_value_t=String::from("https://api.openai.com/v1/chat/completions"))]
url: String,

/// ChatGPT model to use.
#[arg(short, long, default_value_t=String::from("gpt-3.5-turbo"))]
model: String,

/// Temperature value of ChatGPT response.
#[arg(long, default_value_t=0.0, value_parser = in_range)]
temperature: f32,

/// Top-p value of ChatGPT response.
#[arg(long, default_value_t=0.8, value_parser = in_range)]
top_p: f32,

/// Presence penalty value of ChatGPT response.
#[arg(long, default_value_t=0.0, value_parser = in_range)]
presence_penalty: f32,

/// Frequencey penalty value of ChatGPT response.
#[arg(long, default_value_t=0.0, value_parser = in_range)]
frequency_penalty: f32,

/// Prompt that should be send to ChatGPT.
prompt: Vec<String>,
}

Expand All @@ -54,7 +62,7 @@ enum Commands {
}
}

#[derive(Debug, Subcommand)]
#[derive(Debug, Subcommand, Clone)]
enum NewCommand {
/// Create a new chat session
Chat,
Expand All @@ -65,26 +73,30 @@ fn main() {

match cli.command {
Some(Commands::Whisper) => {
println!("Whisper to OpenAI");
handle_whisper(&cli);
}
Some(Commands::New { command }) => {
handle_new_command(&command);
Some(Commands::New { ref command }) => {
handle_new(&cli, &command);
}
None => {
handle_chat_session(&cli);
handle_chat(&cli);
}
}
}

fn handle_new_command(command: &NewCommand) {
fn handle_whisper(_cli: &Cli) {
println!("Whisper to OpenAI");
}

fn handle_new(_cli: &Cli, command: &NewCommand) {
match command {
NewCommand::Chat => {
println!("Create a new chat session");
}
}
}

fn handle_chat_session(cli: &Cli) {
fn handle_chat(cli: &Cli) {
let _url = &cli.url;
let _model = &cli.model;
let _temperature = &cli.temperature;
Expand Down
5 changes: 5 additions & 0 deletions lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# /Lib

> Crates in this directory are published to crates.io and **must obey** semver.
_We currently don't have anything published. Yet._
10 changes: 10 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "xtask"
version = "0.1.0"
publish = false
license = "MIT"
edition = "2021"

[dependencies]
clap = { version = "4.1.8", features = ["derive"] } # a simple to use, efficient, and full-featured Command Line Argument Parser
duct = "0.13.6" # a library for running child processes
3 changes: 3 additions & 0 deletions xtask/src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn script(name: &str) {
println!("Hello, {}!", name);
}
26 changes: 26 additions & 0 deletions xtask/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use clap::{Parser, Subcommand};

#[derive(Debug, Parser)]
#[command(name="xtasks")]
#[command(about="Run project tasks using rust instead of scripts")]
pub struct App {
#[command(subcommand)]
pub command: Option<Commands>,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
/// Runs one of the project binaries
Run {
/// Name of the binary to run.
#[arg(short, long)]
name: String,
},
/// Builds one of the project binaries
Build {
/// Name of the binary to run.
#[arg(short, long)]
name: String,
}
}

31 changes: 31 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! See <https://github.com/matklad/cargo-xtask/>
//!
//! This binary defines various auxiliary build commands, which are not
//! expressible with just `cargo`.
//!
//! The binary is integrated into the `cargo` command line by using an
//! alias in `.cargo/config`.

mod cli;
mod run;
mod build;

use clap::Parser;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = cli::App::parse();

match &cli.command {
Some(cli::Commands::Run { name }) => {
run::script(name)?;
return Ok(());
}
Some(cli::Commands::Build { name }) => {
build::script(name);
return Ok(());
}
None => {
panic!("No command specified");
}
}
}
8 changes: 8 additions & 0 deletions xtask/src/run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::error::Error;
use duct::cmd;

pub fn script(name: &str) -> Result<(), Box<dyn Error>>{
cmd!("cargo", "run", "--bin", name).run()?;

Ok(())
}

0 comments on commit 7319514

Please sign in to comment.