Skip to content

ci: Add homebrew release trigger to release.yml #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
ref: refs/tags/${{ inputs.publish-tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger homebrew release
run: gh workflow run bump.yml --repo zurawiki/homebrew-brews

upload-binary:
name: ${{ matrix.target }}
Expand Down
134 changes: 12 additions & 122 deletions Cargo.lock

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

15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ dirs = "5.0.0"
lazy_static = "1.4.0"
log = "0.4.17"
regex = "1.7.3"
reqwest = { version = "0.11.16", features = ["json", "gzip", "brotli", "rustls-tls"] }
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0.158"
serde_json = "1.0.95"
Expand All @@ -42,5 +41,19 @@ toml = "0.7.3"
toml_edit = "0.19.8"
which = "4.4.0"


[dependencies.reqwest]
version = "0.11.16"
features = [
"brotli",
"gzip",
"json",
"multipart",
"rustls-tls",
"stream",
"socks"
]
default-features = false

[dev-dependencies]
async-std = "1.12.0"
27 changes: 18 additions & 9 deletions src/llms/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::{anyhow, bail, Ok, Result};

use async_trait::async_trait;

use reqwest::{tls, Proxy};
use tiktoken_rs::{get_chat_completion_max_tokens, get_completion_max_tokens};

use crate::settings::OpenAISettings;
Expand Down Expand Up @@ -33,29 +34,37 @@ impl OpenAIClient {
bail!("No OpenAI model configured. Please choose a valid model to use.");
}

let mut client = Client::new().with_api_key(&api_key);
let mut openai_client = Client::new().with_api_key(&api_key);

let api_base = settings.api_base.unwrap_or_default();
if !api_base.is_empty() {
client = client.with_api_base(&api_base);
let mut http_client = reqwest::Client::builder().gzip(true).brotli(true);
if api_base.is_empty() {
http_client = http_client
.http2_prior_knowledge()
.min_tls_version(tls::Version::TLS_1_2);
} else {
openai_client = openai_client.with_api_base(&api_base);
}

// Optimized HTTP client

if let Some(proxy) = settings.proxy {
if !proxy.is_empty() {
let http_client = reqwest::Client::builder()
.proxy(reqwest::Proxy::all(proxy)?)
.build()?;
client = client.with_http_client(http_client);
http_client = http_client.proxy(Proxy::all(proxy)?);
}
}
openai_client = openai_client.with_http_client(http_client.build()?);

if settings.retries.unwrap_or_default() > 0 {
let backoff = backoff::ExponentialBackoffBuilder::new()
.with_max_elapsed_time(Some(std::time::Duration::from_secs(60)))
.build();
client = client.with_backoff(backoff);
openai_client = openai_client.with_backoff(backoff);
}
Ok(Self { model, client })
Ok(Self {
model,
client: openai_client,
})
}

pub(crate) fn should_use_chat_completion(model: &str) -> bool {
Expand Down