diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0b1f850 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +on: + release: + types: [published] + +jobs: + publish: + name: Publish to crates.io + + runs-on: ubuntu-latest + needs: release-please + if: needs.release-please.outputs.created + + environment: crates.io + + steps: + - uses: actions/checkout@v3 + - uses: swatinem/rust-cache@v2 + + - name: Publish + # https://doc.rust-lang.org/cargo/reference/config.html?highlight=CARGO_REGISTRY_TOKEN#credentials + run: > + cargo workspaces publish + --verbose + --allow-branch * + --token ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a073a99..e18a51d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,6 +2,9 @@ name: Cargo Build & Test on: pull_request: + push: + branches: + - main env: CARGO_TERM_COLOR: always @@ -14,17 +17,15 @@ jobs: matrix: toolchain: - stable - # - beta - # - nightly + - beta + - nightly crate: - # - instruct-macros + - instruct-macros - instructor steps: - uses: actions/checkout@v4 - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 - with: - path: ${{ matrix.crate }} - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} - run: cd ${{ matrix.crate }} && cargo build --verbose @@ -35,18 +36,16 @@ jobs: strategy: matrix: toolchain: - # - stable - # - beta + - stable + - beta - nightly crate: - # - instruct-macros + - instruct-macros - instructor steps: - uses: actions/checkout@v4 - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 - with: - path: ${{ matrix.crate }} - name: Install cargo-nextest run: cargo install cargo-nextest --locked - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..dfb4848 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["instruct-macros-types", "instruct-macros", "instructor"] diff --git a/docs/examples/getting-started/Cargo.toml b/docs/examples/getting-started/Cargo.toml deleted file mode 100644 index cf9a7c4..0000000 --- a/docs/examples/getting-started/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "getting-started" -version = "0.1.0" -edition = "2021" - -[dependencies] -instructor-ai = { path = "../../instructor" } -instruct-macros = { path = "../../instruct-macros" } -openai-api-rs = "4.1.0" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -instruct-macros-types = { path = "../../instruct-macros-types" } diff --git a/docs/examples/getting-started/src/main.rs b/docs/examples/getting-started/src/main.rs deleted file mode 100644 index b448578..0000000 --- a/docs/examples/getting-started/src/main.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::env; - -use instruct_macros::{validate, InstructMacro}; -use instruct_macros_types::{ParameterInfo, StructInfo}; -use instructor_ai::from_openai; -use openai_api_rs::v1::{ - api::Client, - chat_completion::{self, ChatCompletionRequest}, - common::GPT3_5_TURBO, -}; -use serde::{Deserialize, Serialize}; - -fn main() { - let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string()); - let instructor_client = from_openai(client); - - #[derive(InstructMacro, Debug, Serialize, Deserialize)] - // This represents a single user - struct UserInfo { - // This represents the name of the user - #[validate(custom = "validate_uppercase")] - name: String, - // This represents the age of the user - age: u8, - } - - #[validate] - fn validate_uppercase(s: &String) -> Result { - if s.chars().any(|c| c.is_lowercase()) { - return Err(format!( - "Name '{}' should be entirely in uppercase. Examples: 'TIMOTHY', 'JANE SMITH'", - s - )); - } - Ok(s.to_uppercase()) - } - - let req = ChatCompletionRequest::new( - GPT3_5_TURBO.to_string(), - vec![chat_completion::ChatCompletionMessage { - role: chat_completion::MessageRole::user, - content: chat_completion::Content::Text(String::from( - "John Doe is a 30 year old software engineer", - )), - name: None, - }], - ); - - let result = instructor_client - .chat_completion::(req, 3) - .unwrap(); - - println!("{}", result.name); // JOHN DOE - println!("{}", result.age); // 30 -} diff --git a/instruct-macros-types/Cargo.toml b/instruct-macros-types/Cargo.toml index c39cb51..4116c4d 100644 --- a/instruct-macros-types/Cargo.toml +++ b/instruct-macros-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "instruct-macros-types" -version = "0.1.2" +version = "0.1.6" edition = "2021" authors = ["Ivan Leo "] description = "Instructor Macro Types are a collection of simple types that we export to work with the instruct-macros crate" diff --git a/instruct-macros/Cargo.toml b/instruct-macros/Cargo.toml index abe119d..1d47d30 100644 --- a/instruct-macros/Cargo.toml +++ b/instruct-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "instruct-macros" -version = "0.1.1" +version = "0.1.6" edition = "2018" authors = ["Ivan Leo "] description = "instruct-macros are a collection of simple macros that we're using in Instructor-AI to generate json schema from Serde Objects" diff --git a/instructor/Cargo.toml b/instructor/Cargo.toml index 1d29e8b..023854e 100644 --- a/instructor/Cargo.toml +++ b/instructor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "instructor-ai" -version = "0.1.0" +version = "0.1.6" edition = "2021" authors = ["Ivan Leo "] description = "instructor-ai is a simple crate that allows for users to do validated structured outputs"