mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-22 15:15:34 +00:00
added debugging
This commit is contained in:
@ -14,6 +14,9 @@ default = ["default-tls"]
|
|||||||
rustls = ["reqwest/rustls-tls", "tokio-tungstenite/rustls-tls-webpki-roots"]
|
rustls = ["reqwest/rustls-tls", "tokio-tungstenite/rustls-tls-webpki-roots"]
|
||||||
default-tls = ["reqwest/default-tls", "tokio-tungstenite/native-tls"]
|
default-tls = ["reqwest/default-tls", "tokio-tungstenite/native-tls"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tracing = "0.1.41"
|
||||||
|
|
||||||
[dependencies.reqwest]
|
[dependencies.reqwest]
|
||||||
version = "0.12"
|
version = "0.12"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
@ -62,6 +62,7 @@ pub struct OpenAIClientBuilder {
|
|||||||
headers: Option<HeaderMap>,
|
headers: Option<HeaderMap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct OpenAIClient {
|
pub struct OpenAIClient {
|
||||||
api_endpoint: String,
|
api_endpoint: String,
|
||||||
api_key: String,
|
api_key: String,
|
||||||
@ -179,9 +180,20 @@ impl OpenAIClient {
|
|||||||
path: &str,
|
path: &str,
|
||||||
body: &impl serde::ser::Serialize,
|
body: &impl serde::ser::Serialize,
|
||||||
) -> Result<T, APIError> {
|
) -> Result<T, APIError> {
|
||||||
let request = self.build_request(Method::POST, path).await;
|
let request_builder = self.build_request(Method::POST, path).await;
|
||||||
let request = request.json(body);
|
let request_builder = request_builder.json(body);
|
||||||
let response = request.send().await?;
|
|
||||||
|
// 💡 Convert to request to inspect it before sending
|
||||||
|
let client = request_builder
|
||||||
|
.try_clone()
|
||||||
|
.expect("Cannot clone request builder")
|
||||||
|
.build()
|
||||||
|
.expect("Failed to build request");
|
||||||
|
|
||||||
|
// 🔍 Debug log: URL, headers, and optionally body
|
||||||
|
tracing::debug!("🔵 URL: {}", client.url());
|
||||||
|
tracing::debug!("🟢 Headers:\n{:#?}", client.headers());
|
||||||
|
let response = request_builder.send().await?;
|
||||||
self.handle_response(response).await
|
self.handle_response(response).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user