refactor cli config and move most of it to own_assist_common so that it can be reused in other clients.

This commit is contained in:
2026-07-28 17:58:44 +02:00
parent c5b594e1da
commit e90efbb544
12 changed files with 2439 additions and 117 deletions
+2 -4
View File
@@ -1,5 +1,4 @@
use ollama_rs::Ollama;
use ollama_rs::headers::{HeaderMap, HeaderValue};
use own_assist_common::config::{AudioClientConfig, MCPClientConfig, OllamaConfig};
use own_assist_common::config_from_file;
use own_assist_common::config_loader::ConfigLoadingError;
use own_mcp::audio::{AudioClient, AudioClientTrait};
@@ -9,7 +8,6 @@ use own_mcp::{AgentChat, mcp};
use rmcp::model::Implementation;
use serde::Deserialize;
use std::collections::HashMap;
use url::Url;
#[derive(Debug, Deserialize)]
pub struct Config {
@@ -98,7 +96,7 @@ pub enum HumanInterface {
#[derive(Debug, Deserialize)]
pub struct AudioConfig {
server: AudioServerConfig,
server: AudioClientConfig,
}
#[derive(Debug, Deserialize)]
+5 -7
View File
@@ -1,12 +1,10 @@
mod config;
mod human_interface;
mod i18n;
mod model;
use crate::config::Config;
use crate::human_interface::HumanInterface;
use crate::i18n::translate;
use crate::model::create_model_from_config;
use base64::Engine;
use clap::Parser;
use cpal::traits::HostTrait;
@@ -100,16 +98,16 @@ async fn main() {
.inspect_err(exit_msg!("error loading assist.toml"))
.unwrap();
let ollama = config.ollama_instance();
let model_name = &config.ollama_config().model.name;
let ollama_config = config.ollama_config();
let ollama = ollama_config.ollama();
let model_name = &ollama_config.model_config.name;
create_model_from_config(&ollama, &config.ollama_config().model, &config.interface)
.await
.inspect_err(exit_msg!(format!(
ollama_config.create_model(Some(tlt!("model_download_needed"))).await.inspect_err(exit_msg!(format!(
"failed creating ollama model `{model_name}`"
)))
.unwrap();
let mcp_clients = config
.mcp_clients()
.await
-40
View File
@@ -1,40 +0,0 @@
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
}