Skip to content

Commit b517c5b

Browse files
committed
only initialize request options vector when needed
1 parent 83eb409 commit b517c5b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

async-openai/src/request_options.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use crate::{config::OPENAI_API_BASE, error::OpenAIError};
66

77
#[derive(Clone, Debug, Default)]
88
pub struct RequestOptions {
9-
query: Vec<(String, String)>,
9+
query: Option<Vec<(String, String)>>,
1010
headers: Option<HeaderMap>,
1111
}
1212

1313
impl RequestOptions {
1414
pub(crate) fn new() -> Self {
1515
Self {
16-
query: Vec::new(),
16+
query: None,
1717
headers: None,
1818
}
1919
}
@@ -66,15 +66,16 @@ impl RequestOptions {
6666
}
6767

6868
// Extract query pairs from the URL and append to our vec
69+
let query = self.query.get_or_insert_with(Vec::new);
6970
for (key, value) in url.query_pairs() {
70-
self.query.push((key.to_string(), value.to_string()));
71+
query.push((key.to_string(), value.to_string()));
7172
}
7273

7374
Ok(())
7475
}
7576

7677
pub(crate) fn query(&self) -> &[(String, String)] {
77-
&self.query
78+
self.query.as_deref().unwrap_or(&[])
7879
}
7980

8081
pub(crate) fn headers(&self) -> Option<&HeaderMap> {

0 commit comments

Comments
 (0)