pub struct ChatCompletionStreamRequest {Show 18 fields
pub model: String,
pub messages: Vec<ChatCompletionMessage>,
pub temperature: Option<f64>,
pub top_p: Option<f64>,
pub n: Option<i64>,
pub response_format: Option<Value>,
pub stop: Option<Vec<String>>,
pub max_tokens: Option<i64>,
pub presence_penalty: Option<f64>,
pub frequency_penalty: Option<f64>,
pub logit_bias: Option<HashMap<String, i32>>,
pub user: Option<String>,
pub seed: Option<i64>,
pub tools: Option<Vec<Tool>>,
pub parallel_tool_calls: Option<bool>,
pub tool_choice: Option<ToolChoiceType>,
pub reasoning: Option<Reasoning>,
pub transforms: Option<Vec<String>>,
}
Fields§
§model: String
§messages: Vec<ChatCompletionMessage>
§temperature: Option<f64>
§top_p: Option<f64>
§n: Option<i64>
§response_format: Option<Value>
§stop: Option<Vec<String>>
§max_tokens: Option<i64>
§presence_penalty: Option<f64>
§frequency_penalty: Option<f64>
§logit_bias: Option<HashMap<String, i32>>
§user: Option<String>
§seed: Option<i64>
§tools: Option<Vec<Tool>>
§parallel_tool_calls: Option<bool>
§tool_choice: Option<ToolChoiceType>
§reasoning: Option<Reasoning>
§transforms: Option<Vec<String>>
Optional list of transforms to apply to the chat completion request.
Transforms allow modifying the request before it’s sent to the API, enabling features like prompt rewriting, content filtering, or other preprocessing steps. When None, no transforms are applied.
Implementations§
Source§impl ChatCompletionStreamRequest
impl ChatCompletionStreamRequest
Sourcepub fn new(model: String, messages: Vec<ChatCompletionMessage>) -> Self
pub fn new(model: String, messages: Vec<ChatCompletionMessage>) -> Self
Examples found in repository?
examples/chat_completion_stream.rs (lines 15-24)
11async fn main() -> Result<(), Box<dyn std::error::Error>> {
12 let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
13 let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
14
15 let req = ChatCompletionStreamRequest::new(
16 GPT4_O_MINI.to_string(),
17 vec![chat_completion::ChatCompletionMessage {
18 role: chat_completion::MessageRole::user,
19 content: chat_completion::Content::Text(String::from("What is bitcoin?")),
20 name: None,
21 tool_calls: None,
22 tool_call_id: None,
23 }],
24 );
25
26 let mut result = client.chat_completion_stream(req).await?;
27 while let Some(response) = result.next().await {
28 match response.clone() {
29 ChatCompletionStreamResponse::ToolCall(toolcalls) => {
30 println!("Tool Call: {:?}", toolcalls);
31 }
32 ChatCompletionStreamResponse::Content(content) => {
33 println!("Content: {:?}", content);
34 }
35 ChatCompletionStreamResponse::Done => {
36 println!("Done");
37 }
38 }
39 }
40
41 Ok(())
42}
Source§impl ChatCompletionStreamRequest
impl ChatCompletionStreamRequest
pub fn temperature(self, temperature: f64) -> Self
pub fn top_p(self, top_p: f64) -> Self
pub fn n(self, n: i64) -> Self
pub fn response_format(self, response_format: Value) -> Self
pub fn stop(self, stop: Vec<String>) -> Self
pub fn max_tokens(self, max_tokens: i64) -> Self
pub fn presence_penalty(self, presence_penalty: f64) -> Self
pub fn frequency_penalty(self, frequency_penalty: f64) -> Self
pub fn logit_bias(self, logit_bias: HashMap<String, i32>) -> Self
pub fn user(self, user: String) -> Self
pub fn seed(self, seed: i64) -> Self
pub fn tools(self, tools: Vec<Tool>) -> Self
pub fn parallel_tool_calls(self, parallel_tool_calls: bool) -> Self
pub fn tool_choice(self, tool_choice: ToolChoiceType) -> Self
pub fn reasoning(self, reasoning: Reasoning) -> Self
pub fn transforms(self, transforms: Vec<String>) -> Self
Trait Implementations§
Source§impl Clone for ChatCompletionStreamRequest
impl Clone for ChatCompletionStreamRequest
Source§fn clone(&self) -> ChatCompletionStreamRequest
fn clone(&self) -> ChatCompletionStreamRequest
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 ChatCompletionStreamRequest
impl Debug for ChatCompletionStreamRequest
Source§impl<'de> Deserialize<'de> for ChatCompletionStreamRequest
impl<'de> Deserialize<'de> for ChatCompletionStreamRequest
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ChatCompletionStreamRequest
impl RefUnwindSafe for ChatCompletionStreamRequest
impl Send for ChatCompletionStreamRequest
impl Sync for ChatCompletionStreamRequest
impl Unpin for ChatCompletionStreamRequest
impl UnwindSafe for ChatCompletionStreamRequest
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more