Files
own_assist/src/model.rs
T
milan d9ade649d3
publish release / release (push) Failing after 3m38s
add experimental action
apply formatting
2026-05-08 22:30:11 +02:00

41 lines
1.5 KiB
Rust

use crate::config::{HumanInterface, OllamaModelConfig};
use crate::tlt;
use crate::translate;
use ollama_rs::Ollama;
use ollama_rs::error::OllamaError;
use ollama_rs::models::ModelOptions;
use ollama_rs::models::create::{CreateModelRequest, CreateModelStatus};
pub async fn create_model_from_config(
ollama: &Ollama,
config: &OllamaModelConfig,
interface: &HumanInterface,
) -> Result<CreateModelStatus, OllamaError> {
let model_options = ModelOptions::default()
.num_ctx(config.context_size.unwrap_or(2048)) // 2048 is the ollama default.
.temperature(config.temperature.unwrap_or(0.8)); // 0.8 is the ollama default
let system_prompt = config.system_prompt.clone().unwrap_or(match interface {
HumanInterface::Cli => tlt!("system_prompt_cli"),
HumanInterface::Audio => tlt!("system_prompt_audio"),
});
// print message to warn user of long waiting times
if let Ok(models) = ollama.list_local_models().await
&& !models.iter().any(|m| m.name == config.from_model)
{
let message = tlt!("model_download_needed", config.from_model.clone());
log::info!("{}", message);
println!("{}", console::style(message).yellow().bold());
}
ollama
.create_model(
CreateModelRequest::new(config.name.clone())
.from_model(config.from_model.clone())
.parameters(model_options)
.system(system_prompt),
)
.await
}