diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 152a146..455a8d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,13 +37,34 @@ jobs: - uses: actions/checkout@v4 with: submodules: true + - name: Install nasm + if: runner.os == 'Windows' + run: choco install nasm -y + - name: Verify NASM Installation + if: runner.os == 'Windows' + shell: powershell + run: | + $env:Path += ";C:\Program Files\NASM" + [System.Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Process) + Write-Host "Checking NASM version..." + nasm -v - name: Install stable uses: dtolnay/rust-toolchain@stable - - name: cargo generate-lockfile + - name: cargo generate-lockfile if: hashFiles('Cargo.lock') == '' - run: cargo generate-lockfile - - name: cargo test - run: cargo test --locked --all-features --all-targets + run: | + cargo generate-lockfile + - name: cargo test - Windows + if: runner.os == 'Windows' + run: | + $env:Path += ";C:\Program Files\NASM" + [System.Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Process) + cargo test --locked --all-features --all-targets + - name: cargo test - Mac + if: runner.os == 'macOS' + run: | + cargo test --locked --all-features --all-targets + coverage: runs-on: ubuntu-latest name: ubuntu / stable / coverage @@ -67,3 +88,33 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true + alpine-test: + runs-on: ubuntu-latest + name: alpine / stable + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Set up Docker container + run: | + docker pull alpine:latest + docker run -d --name alpine-container -v ${{ github.workspace }}:/workspace -w /workspace alpine:latest tail -f /dev/null + - name: Install dependencies + run: | + docker exec alpine-container sh -c " + apk update && + apk add --no-cache musl-dev gcc rust cargo rustup && + rustup-init -y && + source /root/.cargo/env && + rustup toolchain install stable-x86_64-unknown-linux-musl && + rustup default stable-x86_64-unknown-linux-musl + " + + - name: cargo generate-lockfile + if: hashFiles('Cargo.lock') == '' + run: docker exec alpine-container sh -c "source /root/.cargo/env && cargo generate-lockfile" + - name: cargo test --locked + run: docker exec alpine-container sh -c "source /root/.cargo/env && cargo test --locked --all-features --all-targets" + - name: Clean up Docker container + if: always() + run: docker rm -f alpine-container diff --git a/Cargo.toml b/Cargo.toml index 27c5375..1224a9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chat-gpt-lib-rs" -version = "0.4.1" +version = "0.5.0" edition = "2021" description = "A Rust library for interacting with OpenAI's ChatGPT API, providing a simple interface to make API requests and handle responses." license = "Apache-2.0" @@ -18,7 +18,8 @@ path = "examples/cli-chat-example.rs" [dependencies] env_logger = "0.11" log = "0.4" -reqwest = { version = "0.12", features = ["json"] } +reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] } +rustls = "0.23" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tokio = { version = "1.37", features = ["full"] } @@ -27,3 +28,4 @@ tokio = { version = "1.37", features = ["full"] } dotenvy = "0.15" console = "0.15" indicatif = "0.17" + diff --git a/README.md b/README.md index 920d810..eb4b8a0 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ A Rust library for interacting with OpenAI's ChatGPT API. This library simplifie * An example CLI chat application that demonstrates library usage * An token estimation functionality +Utilizes Rustls for the TLS layer, eliminating the need for OpenSSL and enabling seamless native execution on Linux with musl. + ## Installation Add the following line to your 'Cargo.toml' file under the '[dependencies]' section: ```toml diff --git a/examples/cli-chat-example.rs b/examples/cli-chat-example.rs index c41dcc2..70dc3e9 100644 --- a/examples/cli-chat-example.rs +++ b/examples/cli-chat-example.rs @@ -55,7 +55,9 @@ async fn main() -> Result<(), Box> { // Initialize the message history with a system message let mut messages = vec![Message { role: Role::System, - content: "Behave and talk like the computer from star trek.".to_string(), + content: + "Be a helpfull pair programmer, who want to show solutions and examples in code blocks" + .to_string(), }]; // Check if any command line arguments are provided diff --git a/src/client.rs b/src/client.rs index ad3ef60..7590da2 100644 --- a/src/client.rs +++ b/src/client.rs @@ -122,10 +122,15 @@ impl ChatGPTClient { /// * `api_key` - The API key for the ChatGPT API. /// * `base_url` - The base URL for the ChatGPT API. pub fn new(api_key: &str, base_url: &str) -> Self { + let client = Client::builder() + .use_rustls_tls() + .build() + .expect("New client"); + Self { base_url: base_url.to_string(), api_key: api_key.to_string(), - client: Client::new(), + client, } }