Skip to content

Inject reqwest::Client and reuse instance #169

Open
@mrcrgl

Description

@mrcrgl

Describe the feature or improvement you're requesting

The client is created for every request. This means, that the client will not reuse tcp connections for example. In many cases, a default client is sufficient, but I would offer to make the client configurable by the user. The timeout and proxy settings then, will be injected and not set up in the openai client.

let client = Client::builder();

#[cfg(feature = "rustls")]
let client = client.use_rustls_tls();

let client = if let Some(timeout) = self.timeout {
    client.timeout(std::time::Duration::from_secs(timeout))
} else {
    client
};

let client = if let Some(proxy) = &self.proxy {
    client.proxy(reqwest::Proxy::all(proxy).unwrap())
} else {
    client
};

let client = client.build().unwrap();

Additional context

I would implement it if this request is fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions