api_openai 0.3.0

OpenAI's API for accessing large language models (LLMs).
Documentation
//! Conversation items and content management for the Realtime API.

/// Define a private namespace for conversation-related items.
mod private
{
  // Serde imports
  use serde::{ Serialize, Deserialize };

  /// Represents an item within the Realtime conversation context (message, function call, etc.).
  /// Used when creating/retrieving items via client/server events.
  ///
  /// # Used By
  /// - `RealtimeClientEventConversationItemCreate`
  /// - `RealtimeServerEventConversationItemCreated`
  /// - `RealtimeServerEventConversationItemRetrieved`
  /// - `RealtimeServerEventResponseOutputItemAdded`
  /// - `RealtimeServerEventResponseOutputItemDone`
  #[ derive( Debug, Serialize, Deserialize, Clone, PartialEq, former::Former ) ] // Added Serialize
  pub struct RealtimeConversationItem
  {
    /// The unique ID of the item. Optional when creating, generated by server if omitted.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub id : Option< String >,
    /// The type of the item (`message`, `function_call`, `function_call_output`).
    pub r#type : String,
    /// Identifier for the API object type, always `realtime.item`.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub object : Option< String >,
    /// The status of the item (`completed`, `incomplete`). Used for consistency with server events.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub status : Option< String >,
    /// The role of the message sender (`user`, `assistant`, `system`), only for `message` items.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub role : Option< String >,
    /// The content of the message (text, audio), only for `message` items.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub content : Option< Vec< RealtimeConversationItemContent > >, // Represents array of InputContent or OutputContent parts
    /// The ID of the function call, for `function_call` and `function_call_output` items.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub call_id : Option< String >,
    /// The name of the function being called, for `function_call` items.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub name : Option< String >,
    /// The arguments of the function call (JSON string), for `function_call` items.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub arguments : Option< String >,
    /// The output of the function call (JSON string), for `function_call_output` items.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub output : Option< String >,
  }

  /// Represents an item content within the Realtime conversation item
  /// Used when creating/retrieving items via client/server events.
  ///
  /// # Used By
  /// - `RealtimeClientEventConversationItem`
  #[ derive( Debug, Serialize, Deserialize, Clone, PartialEq, former::Former ) ] // Added Serialize
  pub struct RealtimeConversationItemContent
  {
    /// The content type (`input_text`, `input_audio`, `item_reference`, `text`).
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub r#type : Option< String >,
    /// The text content, used for `input_text` and `text` content types.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub text : Option< String >,
    /// ID of a previous conversation item to reference
    /// (for `item_reference` content types in `response.create` events).
    /// These can reference both client and server created items.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub id : Option< String >,
    /// Base64-encoded audio bytes, used for `input_audio` content type.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub audio : Option< String >,
    /// The transcript of the audio, used for `input_audio` content type.
    #[ serde( skip_serializing_if = "Option::is_none" ) ]
    pub transcript : Option< String >,
  }

  /// Represents a reference to an existing conversation item or a new item definition.
  /// Used in `RealtimeResponseCreateParams` to build context.
  ///
  /// # Used By
  /// - `RealtimeResponseCreateParams`
  #[ derive( Debug, Serialize, Deserialize, Clone, PartialEq ) ] // Added Serialize
  #[ serde( untagged ) ] // Can be either a reference or a full item definition
  pub enum RealtimeConversationItemWithReference
  {
    /// A reference to an existing item by ID.
    Reference
    {
      /// The ID of the item to reference.
      id : String,
      /// The type of item to reference, must be "`item_reference`".
      r#type : String
    },
    /// A full definition of a new item to include in the context.
    Item( RealtimeConversationItem ),
  }

  /// Basic information about a Realtime conversation.
  ///
  /// # Used By
  /// - `RealtimeServerEventConversationCreated`
  #[ derive( Debug, Deserialize, Clone, PartialEq ) ]
  pub struct RealtimeConversationInfo
  {
    /// The unique ID of the conversation.
    pub id : String,
    /// The object type, must be `realtime.conversation`.
    pub object : String,
  }

} // end mod private

crate ::mod_interface!
{
  exposed use
  {
    RealtimeConversationItem,
    RealtimeConversationItemContent,
    RealtimeConversationItemWithReference,
    RealtimeConversationInfo,
  };
}