File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -204,9 +204,14 @@ impl<C: Config> Client<C> {
204204 path : & str ,
205205 request_options : & RequestOptions ,
206206 ) -> reqwest:: RequestBuilder {
207- let mut request_builder = self
208- . http_client
209- . request ( method, self . config . url ( path) )
207+ let mut request_builder = if let Some ( path) = request_options. path ( ) {
208+ self . http_client
209+ . request ( method, self . config . url ( path. as_str ( ) ) )
210+ } else {
211+ self . http_client . request ( method, self . config . url ( path) )
212+ } ;
213+
214+ request_builder = request_builder
210215 . query ( & self . config . query ( ) )
211216 . headers ( self . config . headers ( ) ) ;
212217
Original file line number Diff line number Diff line change @@ -8,16 +8,28 @@ use crate::{config::OPENAI_API_BASE, error::OpenAIError};
88pub struct RequestOptions {
99 query : Option < Vec < ( String , String ) > > ,
1010 headers : Option < HeaderMap > ,
11+ path : Option < String > ,
1112}
1213
1314impl RequestOptions {
1415 pub ( crate ) fn new ( ) -> Self {
1516 Self {
1617 query : None ,
1718 headers : None ,
19+ path : None ,
1820 }
1921 }
2022
23+ pub ( crate ) fn with_path ( & mut self , path : & str ) -> Result < ( ) , OpenAIError > {
24+ if path. is_empty ( ) {
25+ return Err ( OpenAIError :: InvalidArgument (
26+ "Path cannot be empty" . to_string ( ) ,
27+ ) ) ;
28+ }
29+ self . path = Some ( path. to_string ( ) ) ;
30+ Ok ( ( ) )
31+ }
32+
2133 pub ( crate ) fn with_headers ( & mut self , headers : HeaderMap ) {
2234 // merge with existing headers or update with new headers
2335 if let Some ( existing_headers) = & mut self . headers {
@@ -81,4 +93,8 @@ impl RequestOptions {
8193 pub ( crate ) fn headers ( & self ) -> Option < & HeaderMap > {
8294 self . headers . as_ref ( )
8395 }
96+
97+ pub ( crate ) fn path ( & self ) -> Option < & String > {
98+ self . path . as_ref ( )
99+ }
84100}
Original file line number Diff line number Diff line change @@ -53,4 +53,10 @@ pub trait RequestOptionsBuilder: Sized {
5353 self . options_mut ( ) . with_query ( query) ?;
5454 Ok ( self )
5555 }
56+
57+ /// Add a path to RequestOptions
58+ fn path < P : Into < String > > ( mut self , path : P ) -> Result < Self , OpenAIError > {
59+ self . options_mut ( ) . with_path ( path. into ( ) . as_str ( ) ) ?;
60+ Ok ( self )
61+ }
5662}
You can’t perform that action at this time.
0 commit comments