use std::ffi::c_char;
use blazen_uniffi::errors::BlazenError as InnerError;
use crate::error::BlazenError;
use crate::llm::{BlazenCompletionModel, BlazenEmbeddingModel};
use crate::string::{cstr_to_opt_string, cstr_to_str};
unsafe fn write_error(out_err: *mut *mut BlazenError, e: InnerError) -> i32 {
if !out_err.is_null() {
unsafe {
*out_err = BlazenError::from(e).into_ptr();
}
}
-1
}
unsafe fn write_internal_error(out_err: *mut *mut BlazenError, msg: &str) -> i32 {
unsafe {
write_error(
out_err,
InnerError::Internal {
message: msg.to_owned(),
},
)
}
}
#[inline]
fn opt_u32_from_i32(v: i32) -> Option<u32> {
if v < 0 {
None
} else {
Some(u32::try_from(v).unwrap_or(0))
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_openai(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_openai_completion_model(api_key.to_owned(), model, base_url)
{
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_anthropic(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_anthropic_completion_model(
api_key.to_owned(),
model,
base_url,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_gemini(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_gemini_completion_model(api_key.to_owned(), model, base_url)
{
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_openrouter(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_openrouter_completion_model(
api_key.to_owned(),
model,
base_url,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_groq(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_groq_completion_model(api_key.to_owned(), model, base_url) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_together(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_together_completion_model(
api_key.to_owned(),
model,
base_url,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_mistral(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_mistral_completion_model(
api_key.to_owned(),
model,
base_url,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_deepseek(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_deepseek_completion_model(
api_key.to_owned(),
model,
base_url,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_fireworks(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_fireworks_completion_model(
api_key.to_owned(),
model,
base_url,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_perplexity(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_perplexity_completion_model(
api_key.to_owned(),
model,
base_url,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_xai(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_xai_completion_model(api_key.to_owned(), model, base_url) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_cohere(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_cohere_completion_model(api_key.to_owned(), model, base_url)
{
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_azure(
api_key: *const c_char,
resource_name: *const c_char,
deployment_name: *const c_char,
api_version: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let Some(resource_name) = (unsafe { cstr_to_str(resource_name) }) else {
return unsafe { write_internal_error(out_err, "resource_name must not be null") };
};
let Some(deployment_name) = (unsafe { cstr_to_str(deployment_name) }) else {
return unsafe { write_internal_error(out_err, "deployment_name must not be null") };
};
let api_version = unsafe { cstr_to_opt_string(api_version) };
match blazen_uniffi::providers::new_azure_completion_model(
api_key.to_owned(),
resource_name.to_owned(),
deployment_name.to_owned(),
api_version,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_bedrock(
api_key: *const c_char,
region: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let Some(region) = (unsafe { cstr_to_str(region) }) else {
return unsafe { write_internal_error(out_err, "region must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_bedrock_completion_model(
api_key.to_owned(),
region.to_owned(),
model,
base_url,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_fal(
api_key: *const c_char,
model: *const c_char,
endpoint: *const c_char,
enterprise: bool,
auto_route_modality: bool,
base_url: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let endpoint = unsafe { cstr_to_opt_string(endpoint) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_fal_completion_model(
api_key.to_owned(),
model,
base_url,
endpoint,
enterprise,
auto_route_modality,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_openai_compat(
provider_name: *const c_char,
base_url: *const c_char,
api_key: *const c_char,
model: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(provider_name) = (unsafe { cstr_to_str(provider_name) }) else {
return unsafe { write_internal_error(out_err, "provider_name must not be null") };
};
let Some(base_url) = (unsafe { cstr_to_str(base_url) }) else {
return unsafe { write_internal_error(out_err, "base_url must not be null") };
};
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let Some(model) = (unsafe { cstr_to_str(model) }) else {
return unsafe { write_internal_error(out_err, "model must not be null") };
};
match blazen_uniffi::providers::new_openai_compat_completion_model(
provider_name.to_owned(),
base_url.to_owned(),
api_key.to_owned(),
model.to_owned(),
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_ollama(
host: *const c_char,
port: u16,
model: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(host) = (unsafe { cstr_to_str(host) }) else {
return unsafe { write_internal_error(out_err, "host must not be null") };
};
let Some(model) = (unsafe { cstr_to_str(model) }) else {
return unsafe { write_internal_error(out_err, "model must not be null") };
};
match blazen_uniffi::providers::new_ollama_completion_model(
host.to_owned(),
port,
model.to_owned(),
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_lm_studio(
host: *const c_char,
port: u16,
model: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(host) = (unsafe { cstr_to_str(host) }) else {
return unsafe { write_internal_error(out_err, "host must not be null") };
};
let Some(model) = (unsafe { cstr_to_str(model) }) else {
return unsafe { write_internal_error(out_err, "model must not be null") };
};
match blazen_uniffi::providers::new_lm_studio_completion_model(
host.to_owned(),
port,
model.to_owned(),
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_custom_with_openai_protocol(
provider_id: *const c_char,
base_url: *const c_char,
model: *const c_char,
api_key: *const c_char,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(provider_id) = (unsafe { cstr_to_str(provider_id) }) else {
return unsafe { write_internal_error(out_err, "provider_id must not be null") };
};
let Some(base_url) = (unsafe { cstr_to_str(base_url) }) else {
return unsafe { write_internal_error(out_err, "base_url must not be null") };
};
let Some(model) = (unsafe { cstr_to_str(model) }) else {
return unsafe { write_internal_error(out_err, "model must not be null") };
};
let api_key = unsafe { cstr_to_opt_string(api_key) };
match blazen_uniffi::providers::new_custom_completion_model_with_openai_protocol(
provider_id.to_owned(),
base_url.to_owned(),
model.to_owned(),
api_key,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[cfg(feature = "mistralrs")]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_mistralrs(
model_id: *const c_char,
device: *const c_char,
quantization: *const c_char,
context_length: i32,
vision: bool,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(model_id) = (unsafe { cstr_to_str(model_id) }) else {
return unsafe { write_internal_error(out_err, "model_id must not be null") };
};
let device = unsafe { cstr_to_opt_string(device) };
let quantization = unsafe { cstr_to_opt_string(quantization) };
let context_length = opt_u32_from_i32(context_length);
match blazen_uniffi::providers::new_mistralrs_completion_model(
model_id.to_owned(),
device,
quantization,
context_length,
vision,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[cfg(feature = "llamacpp")]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_llamacpp(
model_path: *const c_char,
device: *const c_char,
quantization: *const c_char,
context_length: i32,
n_gpu_layers: i32,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(model_path) = (unsafe { cstr_to_str(model_path) }) else {
return unsafe { write_internal_error(out_err, "model_path must not be null") };
};
let device = unsafe { cstr_to_opt_string(device) };
let quantization = unsafe { cstr_to_opt_string(quantization) };
let context_length = opt_u32_from_i32(context_length);
let n_gpu_layers = opt_u32_from_i32(n_gpu_layers);
match blazen_uniffi::providers::new_llamacpp_completion_model(
model_path.to_owned(),
device,
quantization,
context_length,
n_gpu_layers,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[cfg(feature = "candle-llm")]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_completion_model_new_candle(
model_id: *const c_char,
device: *const c_char,
quantization: *const c_char,
revision: *const c_char,
context_length: i32,
out_model: *mut *mut BlazenCompletionModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(model_id) = (unsafe { cstr_to_str(model_id) }) else {
return unsafe { write_internal_error(out_err, "model_id must not be null") };
};
let device = unsafe { cstr_to_opt_string(device) };
let quantization = unsafe { cstr_to_opt_string(quantization) };
let revision = unsafe { cstr_to_opt_string(revision) };
let context_length = opt_u32_from_i32(context_length);
match blazen_uniffi::providers::new_candle_completion_model(
model_id.to_owned(),
device,
quantization,
revision,
context_length,
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenCompletionModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_embedding_model_new_openai(
api_key: *const c_char,
model: *const c_char,
base_url: *const c_char,
out_model: *mut *mut BlazenEmbeddingModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let base_url = unsafe { cstr_to_opt_string(base_url) };
match blazen_uniffi::providers::new_openai_embedding_model(api_key.to_owned(), model, base_url)
{
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenEmbeddingModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_embedding_model_new_fal(
api_key: *const c_char,
model: *const c_char,
dimensions: i32,
out_model: *mut *mut BlazenEmbeddingModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let Some(api_key) = (unsafe { cstr_to_str(api_key) }) else {
return unsafe { write_internal_error(out_err, "api_key must not be null") };
};
let model = unsafe { cstr_to_opt_string(model) };
let dimensions = opt_u32_from_i32(dimensions);
match blazen_uniffi::providers::new_fal_embedding_model(api_key.to_owned(), model, dimensions) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenEmbeddingModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[cfg(feature = "embed")]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_embedding_model_new_fastembed(
model_name: *const c_char,
max_batch_size: i32,
show_download_progress: bool,
out_model: *mut *mut BlazenEmbeddingModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let model_name = unsafe { cstr_to_opt_string(model_name) };
let max_batch_size = opt_u32_from_i32(max_batch_size);
match blazen_uniffi::providers::new_fastembed_embedding_model(
model_name,
max_batch_size,
Some(show_download_progress),
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenEmbeddingModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[cfg(feature = "candle-embed")]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_embedding_model_new_candle(
model_id: *const c_char,
device: *const c_char,
revision: *const c_char,
out_model: *mut *mut BlazenEmbeddingModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let model_id = unsafe { cstr_to_opt_string(model_id) };
let device = unsafe { cstr_to_opt_string(device) };
let revision = unsafe { cstr_to_opt_string(revision) };
match blazen_uniffi::providers::new_candle_embedding_model(model_id, device, revision) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenEmbeddingModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}
#[cfg(feature = "tract")]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_embedding_model_new_tract(
model_name: *const c_char,
max_batch_size: i32,
show_download_progress: bool,
out_model: *mut *mut BlazenEmbeddingModel,
out_err: *mut *mut BlazenError,
) -> i32 {
let model_name = unsafe { cstr_to_opt_string(model_name) };
let max_batch_size = opt_u32_from_i32(max_batch_size);
match blazen_uniffi::providers::new_tract_embedding_model(
model_name,
max_batch_size,
Some(show_download_progress),
) {
Ok(arc) => {
if !out_model.is_null() {
unsafe {
*out_model = BlazenEmbeddingModel::from(arc).into_ptr();
}
}
0
}
Err(e) => unsafe { write_error(out_err, e) },
}
}