use crate::realtime::*;
use beet_core::prelude::*;
use beet_net::prelude::*;
pub struct RealtimeApi;
impl RealtimeApi {
pub async fn create_session(
req: RealtimeSessionCreateRequest,
) -> Result<RealtimeSessionCreateResponse> {
Request::new(
HttpMethod::Post,
"https://api.openai.com/v1/realtime/sessions",
)
.with_auth_bearer(&env_ext::var("OPENAI_API_KEY")?)
.with_json_body(&req)
.unwrap()
.send()
.await?
.into_result()
.await?
.json::<RealtimeSessionCreateResponse>()
.await?
.xok()
}
#[cfg(target_arch = "wasm32")]
pub async fn connect_webrtc(ephemeral_key: String) -> Result<()> {
connect_webrtc(ephemeral_key).await.map_jserr()
}
}
#[cfg(test)]
mod test {
use crate::realtime::*;
use beet_core::prelude::*;
#[beet_core::test]
async fn works() {
use crate::realtime::types::RealtimeSessionCreateRequest;
RealtimeApi::create_session(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).xpect_eq(Some(Box::new(types::VoiceIdsShared::Ash)));
}
}