openai-tools 1.1.0

Tools for OpenAI API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
//! OpenAI Conversations API Request Module
//!
//! This module provides the functionality to interact with the OpenAI Conversations API.
//! The Conversations API allows you to create and manage long-running conversations
//! with the Responses API.
//!
//! # Key Features
//!
//! - **Create Conversations**: Create new conversations with optional metadata and items
//! - **Retrieve Conversations**: Get details of a specific conversation
//! - **Update Conversations**: Modify conversation metadata
//! - **Delete Conversations**: Remove conversations
//! - **Manage Items**: Add and list conversation items
//!
//! # Quick Start
//!
//! ```rust,no_run
//! use openai_tools::conversations::request::Conversations;
//! use openai_tools::conversations::response::InputItem;
//! use std::collections::HashMap;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     let conversations = Conversations::new()?;
//!
//!     // Create a new conversation
//!     let mut metadata = HashMap::new();
//!     metadata.insert("topic".to_string(), "demo".to_string());
//!
//!     let conversation = conversations.create(Some(metadata), None).await?;
//!     println!("Created conversation: {}", conversation.id);
//!
//!     // Add items to the conversation
//!     let items = vec![InputItem::user_message("Hello!")];
//!     let added_items = conversations.create_items(&conversation.id, items).await?;
//!
//!     Ok(())
//! }
//! ```

use crate::common::auth::AuthProvider;
use crate::common::client::create_http_client;
use crate::common::errors::{ErrorResponse, OpenAIToolError, Result};
use crate::conversations::response::{Conversation, ConversationItemListResponse, ConversationListResponse, DeleteConversationResponse, InputItem};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::Duration;

/// Default API path for Conversations
const CONVERSATIONS_PATH: &str = "conversations";

/// Specifies additional data to include in conversation item responses.
///
/// This enum defines various types of additional information that can be
/// included when listing conversation items.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum ConversationInclude {
    /// Include web search call action sources
    #[serde(rename = "web_search_call.action.sources")]
    WebSearchCallSources,
    /// Include code interpreter call outputs
    #[serde(rename = "code_interpreter_call.outputs")]
    CodeInterpreterCallOutputs,
    /// Include file search call results
    #[serde(rename = "file_search_call.results")]
    FileSearchCallResults,
    /// Include image URLs from input messages
    #[serde(rename = "message.input_image.image_url")]
    MessageInputImageUrl,
    /// Include encrypted reasoning content
    #[serde(rename = "reasoning.encrypted_content")]
    ReasoningEncryptedContent,
}

impl ConversationInclude {
    /// Returns the string representation for API requests.
    pub fn as_str(&self) -> &'static str {
        match self {
            ConversationInclude::WebSearchCallSources => "web_search_call.action.sources",
            ConversationInclude::CodeInterpreterCallOutputs => "code_interpreter_call.outputs",
            ConversationInclude::FileSearchCallResults => "file_search_call.results",
            ConversationInclude::MessageInputImageUrl => "message.input_image.image_url",
            ConversationInclude::ReasoningEncryptedContent => "reasoning.encrypted_content",
        }
    }
}

/// Request body for creating a conversation.
#[derive(Debug, Clone, Serialize)]
struct CreateConversationRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    metadata: Option<HashMap<String, String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    items: Option<Vec<InputItem>>,
}

/// Request body for updating a conversation.
#[derive(Debug, Clone, Serialize)]
struct UpdateConversationRequest {
    metadata: HashMap<String, String>,
}

/// Request body for creating conversation items.
#[derive(Debug, Clone, Serialize)]
struct CreateItemsRequest {
    items: Vec<InputItem>,
}

/// Client for interacting with the OpenAI Conversations API.
///
/// This struct provides methods to create, retrieve, update, delete conversations,
/// and manage conversation items. Use [`Conversations::new()`] to create a new instance.
///
/// # Example
///
/// ```rust,no_run
/// use openai_tools::conversations::request::Conversations;
/// use std::collections::HashMap;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
///     let conversations = Conversations::new()?;
///
///     // Create a conversation with metadata
///     let mut metadata = HashMap::new();
///     metadata.insert("user_id".to_string(), "user123".to_string());
///
///     let conv = conversations.create(Some(metadata), None).await?;
///     println!("Created: {}", conv.id);
///
///     // Retrieve the conversation
///     let retrieved = conversations.retrieve(&conv.id).await?;
///     println!("Retrieved: {:?}", retrieved.metadata);
///
///     Ok(())
/// }
/// ```
pub struct Conversations {
    /// Authentication provider (OpenAI or Azure)
    auth: AuthProvider,
    /// Optional request timeout duration
    timeout: Option<Duration>,
}

impl Conversations {
    /// Creates a new Conversations client for OpenAI API.
    ///
    /// Initializes the client by loading the OpenAI API key from
    /// the environment variable `OPENAI_API_KEY`. Supports `.env` file loading
    /// via dotenvy.
    ///
    /// # Returns
    ///
    /// * `Ok(Conversations)` - A new Conversations client ready for use
    /// * `Err(OpenAIToolError)` - If the API key is not found in the environment
    ///
    /// # Example
    ///
    /// ```rust,no_run
    /// use openai_tools::conversations::request::Conversations;
    ///
    /// let conversations = Conversations::new().expect("API key should be set");
    /// ```
    pub fn new() -> Result<Self> {
        let auth = AuthProvider::openai_from_env()?;
        Ok(Self { auth, timeout: None })
    }

    /// Creates a new Conversations client with a custom authentication provider
    pub fn with_auth(auth: AuthProvider) -> Self {
        Self { auth, timeout: None }
    }

    /// Creates a new Conversations client for Azure OpenAI API
    pub fn azure() -> Result<Self> {
        let auth = AuthProvider::azure_from_env()?;
        Ok(Self { auth, timeout: None })
    }

    /// Creates a new Conversations client by auto-detecting the provider
    pub fn detect_provider() -> Result<Self> {
        let auth = AuthProvider::from_env()?;
        Ok(Self { auth, timeout: None })
    }

    /// Creates a new Conversations client with URL-based provider detection
    pub fn with_url<S: Into<String>>(base_url: S, api_key: S) -> Self {
        let auth = AuthProvider::from_url_with_key(base_url, api_key);
        Self { auth, timeout: None }
    }

    /// Creates a new Conversations client from URL using environment variables
    pub fn from_url<S: Into<String>>(url: S) -> Result<Self> {
        let auth = AuthProvider::from_url(url)?;
        Ok(Self { auth, timeout: None })
    }

    /// Returns the authentication provider
    pub fn auth(&self) -> &AuthProvider {
        &self.auth
    }

    /// Sets the request timeout duration.
    ///
    /// # Arguments
    ///
    /// * `timeout` - The maximum time to wait for a response
    ///
    /// # Returns
    ///
    /// A mutable reference to self for method chaining
    pub fn timeout(&mut self, timeout: Duration) -> &mut Self {
        self.timeout = Some(timeout);
        self
    }

    /// Creates the HTTP client with default headers.
    fn create_client(&self) -> Result<(request::Client, request::header::HeaderMap)> {
        let client = create_http_client(self.timeout)?;
        let mut headers = request::header::HeaderMap::new();
        self.auth.apply_headers(&mut headers)?;
        headers.insert("Content-Type", request::header::HeaderValue::from_static("application/json"));
        headers.insert("User-Agent", request::header::HeaderValue::from_static("openai-tools-rust"));
        Ok((client, headers))
    }

    /// Handles API error responses.
    fn handle_error(status: request::StatusCode, content: &str) -> OpenAIToolError {
        if let Ok(error_resp) = serde_json::from_str::<ErrorResponse>(content) {
            OpenAIToolError::Error(error_resp.error.message.unwrap_or_default())
        } else {
            OpenAIToolError::Error(format!("API error ({}): {}", status, content))
        }
    }

    /// Creates a new conversation.
    ///
    /// You can optionally provide metadata and initial items to include
    /// in the conversation.
    ///
    /// # Arguments
    ///
    /// * `metadata` - Optional key-value pairs for storing additional information
    /// * `items` - Optional initial items to add to the conversation (up to 20 items)
    ///
    /// # Returns
    ///
    /// * `Ok(Conversation)` - The created conversation object
    /// * `Err(OpenAIToolError)` - If the request fails
    ///
    /// # Example
    ///
    /// ```rust,no_run
    /// use openai_tools::conversations::request::Conversations;
    /// use openai_tools::conversations::response::InputItem;
    /// use std::collections::HashMap;
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let conversations = Conversations::new()?;
    ///
    ///     // Create with metadata and initial message
    ///     let mut metadata = HashMap::new();
    ///     metadata.insert("topic".to_string(), "greeting".to_string());
    ///
    ///     let items = vec![InputItem::user_message("Hello!")];
    ///
    ///     let conv = conversations.create(Some(metadata), Some(items)).await?;
    ///     println!("Created conversation: {}", conv.id);
    ///     Ok(())
    /// }
    /// ```
    pub async fn create(&self, metadata: Option<HashMap<String, String>>, items: Option<Vec<InputItem>>) -> Result<Conversation> {
        let (client, headers) = self.create_client()?;

        let request_body = CreateConversationRequest { metadata, items };
        let body = serde_json::to_string(&request_body)?;

        let url = self.auth.endpoint(CONVERSATIONS_PATH);
        let response = client.post(&url).headers(headers).body(body).send().await.map_err(OpenAIToolError::RequestError)?;

        let status = response.status();
        let content = response.text().await.map_err(OpenAIToolError::RequestError)?;

        if cfg!(test) {
            tracing::info!("Response content: {}", content);
        }

        if !status.is_success() {
            return Err(Self::handle_error(status, &content));
        }

        serde_json::from_str::<Conversation>(&content).map_err(OpenAIToolError::SerdeJsonError)
    }

    /// Retrieves a specific conversation.
    ///
    /// # Arguments
    ///
    /// * `conversation_id` - The ID of the conversation to retrieve
    ///
    /// # Returns
    ///
    /// * `Ok(Conversation)` - The conversation object
    /// * `Err(OpenAIToolError)` - If the conversation is not found or the request fails
    ///
    /// # Example
    ///
    /// ```rust,no_run
    /// use openai_tools::conversations::request::Conversations;
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let conversations = Conversations::new()?;
    ///     let conv = conversations.retrieve("conv_abc123").await?;
    ///
    ///     println!("Conversation: {}", conv.id);
    ///     println!("Created at: {}", conv.created_at);
    ///     Ok(())
    /// }
    /// ```
    pub async fn retrieve(&self, conversation_id: &str) -> Result<Conversation> {
        let (client, headers) = self.create_client()?;
        let url = format!("{}/{}", self.auth.endpoint(CONVERSATIONS_PATH), conversation_id);

        let response = client.get(&url).headers(headers).send().await.map_err(OpenAIToolError::RequestError)?;

        let status = response.status();
        let content = response.text().await.map_err(OpenAIToolError::RequestError)?;

        if cfg!(test) {
            tracing::info!("Response content: {}", content);
        }

        if !status.is_success() {
            return Err(Self::handle_error(status, &content));
        }

        serde_json::from_str::<Conversation>(&content).map_err(OpenAIToolError::SerdeJsonError)
    }

    /// Updates a conversation's metadata.
    ///
    /// # Arguments
    ///
    /// * `conversation_id` - The ID of the conversation to update
    /// * `metadata` - The new metadata to set
    ///
    /// # Returns
    ///
    /// * `Ok(Conversation)` - The updated conversation object
    /// * `Err(OpenAIToolError)` - If the request fails
    ///
    /// # Example
    ///
    /// ```rust,no_run
    /// use openai_tools::conversations::request::Conversations;
    /// use std::collections::HashMap;
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let conversations = Conversations::new()?;
    ///
    ///     let mut metadata = HashMap::new();
    ///     metadata.insert("topic".to_string(), "updated-topic".to_string());
    ///
    ///     let conv = conversations.update("conv_abc123", metadata).await?;
    ///     println!("Updated: {:?}", conv.metadata);
    ///     Ok(())
    /// }
    /// ```
    pub async fn update(&self, conversation_id: &str, metadata: HashMap<String, String>) -> Result<Conversation> {
        let (client, headers) = self.create_client()?;
        let url = format!("{}/{}", self.auth.endpoint(CONVERSATIONS_PATH), conversation_id);

        let request_body = UpdateConversationRequest { metadata };
        let body = serde_json::to_string(&request_body)?;

        let response = client.post(&url).headers(headers).body(body).send().await.map_err(OpenAIToolError::RequestError)?;

        let status = response.status();
        let content = response.text().await.map_err(OpenAIToolError::RequestError)?;

        if cfg!(test) {
            tracing::info!("Response content: {}", content);
        }

        if !status.is_success() {
            return Err(Self::handle_error(status, &content));
        }

        serde_json::from_str::<Conversation>(&content).map_err(OpenAIToolError::SerdeJsonError)
    }

    /// Deletes a conversation.
    ///
    /// # Arguments
    ///
    /// * `conversation_id` - The ID of the conversation to delete
    ///
    /// # Returns
    ///
    /// * `Ok(DeleteConversationResponse)` - Confirmation of deletion
    /// * `Err(OpenAIToolError)` - If the request fails
    ///
    /// # Example
    ///
    /// ```rust,no_run
    /// use openai_tools::conversations::request::Conversations;
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let conversations = Conversations::new()?;
    ///     let result = conversations.delete("conv_abc123").await?;
    ///
    ///     if result.deleted {
    ///         println!("Conversation {} was deleted", result.id);
    ///     }
    ///     Ok(())
    /// }
    /// ```
    pub async fn delete(&self, conversation_id: &str) -> Result<DeleteConversationResponse> {
        let (client, headers) = self.create_client()?;
        let url = format!("{}/{}", self.auth.endpoint(CONVERSATIONS_PATH), conversation_id);

        let response = client.delete(&url).headers(headers).send().await.map_err(OpenAIToolError::RequestError)?;

        let status = response.status();
        let content = response.text().await.map_err(OpenAIToolError::RequestError)?;

        if cfg!(test) {
            tracing::info!("Response content: {}", content);
        }

        if !status.is_success() {
            return Err(Self::handle_error(status, &content));
        }

        serde_json::from_str::<DeleteConversationResponse>(&content).map_err(OpenAIToolError::SerdeJsonError)
    }

    /// Creates items in a conversation.
    ///
    /// You can add up to 20 items at a time.
    ///
    /// # Arguments
    ///
    /// * `conversation_id` - The ID of the conversation
    /// * `items` - The items to add to the conversation
    ///
    /// # Returns
    ///
    /// * `Ok(ConversationItemListResponse)` - The created items
    /// * `Err(OpenAIToolError)` - If the request fails
    ///
    /// # Example
    ///
    /// ```rust,no_run
    /// use openai_tools::conversations::request::Conversations;
    /// use openai_tools::conversations::response::InputItem;
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let conversations = Conversations::new()?;
    ///
    ///     let items = vec![
    ///         InputItem::user_message("What is the weather like?"),
    ///         InputItem::assistant_message("I'd be happy to help with weather information!"),
    ///     ];
    ///
    ///     let result = conversations.create_items("conv_abc123", items).await?;
    ///     println!("Added {} items", result.data.len());
    ///     Ok(())
    /// }
    /// ```
    pub async fn create_items(&self, conversation_id: &str, items: Vec<InputItem>) -> Result<ConversationItemListResponse> {
        let (client, headers) = self.create_client()?;
        let url = format!("{}/{}/items", self.auth.endpoint(CONVERSATIONS_PATH), conversation_id);

        let request_body = CreateItemsRequest { items };
        let body = serde_json::to_string(&request_body)?;

        let response = client.post(&url).headers(headers).body(body).send().await.map_err(OpenAIToolError::RequestError)?;

        let status = response.status();
        let content = response.text().await.map_err(OpenAIToolError::RequestError)?;

        if cfg!(test) {
            tracing::info!("Response content: {}", content);
        }

        if !status.is_success() {
            return Err(Self::handle_error(status, &content));
        }

        serde_json::from_str::<ConversationItemListResponse>(&content).map_err(OpenAIToolError::SerdeJsonError)
    }

    /// Lists items in a conversation.
    ///
    /// # Arguments
    ///
    /// * `conversation_id` - The ID of the conversation
    /// * `limit` - Maximum number of items to return (1-100, default 20)
    /// * `after` - Cursor for pagination (item ID to start after)
    /// * `order` - Sort order ("asc" or "desc", default "desc")
    /// * `include` - Additional data to include in the response
    ///
    /// # Returns
    ///
    /// * `Ok(ConversationItemListResponse)` - The list of items
    /// * `Err(OpenAIToolError)` - If the request fails
    ///
    /// # Example
    ///
    /// ```rust,no_run
    /// use openai_tools::conversations::request::{Conversations, ConversationInclude};
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let conversations = Conversations::new()?;
    ///
    ///     // List items with pagination
    ///     let items = conversations.list_items(
    ///         "conv_abc123",
    ///         Some(20),
    ///         None,
    ///         Some("desc"),
    ///         None,
    ///     ).await?;
    ///
    ///     for item in &items.data {
    ///         println!("Item: {} ({})", item.id, item.item_type);
    ///     }
    ///     Ok(())
    /// }
    /// ```
    pub async fn list_items(
        &self,
        conversation_id: &str,
        limit: Option<u32>,
        after: Option<&str>,
        order: Option<&str>,
        include: Option<Vec<ConversationInclude>>,
    ) -> Result<ConversationItemListResponse> {
        let (client, headers) = self.create_client()?;

        // Build query parameters
        let mut params = Vec::new();
        if let Some(l) = limit {
            params.push(format!("limit={}", l));
        }
        if let Some(a) = after {
            params.push(format!("after={}", a));
        }
        if let Some(o) = order {
            params.push(format!("order={}", o));
        }
        if let Some(inc) = include {
            for i in inc {
                params.push(format!("include[]={}", i.as_str()));
            }
        }

        let url = if params.is_empty() {
            format!("{}/{}/items", self.auth.endpoint(CONVERSATIONS_PATH), conversation_id)
        } else {
            format!("{}/{}/items?{}", self.auth.endpoint(CONVERSATIONS_PATH), conversation_id, params.join("&"))
        };

        let response = client.get(&url).headers(headers).send().await.map_err(OpenAIToolError::RequestError)?;

        let status = response.status();
        let content = response.text().await.map_err(OpenAIToolError::RequestError)?;

        if cfg!(test) {
            tracing::info!("Response content: {}", content);
        }

        if !status.is_success() {
            return Err(Self::handle_error(status, &content));
        }

        serde_json::from_str::<ConversationItemListResponse>(&content).map_err(OpenAIToolError::SerdeJsonError)
    }

    /// Lists all conversations (if available).
    ///
    /// Note: This endpoint may not be available in all API versions.
    ///
    /// # Arguments
    ///
    /// * `limit` - Maximum number of conversations to return (1-100, default 20)
    /// * `after` - Cursor for pagination (conversation ID to start after)
    ///
    /// # Returns
    ///
    /// * `Ok(ConversationListResponse)` - The list of conversations
    /// * `Err(OpenAIToolError)` - If the request fails
    ///
    /// # Example
    ///
    /// ```rust,no_run
    /// use openai_tools::conversations::request::Conversations;
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let conversations = Conversations::new()?;
    ///
    ///     let response = conversations.list(Some(10), None).await?;
    ///     for conv in &response.data {
    ///         println!("Conversation: {} (created: {})", conv.id, conv.created_at);
    ///     }
    ///     Ok(())
    /// }
    /// ```
    pub async fn list(&self, limit: Option<u32>, after: Option<&str>) -> Result<ConversationListResponse> {
        let (client, headers) = self.create_client()?;

        // Build query parameters
        let mut params = Vec::new();
        if let Some(l) = limit {
            params.push(format!("limit={}", l));
        }
        if let Some(a) = after {
            params.push(format!("after={}", a));
        }

        let url = if params.is_empty() {
            self.auth.endpoint(CONVERSATIONS_PATH)
        } else {
            format!("{}?{}", self.auth.endpoint(CONVERSATIONS_PATH), params.join("&"))
        };

        let response = client.get(&url).headers(headers).send().await.map_err(OpenAIToolError::RequestError)?;

        let status = response.status();
        let content = response.text().await.map_err(OpenAIToolError::RequestError)?;

        if cfg!(test) {
            tracing::info!("Response content: {}", content);
        }

        if !status.is_success() {
            return Err(Self::handle_error(status, &content));
        }

        serde_json::from_str::<ConversationListResponse>(&content).map_err(OpenAIToolError::SerdeJsonError)
    }
}