mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-24 01:38:29 +02:00
feat: improved configuration
configuration now works with both env variables and config file
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
use config::{Config, ConfigError, File};
|
use config::{Config, ConfigError, Environment, File};
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Deserialize, Debug)]
|
||||||
pub struct AppConfig {
|
pub struct AppConfig {
|
||||||
|
pub openai_api_key: String,
|
||||||
pub surrealdb_address: String,
|
pub surrealdb_address: String,
|
||||||
pub surrealdb_username: String,
|
pub surrealdb_username: String,
|
||||||
pub surrealdb_password: String,
|
pub surrealdb_password: String,
|
||||||
@@ -11,14 +13,9 @@ pub struct AppConfig {
|
|||||||
|
|
||||||
pub fn get_config() -> Result<AppConfig, ConfigError> {
|
pub fn get_config() -> Result<AppConfig, ConfigError> {
|
||||||
let config = Config::builder()
|
let config = Config::builder()
|
||||||
.add_source(File::with_name("config"))
|
.add_source(File::with_name("config").required(false))
|
||||||
|
.add_source(Environment::default())
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
Ok(AppConfig {
|
Ok(config.try_deserialize()?)
|
||||||
surrealdb_address: config.get_string("SURREALDB_ADDRESS")?,
|
|
||||||
surrealdb_username: config.get_string("SURREALDB_USERNAME")?,
|
|
||||||
surrealdb_password: config.get_string("SURREALDB_PASSWORD")?,
|
|
||||||
surrealdb_namespace: config.get_string("SURREALDB_NAMESPACE")?,
|
|
||||||
surrealdb_database: config.get_string("SURREALDB_DATABASE")?,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,8 +145,10 @@ where
|
|||||||
.unwrap_or_else(|| "An error occurred.".to_string());
|
.unwrap_or_else(|| "An error occurred.".to_string());
|
||||||
|
|
||||||
let trigger_payload = json!({"toast": {"title": title, "description": description, "type": "error"}});
|
let trigger_payload = json!({"toast": {"title": title, "description": description, "type": "error"}});
|
||||||
let trigger_value = serde_json::to_string(&trigger_payload).unwrap_or_else(|e| {error!("Failed to serialize HX-Trigger payload: {}", e);
|
let trigger_value = serde_json::to_string(&trigger_payload).unwrap_or_else(|e| {
|
||||||
r#"{"toast":{"title":"Error","description":"An unexpected error occurred.", "type":"error"}}"#.to_string()});
|
error!("Failed to serialize HX-Trigger payload: {}", e);
|
||||||
|
r#"{"toast":{"title":"Error","description":"An unexpected error occurred.", "type":"error"}}"#.to_string()
|
||||||
|
});
|
||||||
(StatusCode::NO_CONTENT, [(HX_TRIGGER, trigger_value)], "").into_response()
|
(StatusCode::NO_CONTENT, [(HX_TRIGGER, trigger_value)], "").into_response()
|
||||||
} else {
|
} else {
|
||||||
// Non-HTMX request: Render the full errors/error.html page
|
// Non-HTMX request: Render the full errors/error.html page
|
||||||
|
|||||||
@@ -151,7 +151,6 @@ pub async fn show_active_jobs(
|
|||||||
State(state): State<HtmlState>,
|
State(state): State<HtmlState>,
|
||||||
RequireUser(user): RequireUser,
|
RequireUser(user): RequireUser,
|
||||||
) -> Result<impl IntoResponse, HtmlError> {
|
) -> Result<impl IntoResponse, HtmlError> {
|
||||||
return Ok(TemplateResponse::server_error());
|
|
||||||
let active_jobs = User::get_unfinished_ingestion_tasks(&user.id, &state.db).await?;
|
let active_jobs = User::get_unfinished_ingestion_tasks(&user.id, &state.db).await?;
|
||||||
|
|
||||||
Ok(TemplateResponse::new_partial(
|
Ok(TemplateResponse::new_partial(
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
db.ensure_initialized().await?;
|
db.ensure_initialized().await?;
|
||||||
|
|
||||||
let session_store = Arc::new(db.create_session_store().await?);
|
let session_store = Arc::new(db.create_session_store().await?);
|
||||||
let openai_client = Arc::new(async_openai::Client::new());
|
let openai_client = Arc::new(async_openai::Client::with_config(
|
||||||
|
OpenAIConfig::new().with_api_key(&config.openai_api_key),
|
||||||
|
));
|
||||||
|
|
||||||
let html_state = HtmlState::new_with_resources(db, openai_client, session_store)?;
|
let html_state = HtmlState::new_with_resources(db, openai_client, session_store)?;
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
db.ensure_initialized().await?;
|
db.ensure_initialized().await?;
|
||||||
|
|
||||||
let session_store = Arc::new(db.create_session_store().await?);
|
let session_store = Arc::new(db.create_session_store().await?);
|
||||||
let openai_client = Arc::new(async_openai::Client::new());
|
let openai_client = Arc::new(async_openai::Client::with_config(
|
||||||
|
OpenAIConfig::new().with_api_key(&config.openai_api_key),
|
||||||
|
));
|
||||||
|
|
||||||
let html_state = HtmlState::new_with_resources(db, openai_client, session_store)?;
|
let html_state = HtmlState::new_with_resources(db, openai_client, session_store)?;
|
||||||
|
|
||||||
|
|||||||
8
todo.md
8
todo.md
@@ -1,10 +1,8 @@
|
|||||||
\[\] archive ingressed webpage
|
\[\] archive ingressed webpage
|
||||||
\[\] configs primarily get envs
|
\[x\] configs primarily get envs
|
||||||
\[\] filtering on categories
|
\[\] filtering on categories
|
||||||
\[\] integrate assets folder in release build
|
|
||||||
\[\] make sure error messages render correctly
|
|
||||||
\[\] markdown rendering in client
|
\[\] markdown rendering in client
|
||||||
\[\] openai api key in config
|
\[x\] openai api key in config
|
||||||
\[\] testing core functions
|
\[\] testing core functions
|
||||||
\[\] three js graph explorer
|
\[\] three js graph explorer
|
||||||
\[\] three js vector explorer
|
\[\] three js vector explorer
|
||||||
@@ -17,11 +15,13 @@
|
|||||||
\[x\] gdpr
|
\[x\] gdpr
|
||||||
\[x\] html ingression
|
\[x\] html ingression
|
||||||
\[x\] hx-redirect
|
\[x\] hx-redirect
|
||||||
|
\[x\] integrate assets folder in release build
|
||||||
\[x\] integrate templates in release build
|
\[x\] integrate templates in release build
|
||||||
\[x\] ios shortcut generation
|
\[x\] ios shortcut generation
|
||||||
\[x\] job queue
|
\[x\] job queue
|
||||||
\[x\] link to ingressed urls or archives
|
\[x\] link to ingressed urls or archives
|
||||||
\[x\] macro for pagedata?
|
\[x\] macro for pagedata?
|
||||||
|
\[x\] make sure error messages render correctly
|
||||||
\[x\] on updates of knowledgeentity create new embeddings
|
\[x\] on updates of knowledgeentity create new embeddings
|
||||||
\[x\] option to set models, query and processing
|
\[x\] option to set models, query and processing
|
||||||
\[x\] redirects
|
\[x\] redirects
|
||||||
|
|||||||
Reference in New Issue
Block a user