chore: make proxy in simple-chat configure (#134)

and remove some prints and some useless codes

Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
This commit is contained in:
jokemanfire 2025-04-20 11:00:47 +08:00 • committed by GitHub
commit b6fabc8836
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,14 +16,17 @@ pub struct OpenAIClient {
}
impl OpenAIClient {
pub fn new(api_key: String, url: Option<String>) -> Self {
pub fn new(api_key: String, url: Option<String>, proxy: Option<bool>) -> Self {
let base_url = url.unwrap_or("https://api.openai.com/v1/chat/completions".to_string());
// create http client without proxy
let client = HttpClient::builder()
.no_proxy()
.build()
.unwrap_or_else(|_| HttpClient::new());
let proxy = proxy.unwrap_or(false);
let client = if proxy {
HttpClient::new()
} else {
HttpClient::builder()
.no_proxy()
.build()
.unwrap_or_else(|_| HttpClient::new())
};
Self {
api_key,
@ -41,12 +44,6 @@ impl OpenAIClient {
#[async_trait]
impl ChatClient for OpenAIClient {
async fn complete(&self, request: CompletionRequest) -> Result<CompletionResponse> {
println!("sending request to {}", self.base_url);
println!("using api key: {}", self.api_key);
let request_json = serde_json::to_string(&request)?;
println!("request content: {}", request_json);
// no proxy
let response = self
.client
.post(&self.base_url)