mirror of
https://github.com/perstarkse/minne.git
synced 2026-01-11 20:50:24 +01:00
chore: clippy helps out
This commit is contained in:
@@ -50,7 +50,7 @@ pub async fn ingest_data(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
try_join_all(futures).await.map_err(AppError::from)?;
|
try_join_all(futures).await?;
|
||||||
|
|
||||||
Ok(StatusCode::OK)
|
Ok(StatusCode::OK)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,5 +30,5 @@ pub fn get_config() -> Result<AppConfig, ConfigError> {
|
|||||||
.add_source(Environment::default())
|
.add_source(Environment::default())
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
Ok(config.try_deserialize()?)
|
config.try_deserialize()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ pub async fn generate_embedding_with_params(
|
|||||||
let request = CreateEmbeddingRequestArgs::default()
|
let request = CreateEmbeddingRequestArgs::default()
|
||||||
.model(model)
|
.model(model)
|
||||||
.input([input])
|
.input([input])
|
||||||
.dimensions(dimensions as u32)
|
.dimensions(dimensions)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let response = client.embeddings().create(request).await?;
|
let response = client.embeddings().create(request).await?;
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ where
|
|||||||
if is_htmx {
|
if is_htmx {
|
||||||
(StatusCode::OK, [(axum_htmx::HX_REDIRECT, path)], "").into_response()
|
(StatusCode::OK, [(axum_htmx::HX_REDIRECT, path)], "").into_response()
|
||||||
} else {
|
} else {
|
||||||
Redirect::to(&path).into_response()
|
Redirect::to(path).into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ pub async fn process_ingress_form(
|
|||||||
error: String,
|
error: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.content.as_ref().map_or(true, |c| c.len() < 2) && input.files.is_empty() {
|
if input.content.as_ref().is_none_or(|c| c.len() < 2) && input.files.is_empty() {
|
||||||
return Ok(TemplateResponse::new_template(
|
return Ok(TemplateResponse::new_template(
|
||||||
"index/signed_in/ingress_form.html",
|
"index/signed_in/ingress_form.html",
|
||||||
IngressFormData {
|
IngressFormData {
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ use std::io::{Seek, SeekFrom};
|
|||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
|
||||||
use crate::utils::{audio_transcription::transcribe_audio_file, image_parsing::extract_text_from_image};
|
use crate::utils::{
|
||||||
|
audio_transcription::transcribe_audio_file, image_parsing::extract_text_from_image,
|
||||||
|
};
|
||||||
|
|
||||||
pub async fn to_text_content(
|
pub async fn to_text_content(
|
||||||
ingestion_payload: IngestionPayload,
|
ingestion_payload: IngestionPayload,
|
||||||
@@ -37,7 +39,7 @@ pub async fn to_text_content(
|
|||||||
category,
|
category,
|
||||||
user_id,
|
user_id,
|
||||||
} => {
|
} => {
|
||||||
let (article, file_info) = fetch_article_from_url(&url, db, &user_id, &config).await?;
|
let (article, file_info) = fetch_article_from_url(&url, db, &user_id, config).await?;
|
||||||
Ok(TextContent::new(
|
Ok(TextContent::new(
|
||||||
article.text_content.into(),
|
article.text_content.into(),
|
||||||
Some(context),
|
Some(context),
|
||||||
@@ -179,7 +181,7 @@ async fn fetch_article_from_url(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Store screenshot
|
// Store screenshot
|
||||||
let file_info = FileInfo::new(field_data, db, user_id, &config).await?;
|
let file_info = FileInfo::new(field_data, db, user_id, config).await?;
|
||||||
|
|
||||||
// Parse content...
|
// Parse content...
|
||||||
let config = dom_smoothie::Config {
|
let config = dom_smoothie::Config {
|
||||||
@@ -231,8 +233,8 @@ async fn extract_text_from_file(
|
|||||||
let content = tokio::fs::read_to_string(&file_info.path).await?;
|
let content = tokio::fs::read_to_string(&file_info.path).await?;
|
||||||
Ok(content)
|
Ok(content)
|
||||||
}
|
}
|
||||||
"audio/mpeg" | "audio/mp3" | "audio/wav" | "audio/x-wav" | "audio/webm" | "audio/mp4" | "audio/ogg" | "audio/flac" => {
|
"audio/mpeg" | "audio/mp3" | "audio/wav" | "audio/x-wav" | "audio/webm" | "audio/mp4"
|
||||||
|
| "audio/ogg" | "audio/flac" => {
|
||||||
transcribe_audio_file(&file_info.path, db_client, openai_client).await
|
transcribe_audio_file(&file_info.path, db_client, openai_client).await
|
||||||
}
|
}
|
||||||
// Handle other MIME types as needed
|
// Handle other MIME types as needed
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ pub async fn extract_text_from_image(
|
|||||||
|
|
||||||
let description = response
|
let description = response
|
||||||
.choices
|
.choices
|
||||||
.get(0)
|
.first()
|
||||||
.and_then(|c| c.message.content.as_ref())
|
.and_then(|c| c.message.content.as_ref())
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_else(|| "No description found.".to_string());
|
.unwrap_or_else(|| "No description found.".to_string());
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
pub mod audio_transcription;
|
||||||
pub mod image_parsing;
|
pub mod image_parsing;
|
||||||
pub mod llm_instructions;
|
pub mod llm_instructions;
|
||||||
pub mod audio_transcription;
|
|
||||||
|
|
||||||
use common::error::AppError;
|
use common::error::AppError;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -33,16 +33,12 @@ impl GraphMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If parsing fails, look it up in the map.
|
// If parsing fails, look it up in the map.
|
||||||
self.key_to_id
|
self.key_to_id.get(key).copied().ok_or_else(|| {
|
||||||
.get(key)
|
AppError::GraphMapper(format!(
|
||||||
.map(|id| *id) // Dereference the &Uuid to get Uuid
|
"Key '{}' is not a valid UUID and was not found in the map.",
|
||||||
// If `get` returned None, create and return an error.
|
key
|
||||||
.ok_or_else(|| {
|
))
|
||||||
AppError::GraphMapper(format!(
|
})
|
||||||
"Key '{}' is not a valid UUID and was not found in the map.",
|
|
||||||
key
|
|
||||||
))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assigns a new UUID for a given key. (No changes needed here)
|
/// Assigns a new UUID for a given key. (No changes needed here)
|
||||||
@@ -56,7 +52,7 @@ impl GraphMapper {
|
|||||||
pub fn get_id(&self, key: &str) -> Result<Uuid, AppError> {
|
pub fn get_id(&self, key: &str) -> Result<Uuid, AppError> {
|
||||||
self.key_to_id
|
self.key_to_id
|
||||||
.get(key)
|
.get(key)
|
||||||
.map(|id| *id)
|
.copied()
|
||||||
.ok_or_else(|| AppError::GraphMapper(format!("Key '{}' not found in map.", key)))
|
.ok_or_else(|| AppError::GraphMapper(format!("Key '{}' not found in map.", key)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -441,11 +441,9 @@ pub fn parse_stream(json_string: &str) -> Result<Value, String> {
|
|||||||
current_status.clone(),
|
current_status.clone(),
|
||||||
current_char.to_string()
|
current_char.to_string()
|
||||||
);
|
);
|
||||||
if let Err(e) = add_char_into_object(&mut out, &mut current_status, current_char) {
|
add_char_into_object(&mut out, &mut current_status, current_char)?
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Ok(out);
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
@@ -464,6 +462,11 @@ pub struct JsonStreamParser {
|
|||||||
object: Value,
|
object: Value,
|
||||||
current_status: ObjectStatus,
|
current_status: ObjectStatus,
|
||||||
}
|
}
|
||||||
|
impl Default for JsonStreamParser {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl JsonStreamParser {
|
impl JsonStreamParser {
|
||||||
pub fn new() -> JsonStreamParser {
|
pub fn new() -> JsonStreamParser {
|
||||||
|
|||||||
Reference in New Issue
Block a user