Skip to content

Commit 699bcfb

Browse files
committed
Fix errors due to cherrypicks
1 parent 3ed96d2 commit 699bcfb

File tree

6 files changed

+32
-56
lines changed

6 files changed

+32
-56
lines changed

async-openai/src/types/impls.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::fmt::Display;
33
use bytes::Bytes;
44

55
use super::{
6-
responses::{EasyInputContent, Role as ResponsesRole},
76
AddUploadPartRequest, AudioInput, AudioResponseFormat, ChatCompletionFunctionCall,
87
ChatCompletionFunctions, ChatCompletionNamedToolChoice, ChatCompletionRequestAssistantMessage,
98
ChatCompletionRequestAssistantMessageContent, ChatCompletionRequestDeveloperMessage,
@@ -19,7 +18,7 @@ use super::{
1918
EmbeddingInput, FileExpiresAfterAnchor, FileInput, FilePurpose, FunctionName, ImageInput,
2019
ImageModel, ImageResponseFormat, ImageSize, ImageUrl, ModerationInput, Prompt, Role, Stop,
2120
TimestampGranularity, VideoSize,
22-
responses::{CodeInterpreterContainer, Input, InputContent},
21+
responses::EasyInputContent,
2322
};
2423
use crate::traits::AsyncTryFrom;
2524
use crate::{error::OpenAIError, types::InputSource, util::create_file_part};
@@ -974,12 +973,6 @@ impl Default for EasyInputContent {
974973
}
975974
}
976975

977-
impl Default for ResponsesRole {
978-
fn default() -> Self {
979-
Self::User
980-
}
981-
}
982-
983976
impl From<String> for EasyInputContent {
984977
fn from(value: String) -> Self {
985978
Self::Text(value)

async-openai/src/types/realtime/client_event.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use serde::{Deserialize, Serialize};
2-
use super::{item::Item, session_resource::SessionResource};
32

43
use crate::types::realtime::{RealtimeConversationItem, RealtimeResponseCreateParams, Session};
54

@@ -247,22 +246,6 @@ impl From<&RealtimeClientEvent> for String {
247246
}
248247
}
249248

250-
impl From<RealtimeClientEvent> for Message {
251-
fn from(value: RealtimeClientEvent) -> Self {
252-
Message::Text(String::from(&value).into())
253-
}
254-
}
255-
256-
macro_rules! message_from_event {
257-
($from_typ:ty, $evt_typ:ty) => {
258-
impl From<$from_typ> for Message {
259-
fn from(value: $from_typ) -> Self {
260-
Self::from(<$evt_typ>::from(value))
261-
}
262-
}
263-
};
264-
}
265-
266249
macro_rules! event_from {
267250
($from_typ:ty, $evt_typ:ty, $variant:ident) => {
268251
impl From<$from_typ> for $evt_typ {
@@ -283,32 +266,32 @@ event_from!(
283266
RealtimeClientEvent,
284267
InputAudioBufferAppend
285268
);
286-
event_struct_to_variant!(
269+
event_from!(
287270
RealtimeClientEventInputAudioBufferCommit,
288271
RealtimeClientEvent,
289272
InputAudioBufferCommit
290273
);
291-
event_struct_to_variant!(
274+
event_from!(
292275
RealtimeClientEventInputAudioBufferClear,
293276
RealtimeClientEvent,
294277
InputAudioBufferClear
295278
);
296-
event_struct_to_variant!(
279+
event_from!(
297280
RealtimeClientEventConversationItemCreate,
298281
RealtimeClientEvent,
299282
ConversationItemCreate
300283
);
301-
event_struct_to_variant!(
284+
event_from!(
302285
RealtimeClientEventConversationItemTruncate,
303286
RealtimeClientEvent,
304287
ConversationItemTruncate
305288
);
306-
event_struct_to_variant!(
289+
event_from!(
307290
RealtimeClientEventConversationItemDelete,
308291
RealtimeClientEvent,
309292
ConversationItemDelete
310293
);
311-
event_struct_to_variant!(
294+
event_from!(
312295
RealtimeClientEventConversationItemRetrieve,
313296
RealtimeClientEvent,
314297
ConversationItemRetrieve
@@ -318,7 +301,7 @@ event_from!(
318301
RealtimeClientEvent,
319302
ResponseCreate
320303
);
321-
event_struct_to_variant!(
304+
event_from!(
322305
RealtimeClientEventResponseCancel,
323306
RealtimeClientEvent,
324307
ResponseCancel
@@ -329,7 +312,7 @@ event_from!(
329312
OutputAudioBufferClear
330313
);
331314

332-
impl<T: Into<ClientEvent>> ToText for T {
315+
impl<T: Into<RealtimeClientEvent>> ToText for T {
333316
// blanket impl for all client event structs
334317
fn to_text(self) -> String {
335318
(&self.into()).into()

async-openai/src/types/realtime/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use serde::{Deserialize, Serialize};
22

33
use crate::types::{
4-
responses::{Prompt, ToolChoiceFunction, ToolChoiceMCP, ToolChoiceOptions},
54
MCPTool,
5+
responses::{Prompt, ToolChoiceFunction, ToolChoiceMCP, ToolChoiceOptions},
66
};
77

88
#[derive(Debug, Default, Serialize, Deserialize, Clone)]

async-openai/src/types/responses/response.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ use serde::{Deserialize, Serialize};
99
use std::collections::HashMap;
1010

1111
/// Role of messages in the API.
12-
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
12+
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Default)]
1313
#[serde(rename_all = "lowercase")]
1414
pub enum Role {
15+
#[default]
1516
User,
1617
Assistant,
1718
System,
@@ -583,10 +584,10 @@ pub struct CreateResponse {
583584
/// - `web_search_call.action.sources`: Include the sources of the web search tool call.
584585
///
585586
/// - `code_interpreter_call.outputs`: Includes the outputs of python code execution in code
586-
/// interpreter tool call items.
587+
/// interpreter tool call items.
587588
///
588589
/// - `computer_call_output.output.image_url`: Include image urls from the computer call
589-
/// output.
590+
/// output.
590591
///
591592
/// - `file_search_call.results`: Include the search results of the file search tool call.
592593
///
@@ -595,9 +596,9 @@ pub struct CreateResponse {
595596
/// - `message.output_text.logprobs`: Include logprobs with assistant messages.
596597
///
597598
/// - `reasoning.encrypted_content`: Includes an encrypted version of reasoning tokens in
598-
/// reasoning item outputs. This enables reasoning items to be used in multi-turn
599-
/// conversations when using the Responses API statelessly (like when the `store` parameter is
600-
/// set to `false`, or when an organization is enrolled in the zero data retention program).
599+
/// reasoning item outputs. This enables reasoning items to be used in multi-turn
600+
/// conversations when using the Responses API statelessly (like when the `store` parameter is
601+
/// set to `false`, or when an organization is enrolled in the zero data retention program).
601602
#[serde(skip_serializing_if = "Option::is_none")]
602603
pub include: Option<Vec<IncludeEnum>>,
603604

@@ -760,10 +761,10 @@ pub struct CreateResponse {
760761

761762
///The truncation strategy to use for the model response.
762763
/// - `auto`: If the input to this Response exceeds
763-
/// the model's context window size, the model will truncate the
764-
/// response to fit the context window by dropping items from the beginning of the conversation.
764+
/// the model's context window size, the model will truncate the
765+
/// response to fit the context window by dropping items from the beginning of the conversation.
765766
/// - `disabled` (default): If the input size will exceed the context window
766-
/// size for a model, the request will fail with a 400 error.
767+
/// size for a model, the request will fail with a 400 error.
767768
#[serde(skip_serializing_if = "Option::is_none")]
768769
pub truncation: Option<Truncation>,
769770
}
@@ -2333,10 +2334,10 @@ pub struct Response {
23332334

23342335
///The truncation strategy to use for the model response.
23352336
/// - `auto`: If the input to this Response exceeds
2336-
/// the model's context window size, the model will truncate the
2337-
/// response to fit the context window by dropping items from the beginning of the conversation.
2337+
/// the model's context window size, the model will truncate the
2338+
/// response to fit the context window by dropping items from the beginning of the conversation.
23382339
/// - `disabled` (default): If the input size will exceed the context window
2339-
/// size for a model, the request will fail with a 400 error.
2340+
/// size for a model, the request will fail with a 400 error.
23402341
#[serde(skip_serializing_if = "Option::is_none")]
23412342
pub truncation: Option<Truncation>,
23422343

@@ -2539,10 +2540,10 @@ pub struct TokenCountsBody {
25392540

25402541
///The truncation strategy to use for the model response.
25412542
/// - `auto`: If the input to this Response exceeds
2542-
/// the model's context window size, the model will truncate the
2543-
/// response to fit the context window by dropping items from the beginning of the conversation.
2543+
/// the model's context window size, the model will truncate the
2544+
/// response to fit the context window by dropping items from the beginning of the conversation.
25442545
/// - `disabled` (default): If the input size will exceed the context window
2545-
/// size for a model, the request will fail with a 400 error.
2546+
/// size for a model, the request will fail with a 400 error.
25462547
#[serde(skip_serializing_if = "Option::is_none")]
25472548
pub truncation: Option<Truncation>,
25482549
}

async-openai/src/types/responses/response_stream.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
use futures::Stream;
21
use serde::{Deserialize, Serialize};
3-
use std::pin::Pin;
42

53
use crate::{
6-
error::OpenAIError,
4+
OpenAIEventStream,
75
types::responses::{OutputContent, OutputItem, Response, ResponseLogProb, Summary},
86
};
97

108
/// Stream of response events
11-
pub type ResponseStream =
12-
Pin<Box<dyn Stream<Item = Result<ResponseStreamEvent, OpenAIError>> + Send>>;
9+
pub type ResponseStream = OpenAIEventStream<ResponseStreamEvent>;
1310

1411
/// Event types for streaming responses from the Responses API
1512
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]

examples/realtime/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::process::exit;
22

33
use async_openai_wasm::types::realtime::{
44
RealtimeClientEventConversationItemCreate, RealtimeClientEventResponseCreate,
5-
RealtimeConversationItem, RealtimeServerEvent,
5+
RealtimeConversationItem, RealtimeServerEvent, ToText,
66
};
77
use futures_util::{StreamExt, future, pin_mut};
88

@@ -128,7 +128,9 @@ async fn read_stdin(tx: futures_channel::mpsc::UnboundedSender<Message>) {
128128
tx.unbounded_send(message).unwrap();
129129
// send WebSocket message containing event of type "response.create" to server
130130
tx.unbounded_send(Message::Text(
131-
ResponseCreateEvent::default().to_text().into(),
131+
RealtimeClientEventResponseCreate::default()
132+
.to_text()
133+
.into(),
132134
))
133135
.unwrap();
134136
}

0 commit comments

Comments
 (0)