use super::types::*;
use crate::openai::*;
use beet_core::cross_fetch::Request;
use beet_core::cross_fetch::ResponseInner;
use beet_core::prelude::*;
pub struct RealtimeApi;
impl RealtimeApi {
pub async fn create(
req: RealtimeSessionCreateRequest,
) -> OpenAiResult<RealtimeSessionCreateResponse> {
Request::new("https://api.openai.com/v1/realtime/sessions")
.method(HttpMethod::Post)
.auth_bearer(&OpenAiKey::get()?)
.body(req)?
.send()
.await?
.into_result()?
.body::<RealtimeSessionCreateResponse>()
.await?
.xok()
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::openai::realtime::*;
use sweet::prelude::*;
#[sweet::test]
async fn works() {
use crate::openai::realtime::types::RealtimeSessionCreateRequest;
RealtimeApi::create(RealtimeSessionCreateRequest {
voice: Some(Box::new(types::VoiceIdsShared::Ash)),
model: Some(types::realtime_session_create_request::Model::Gpt4oRealtimePreview),
..Default::default()
})
.await
.unwrap().xmap(|res|res.voice).xmap(expect).to_be(Some(Box::new(types::VoiceIdsShared::Ash)));
}
}