Skip to content

Commit fc180ec

Browse files
committed
fix: resolve compilation errors in ChatWithTrait
- Make ClientWithTrait fields pub(crate) for internal access - Fix error type conversions - Use InvalidArgument for serialization errors
1 parent c8fd213 commit fc180ec

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

async-openai/src/chat_with_trait.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::{
44
config::Config,
55
error::{ApiError, OpenAIError},
6-
http_client::{HttpClient, HttpResponse},
6+
http_client::HttpResponse,
77
types::{
88
CreateChatCompletionRequest, CreateChatCompletionResponse,
99
CreateChatCompletionStreamResponse,
@@ -35,7 +35,7 @@ impl<'c, C: Config> ChatWithTrait<'c, C> {
3535

3636
// Serialize request body
3737
let body = serde_json::to_vec(&request)
38-
.map_err(|e| OpenAIError::JSONSerialize(e))?;
38+
.map_err(|e| OpenAIError::InvalidArgument(format!("Failed to serialize request: {}", e)))?;
3939

4040
// Prepare headers
4141
let mut headers = self.client.config.headers();
@@ -117,12 +117,10 @@ impl<'c, C: Config> ChatWithTrait<'c, C> {
117117
}
118118
}
119119
Err(e) => {
120-
// Network error, retry
121-
Err(backoff::Error::transient(OpenAIError::Reqwest(
122-
reqwest::Error::from(std::io::Error::new(
123-
std::io::ErrorKind::Other,
124-
e.message
125-
))
120+
// Network error, retry
121+
// Convert to a string-based error since we can't create reqwest::Error directly
122+
Err(backoff::Error::transient(OpenAIError::InvalidArgument(
123+
format!("HTTP client error: {}", e.message)
126124
)))
127125
}
128126
}

async-openai/src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,9 @@ where
570570

571571
/// Client with HttpClient trait support
572572
pub struct ClientWithTrait<C: Config> {
573-
http_client: BoxedHttpClient,
574-
config: C,
575-
backoff: backoff::ExponentialBackoff,
573+
pub(crate) http_client: BoxedHttpClient,
574+
pub(crate) config: C,
575+
pub(crate) backoff: backoff::ExponentialBackoff,
576576
}
577577

578578
impl<C: Config> ClientWithTrait<C> {

0 commit comments

Comments
 (0)