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:
+1
-1
@@ -12,7 +12,7 @@ log = { version = "0.4.29" }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
url = "2.5.8"
|
||||
own_mcp = { version = "0.1.1", registry = "gitea" }
|
||||
own_assist_common = { version = "0.3.0", registry = "gitea" }
|
||||
own_assist_common = { version = "0.4.1", registry = "gitea" }
|
||||
mcp_server_collection = { version = "0.2.0", registry = "gitea", optional = true}
|
||||
thiserror = "2.0.18"
|
||||
dialoguer = "0.12.0"
|
||||
|
||||
+25
-23
@@ -44,13 +44,13 @@
|
||||
|
||||
<h2>Overview of licenses:</h2>
|
||||
<ul class="licenses-overview">
|
||||
<li><a href="#Apache-2.0">Apache License 2.0</a> (250)</li>
|
||||
<li><a href="#Apache-2.0">Apache License 2.0</a> (251)</li>
|
||||
<li><a href="#MIT">MIT License</a> (77)</li>
|
||||
<li><a href="#Unicode-3.0">Unicode License v3</a> (19)</li>
|
||||
<li><a href="#MPL-2.0">Mozilla Public License 2.0</a> (12)</li>
|
||||
<li><a href="#BSD-3-Clause">BSD 3-Clause "New" or "Revised" License</a> (7)</li>
|
||||
<li><a href="#GPL-3.0">GNU General Public License v3.0 only</a> (5)</li>
|
||||
<li><a href="#ISC">ISC License</a> (5)</li>
|
||||
<li><a href="#GPL-3.0">GNU General Public License v3.0 only</a> (4)</li>
|
||||
<li><a href="#CDLA-Permissive-2.0">Community Data License Agreement Permissive 2.0</a> (2)</li>
|
||||
<li><a href="#Zlib">zlib License</a> (1)</li>
|
||||
</ul>
|
||||
@@ -64,6 +64,7 @@
|
||||
<li><a href=" https://github.com/tormol/encode_unicode ">encode_unicode 1.0.0</a></li>
|
||||
<li><a href=" https://github.com/hsivonen/encoding_rs ">encoding_rs 0.8.35</a></li>
|
||||
<li><a href=" https://github.com/ruuda/hound ">hound 3.5.1</a></li>
|
||||
<li><a href=" https://github.com/4t145/sse-stream/ ">sse-stream 0.2.5</a></li>
|
||||
<li><a href=" https://github.com/nvzqz/static-assertions-rs ">static_assertions 1.1.0</a></li>
|
||||
<li><a href=" https://github.com/hsivonen/utf8_iter ">utf8_iter 1.0.4</a></li>
|
||||
<li><a href=" https://github.com/RustCrypto/utils ">zeroize 1.9.0</a></li>
|
||||
@@ -506,7 +507,7 @@
|
||||
<h3 id="Apache-2.0">Apache License 2.0</h3>
|
||||
<h4>Used by:</h4>
|
||||
<ul class="license-used-by">
|
||||
<li><a href=" https://github.com/google/zerocopy ">zerocopy 0.8.54</a></li>
|
||||
<li><a href=" https://github.com/google/zerocopy ">zerocopy 0.8.55</a></li>
|
||||
</ul>
|
||||
<pre class="license-text"> Apache License
|
||||
Version 2.0, January 2004
|
||||
@@ -1559,9 +1560,9 @@
|
||||
<li><a href=" https://github.com/rust-cli/anstyle.git ">anstyle-query 1.1.5</a></li>
|
||||
<li><a href=" https://github.com/rust-cli/anstyle.git ">anstyle-wincon 3.0.11</a></li>
|
||||
<li><a href=" https://github.com/rust-cli/anstyle.git ">anstyle 1.0.14</a></li>
|
||||
<li><a href=" https://github.com/clap-rs/clap ">clap 4.6.2</a></li>
|
||||
<li><a href=" https://github.com/clap-rs/clap ">clap 4.6.4</a></li>
|
||||
<li><a href=" https://github.com/clap-rs/clap ">clap_builder 4.6.2</a></li>
|
||||
<li><a href=" https://github.com/clap-rs/clap ">clap_derive 4.6.1</a></li>
|
||||
<li><a href=" https://github.com/clap-rs/clap ">clap_derive 4.6.4</a></li>
|
||||
<li><a href=" https://github.com/clap-rs/clap ">clap_lex 1.1.0</a></li>
|
||||
<li><a href=" https://github.com/rust-cli/anstyle.git ">colorchoice 1.0.5</a></li>
|
||||
<li><a href=" https://github.com/rust-cli/env_logger ">env_filter 2.0.0</a></li>
|
||||
@@ -3472,7 +3473,7 @@ limitations under the License.
|
||||
<h3 id="Apache-2.0">Apache License 2.0</h3>
|
||||
<h4>Used by:</h4>
|
||||
<ul class="license-used-by">
|
||||
<li><a href=" https://github.com/rustls/pki-types ">rustls-pki-types 1.15.0</a></li>
|
||||
<li><a href=" https://github.com/rustls/pki-types ">rustls-pki-types 1.15.1</a></li>
|
||||
</ul>
|
||||
<pre class="license-text"> Apache License
|
||||
Version 2.0, January 2004
|
||||
@@ -3685,10 +3686,11 @@ limitations under the License.
|
||||
<li><a href=" https://github.com/smol-rs/atomic-waker ">atomic-waker 1.1.2</a></li>
|
||||
<li><a href=" https://github.com/cuviper/autocfg ">autocfg 1.5.1</a></li>
|
||||
<li><a href=" https://github.com/marshallpierce/rust-base64 ">base64 0.22.1</a></li>
|
||||
<li><a href=" https://github.com/marshallpierce/rust-base64 ">base64 0.23.0</a></li>
|
||||
<li><a href=" https://github.com/bitflags/bitflags ">bitflags 1.3.2</a></li>
|
||||
<li><a href=" https://github.com/bitflags/bitflags ">bitflags 2.13.1</a></li>
|
||||
<li><a href=" https://github.com/fitzgen/bumpalo ">bumpalo 3.20.3</a></li>
|
||||
<li><a href=" https://github.com/rust-lang/cc-rs ">cc 1.3.0</a></li>
|
||||
<li><a href=" https://github.com/rust-lang/cc-rs ">cc 1.4.0</a></li>
|
||||
<li><a href=" https://github.com/rust-lang/cfg-if ">cfg-if 1.0.4</a></li>
|
||||
<li><a href=" https://github.com/rust-lang/cmake-rs ">cmake 0.1.58</a></li>
|
||||
<li><a href=" https://github.com/servo/core-foundation-rs ">core-foundation-sys 0.8.7</a></li>
|
||||
@@ -3698,7 +3700,7 @@ limitations under the License.
|
||||
<li><a href=" https://github.com/yaahc/displaydoc ">displaydoc 0.2.6</a></li>
|
||||
<li><a href=" https://github.com/indexmap-rs/equivalent ">equivalent 1.0.2</a></li>
|
||||
<li><a href=" https://github.com/lambda-fairy/rust-errno ">errno 0.3.14</a></li>
|
||||
<li><a href=" https://github.com/smol-rs/fastrand ">fastrand 2.4.1</a></li>
|
||||
<li><a href=" https://github.com/smol-rs/fastrand ">fastrand 2.5.0</a></li>
|
||||
<li><a href=" https://github.com/rust-lang/cc-rs ">find-msvc-tools 0.1.9</a></li>
|
||||
<li><a href=" https://github.com/servo/rust-fnv ">fnv 1.0.7</a></li>
|
||||
<li><a href=" https://github.com/servo/rust-url ">form_urlencoded 1.2.2</a></li>
|
||||
@@ -5013,7 +5015,7 @@ limitations under the License.
|
||||
<h3 id="Apache-2.0">Apache License 2.0</h3>
|
||||
<h4>Used by:</h4>
|
||||
<ul class="license-used-by">
|
||||
<li><a href=" https://github.com/Lokathor/bytemuck ">bytemuck 1.25.1</a></li>
|
||||
<li><a href=" https://github.com/Lokathor/bytemuck ">bytemuck 1.25.2</a></li>
|
||||
</ul>
|
||||
<pre class="license-text">Apache License
|
||||
Version 2.0, January 2004
|
||||
@@ -5305,7 +5307,7 @@ limitations under the License.
|
||||
<li><a href=" https://github.com/jni-rs/jni-rs ">jni-macros 0.22.4</a></li>
|
||||
<li><a href=" https://github.com/jni-rs/jni-sys ">jni-sys-macros 0.4.1</a></li>
|
||||
<li><a href=" https://github.com/jni-rs/jni-rs ">jni 0.22.4</a></li>
|
||||
<li><a href=" https://github.com/rust-lang/libc ">libc 0.2.186</a></li>
|
||||
<li><a href=" https://github.com/rust-lang/libc ">libc 0.2.189</a></li>
|
||||
<li><a href=" https://github.com/JohnTitor/mach2 ">mach2 0.5.0</a></li>
|
||||
<li><a href=" https://github.com/JohnTitor/mach2 ">mach2 0.6.0</a></li>
|
||||
<li><a href=" https://github.com/rust-windowing/android-ndk-rs ">ndk-context 0.1.1</a></li>
|
||||
@@ -5342,15 +5344,14 @@ limitations under the License.
|
||||
<li><a href=" https://github.com/serde-rs/serde ">serde_core 1.0.229</a></li>
|
||||
<li><a href=" https://github.com/serde-rs/serde ">serde_derive 1.0.229</a></li>
|
||||
<li><a href=" https://github.com/serde-rs/serde ">serde_derive_internals 0.29.1</a></li>
|
||||
<li><a href=" https://github.com/serde-rs/json ">serde_json 1.0.150</a></li>
|
||||
<li><a href=" https://github.com/serde-rs/json ">serde_json 1.0.151</a></li>
|
||||
<li><a href=" https://github.com/dtolnay/path-to-error ">serde_path_to_error 0.1.20</a></li>
|
||||
<li><a href=" https://github.com/nox/serde_urlencoded ">serde_urlencoded 0.7.1</a></li>
|
||||
<li><a href=" https://github.com/comex/rust-shlex ">shlex 2.0.1</a></li>
|
||||
<li><a href=" https://github.com/rusticstuff/simdutf8 ">simdutf8 0.1.5</a></li>
|
||||
<li><a href=" https://github.com/jedisct1/rust-siphash ">siphasher 1.0.3</a></li>
|
||||
<li><a href=" https://github.com/4t145/sse-stream/ ">sse-stream 0.2.4</a></li>
|
||||
<li><a href=" https://github.com/dtolnay/syn ">syn 2.0.119</a></li>
|
||||
<li><a href=" https://github.com/dtolnay/syn ">syn 3.0.0</a></li>
|
||||
<li><a href=" https://github.com/dtolnay/syn ">syn 3.0.3</a></li>
|
||||
<li><a href=" https://github.com/Actyx/sync_wrapper ">sync_wrapper 1.0.2</a></li>
|
||||
<li><a href=" https://github.com/dtolnay/thiserror ">thiserror-impl 1.0.69</a></li>
|
||||
<li><a href=" https://github.com/dtolnay/thiserror ">thiserror-impl 2.0.19</a></li>
|
||||
@@ -6197,9 +6198,10 @@ insights.
|
||||
<h4>Used by:</h4>
|
||||
<ul class="license-used-by">
|
||||
<li><a href=" https://crates.io/crates/own_assist_cli ">own_assist_cli 0.3.0</a></li>
|
||||
<li><a href=" https://crates.io/crates/own_assist_common ">own_assist_common 0.3.0</a></li>
|
||||
<li><a href=" https://crates.io/crates/mcp_server_collection ">mcp_server_collection 0.2.2</a></li>
|
||||
<li><a href=" https://crates.io/crates/own_mcp ">own_mcp 0.1.0</a></li>
|
||||
<li><a href=" https://crates.io/crates/own_assist_common ">own_assist_common 0.3.0</a></li>
|
||||
<li><a href=" https://crates.io/crates/own_assist_common ">own_assist_common 0.4.1</a></li>
|
||||
<li><a href=" https://crates.io/crates/own_mcp ">own_mcp 0.1.1</a></li>
|
||||
</ul>
|
||||
<pre class="license-text">GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
@@ -6613,7 +6615,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
<h3 id="MIT">MIT License</h3>
|
||||
<h4>Used by:</h4>
|
||||
<ul class="license-used-by">
|
||||
<li><a href=" https://github.com/hyperium/hyper ">hyper 1.10.1</a></li>
|
||||
<li><a href=" https://github.com/hyperium/hyper ">hyper 1.11.0</a></li>
|
||||
</ul>
|
||||
<pre class="license-text">Copyright (c) 2014-2026 Sean McArthur
|
||||
|
||||
@@ -6640,7 +6642,7 @@ THE SOFTWARE.
|
||||
<h3 id="MIT">MIT License</h3>
|
||||
<h4>Used by:</h4>
|
||||
<ul class="license-used-by">
|
||||
<li><a href=" https://github.com/badboy/iso8601 ">iso8601 0.6.3</a></li>
|
||||
<li><a href=" https://github.com/badboy/iso8601 ">iso8601 0.6.5</a></li>
|
||||
</ul>
|
||||
<pre class="license-text">Copyright (c) 2015 Jan-Erik Rediger, Hendrik Sollich
|
||||
|
||||
@@ -7395,8 +7397,8 @@ SOFTWARE.
|
||||
<h3 id="MIT">MIT License</h3>
|
||||
<h4>Used by:</h4>
|
||||
<ul class="license-used-by">
|
||||
<li><a href=" https://github.com/pepperoni21/ollama-rs ">ollama-rs-macros 0.3.5</a></li>
|
||||
<li><a href=" https://github.com/pepperoni21/ollama-rs ">ollama-rs 0.3.5</a></li>
|
||||
<li><a href=" https://github.com/pepperoni21/ollama-rs ">ollama-rs-macros 0.3.6</a></li>
|
||||
<li><a href=" https://github.com/pepperoni21/ollama-rs ">ollama-rs 0.3.6</a></li>
|
||||
</ul>
|
||||
<pre class="license-text">MIT License
|
||||
|
||||
@@ -7486,9 +7488,9 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
<h3 id="MIT">MIT License</h3>
|
||||
<h4>Used by:</h4>
|
||||
<ul class="license-used-by">
|
||||
<li><a href=" https://github.com/tokio-rs/tokio ">tokio-stream 0.1.18</a></li>
|
||||
<li><a href=" https://github.com/tokio-rs/tokio ">tokio-util 0.7.18</a></li>
|
||||
<li><a href=" https://github.com/tokio-rs/tokio ">tokio 1.53.0</a></li>
|
||||
<li><a href=" https://github.com/tokio-rs/tokio ">tokio-stream 0.1.19</a></li>
|
||||
<li><a href=" https://github.com/tokio-rs/tokio ">tokio-util 0.7.19</a></li>
|
||||
<li><a href=" https://github.com/tokio-rs/tokio ">tokio 1.53.1</a></li>
|
||||
</ul>
|
||||
<pre class="license-text">MIT License
|
||||
|
||||
@@ -7605,7 +7607,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
<ul class="license-used-by">
|
||||
<li><a href=" https://github.com/BurntSushi/aho-corasick ">aho-corasick 1.1.4</a></li>
|
||||
<li><a href=" https://github.com/BurntSushi/jiff ">jiff-core 0.1.0</a></li>
|
||||
<li><a href=" https://github.com/BurntSushi/jiff ">jiff 0.2.33</a></li>
|
||||
<li><a href=" https://github.com/BurntSushi/jiff ">jiff 0.2.35</a></li>
|
||||
<li><a href=" https://github.com/BurntSushi/memchr ">memchr 2.8.3</a></li>
|
||||
<li><a href=" https://github.com/BurntSushi/walkdir ">walkdir 2.5.0</a></li>
|
||||
</ul>
|
||||
|
||||
+2
-4
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user