pub struct OpenAIChatModel { /* private fields */ }Available on crate feature
openai only.Expand description
OpenAI Chat Completions model.
Implementations§
Source§impl OpenAIChatModel
impl OpenAIChatModel
Sourcepub fn new(
model_name: impl Into<String>,
api_key: impl Into<String>,
) -> OpenAIChatModel
pub fn new( model_name: impl Into<String>, api_key: impl Into<String>, ) -> OpenAIChatModel
Create a new OpenAI chat model.
Sourcepub fn from_env(
model_name: impl Into<String>,
) -> Result<OpenAIChatModel, ModelError>
pub fn from_env( model_name: impl Into<String>, ) -> Result<OpenAIChatModel, ModelError>
Create from environment variable OPENAI_API_KEY.
Sourcepub fn with_base_url(self, url: impl Into<String>) -> OpenAIChatModel
pub fn with_base_url(self, url: impl Into<String>) -> OpenAIChatModel
Set the base URL.
Sourcepub fn with_organization(self, org: impl Into<String>) -> OpenAIChatModel
pub fn with_organization(self, org: impl Into<String>) -> OpenAIChatModel
Set the organization ID.
Sourcepub fn with_project(self, project: impl Into<String>) -> OpenAIChatModel
pub fn with_project(self, project: impl Into<String>) -> OpenAIChatModel
Set the project ID.
Sourcepub fn with_client(self, client: Client) -> OpenAIChatModel
pub fn with_client(self, client: Client) -> OpenAIChatModel
Set a custom HTTP client.
Sourcepub fn with_timeout(self, timeout: Duration) -> OpenAIChatModel
pub fn with_timeout(self, timeout: Duration) -> OpenAIChatModel
Set the default timeout.
Sourcepub fn with_profile(self, profile: ModelProfile) -> OpenAIChatModel
pub fn with_profile(self, profile: ModelProfile) -> OpenAIChatModel
Set a custom profile.
Sourcepub fn convert_response_to_message(&self, resp: &ModelResponse) -> ChatMessage
pub fn convert_response_to_message(&self, resp: &ModelResponse) -> ChatMessage
Convert a ModelResponse to an assistant ChatMessage.
Sourcepub fn add_response_to_messages(
&self,
messages: &mut Vec<ChatMessage>,
response: &ModelResponse,
)
pub fn add_response_to_messages( &self, messages: &mut Vec<ChatMessage>, response: &ModelResponse, )
Add an assistant response to messages (for multi-turn conversations).
Trait Implementations§
Source§impl Clone for OpenAIChatModel
impl Clone for OpenAIChatModel
Source§fn clone(&self) -> OpenAIChatModel
fn clone(&self) -> OpenAIChatModel
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OpenAIChatModel
impl Debug for OpenAIChatModel
Source§impl Model for OpenAIChatModel
impl Model for OpenAIChatModel
Source§fn profile(&self) -> &ModelProfile
fn profile(&self) -> &ModelProfile
Get the model profile (capabilities, schema transforms).
Source§fn request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
messages: &'life1 [ModelRequest],
settings: &'life2 ModelSettings,
params: &'life3 ModelRequestParameters,
) -> Pin<Box<dyn Future<Output = Result<ModelResponse, ModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
OpenAIChatModel: 'async_trait,
fn request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
messages: &'life1 [ModelRequest],
settings: &'life2 ModelSettings,
params: &'life3 ModelRequestParameters,
) -> Pin<Box<dyn Future<Output = Result<ModelResponse, ModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
OpenAIChatModel: 'async_trait,
Make a request to the model.
Source§fn request_stream<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
messages: &'life1 [ModelRequest],
settings: &'life2 ModelSettings,
params: &'life3 ModelRequestParameters,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ModelResponseStreamEvent, ModelError>> + Send>>, ModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
OpenAIChatModel: 'async_trait,
fn request_stream<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
messages: &'life1 [ModelRequest],
settings: &'life2 ModelSettings,
params: &'life3 ModelRequestParameters,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ModelResponseStreamEvent, ModelError>> + Send>>, ModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
OpenAIChatModel: 'async_trait,
Make a streaming request to the model. Read more
Source§fn identifier(&self) -> String
fn identifier(&self) -> String
Get the full model identifier.
Source§fn count_tokens<'life0, 'life1, 'async_trait>(
&'life0 self,
_messages: &'life1 [ModelRequest],
) -> Pin<Box<dyn Future<Output = Result<u64, ModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn count_tokens<'life0, 'life1, 'async_trait>(
&'life0 self,
_messages: &'life1 [ModelRequest],
) -> Pin<Box<dyn Future<Output = Result<u64, ModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Count tokens for messages (if supported). Read more
Source§fn supports(&self, capability: ModelCapability) -> bool
fn supports(&self, capability: ModelCapability) -> bool
Check if the model supports a specific capability.
Auto Trait Implementations§
impl Freeze for OpenAIChatModel
impl !RefUnwindSafe for OpenAIChatModel
impl Send for OpenAIChatModel
impl Sync for OpenAIChatModel
impl Unpin for OpenAIChatModel
impl !UnwindSafe for OpenAIChatModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more