use futures::{Stream, StreamExt};
use serde_json::Value;
use crate::Result;
use crate::bindings::oino::extension::models as wm;
pub use crate::bindings::oino::extension::models::Credential;
use crate::error::parse;
pub async fn complete(request: &Value) -> Result<Value> {
parse(&wm::complete(request.to_string(), None).await?)
}
pub async fn stream(request: &Value) -> Result<impl Stream<Item = Value>> {
let reader = wm::stream(request.to_string()).await?;
Ok(reader
.into_stream()
.map(|item: String| serde_json::from_str(&item).unwrap_or(Value::String(item))))
}
pub async fn summarize_default(
messages: &Value,
custom_instructions: Option<&str>,
previous_summary: Option<&str>,
) -> Result<Value> {
parse(
&wm::summarize_default(
messages.to_string(),
custom_instructions.map(ToOwned::to_owned),
previous_summary.map(ToOwned::to_owned),
)
.await?,
)
}
pub async fn credential_for(provider_or_base_url: &str) -> Result<Option<Credential>> {
Ok(wm::credential_for(provider_or_base_url.to_owned()).await?)
}
pub async fn classify(request: &Value) -> Result<Value> {
parse(&wm::classify(request.to_string()).await?)
}
pub async fn generate_image(request: &Value) -> Result<Value> {
parse(&wm::generate_image(request.to_string()).await?)
}