chore: clippy suggestions

This commit is contained in:
Per Stark
2025-03-31 12:35:46 +02:00
parent 56a2e1d801
commit 42798788a5
8 changed files with 32 additions and 28 deletions
@@ -94,7 +94,7 @@ impl TemplateResponse {
pub fn redirect(path: impl Into<String>) -> Self { pub fn redirect(path: impl Into<String>) -> Self {
Self { Self {
template_kind: TemplateKind::Redirect(path.into()), template_kind: TemplateKind::Redirect(path.into()),
context: Value::from_serialize(&()), context: Value::from_serialize(()),
} }
} }
} }
+3 -1
View File
@@ -38,13 +38,15 @@ macro_rules! create_asset_service {
}}; }};
} }
pub type MiddleWareVecType<S> = Vec<Box<dyn FnOnce(Router<S>) -> Router<S> + Send>>;
pub struct RouterFactory<S> { pub struct RouterFactory<S> {
app_state: HtmlState, app_state: HtmlState,
public_routers: Vec<Router<S>>, public_routers: Vec<Router<S>>,
protected_routers: Vec<Router<S>>, protected_routers: Vec<Router<S>>,
nested_routes: Vec<(String, Router<S>)>, nested_routes: Vec<(String, Router<S>)>,
nested_protected_routes: Vec<(String, Router<S>)>, nested_protected_routes: Vec<(String, Router<S>)>,
custom_middleware: Vec<Box<dyn FnOnce(Router<S>) -> Router<S> + Send>>, custom_middleware: MiddleWareVecType<S>,
public_assets_config: Option<AssetsConfig>, public_assets_config: Option<AssetsConfig>,
} }
@@ -112,7 +112,7 @@ pub async fn show_change_password(
) -> Result<impl IntoResponse, HtmlError> { ) -> Result<impl IntoResponse, HtmlError> {
Ok(TemplateResponse::new_template( Ok(TemplateResponse::new_template(
"auth/change_password_form.html", "auth/change_password_form.html",
{}, (),
)) ))
} }
@@ -138,6 +138,6 @@ pub async fn change_password(
Ok(TemplateResponse::new_partial( Ok(TemplateResponse::new_partial(
"auth/account_settings.html", "auth/account_settings.html",
"change_password_section", "change_password_section",
{}, (),
)) ))
} }
+2 -2
View File
@@ -31,9 +31,9 @@ pub async fn show_signin_form(
true => Ok(TemplateResponse::new_partial( true => Ok(TemplateResponse::new_partial(
"auth/signin_form.html", "auth/signin_form.html",
"body", "body",
{}, (),
)), )),
false => Ok(TemplateResponse::new_template("auth/signin_form.html", {})), false => Ok(TemplateResponse::new_template("auth/signin_form.html", ())),
} }
} }
+2 -2
View File
@@ -33,9 +33,9 @@ pub async fn show_signup_form(
true => Ok(TemplateResponse::new_partial( true => Ok(TemplateResponse::new_partial(
"auth/signup_form.html", "auth/signup_form.html",
"body", "body",
{}, (),
)), )),
false => Ok(TemplateResponse::new_template("auth/signup_form.html", {})), false => Ok(TemplateResponse::new_template("auth/signup_form.html", ())),
} }
} }
@@ -92,7 +92,7 @@ pub async fn process_ingress_form(
input input
.files .files
.into_iter() .into_iter()
.map(|file| FileInfo::new(file, &state.db, &user.id).map_err(|e| AppError::from(e))), .map(|file| FileInfo::new(file, &state.db, &user.id).map_err(AppError::from)),
) )
.await?; .await?;
@@ -85,7 +85,7 @@ pub async fn show_knowledge_page(
let edge_trace = Scatter3D::new(edge_x, edge_y, edge_z) let edge_trace = Scatter3D::new(edge_x, edge_y, edge_z)
.mode(Mode::Lines) .mode(Mode::Lines)
.line(Line::new().color("#888").width(2.0)) .line(Line::new().color("#888").width(2.0))
.hover_template(&format!( .hover_template(format!(
"Relationship: {}<br>", "Relationship: {}<br>",
rel.metadata.relationship_type rel.metadata.relationship_type
)) ))
+20 -18
View File
@@ -6,18 +6,18 @@ use async_openai::types::{
ChatCompletionRequestSystemMessage, ChatCompletionRequestUserMessage, ChatCompletionRequestSystemMessage, ChatCompletionRequestUserMessage,
CreateChatCompletionRequestArgs, CreateChatCompletionRequestArgs,
}; };
use common::storage::db::SurrealDbClient;
use common::{ use common::{
error::AppError, error::AppError,
storage::types::{ storage::types::{
file_info::FileInfo, ingestion_payload::IngestionPayload, text_content::TextContent, file_info::FileInfo, ingestion_payload::IngestionPayload, system_settings::SystemSettings,
system_settings::SystemSettings, text_content::TextContent,
}, },
}; };
use reqwest; use reqwest;
use scraper::{Html, Selector}; use scraper::{Html, Selector};
use std::fmt::Write; use std::fmt::Write;
use tiktoken_rs::{o200k_base, CoreBPE}; use tiktoken_rs::{o200k_base, CoreBPE};
use common::storage::db::SurrealDbClient;
pub async fn to_text_content( pub async fn to_text_content(
ingestion_payload: IngestionPayload, ingestion_payload: IngestionPayload,
@@ -34,11 +34,11 @@ pub async fn to_text_content(
let text = fetch_text_from_url(&url, openai_client, db_client).await?; let text = fetch_text_from_url(&url, openai_client, db_client).await?;
Ok(TextContent::new( Ok(TextContent::new(
text, text,
instructions.into(), instructions,
category.into(), category,
None, None,
Some(url.into()), Some(url),
user_id.into(), user_id,
)) ))
} }
IngestionPayload::Text { IngestionPayload::Text {
@@ -47,12 +47,12 @@ pub async fn to_text_content(
category, category,
user_id, user_id,
} => Ok(TextContent::new( } => Ok(TextContent::new(
text.into(), text,
instructions.into(), instructions,
category.into(), category,
None, None,
None, None,
user_id.into(), user_id,
)), )),
IngestionPayload::File { IngestionPayload::File {
file_info, file_info,
@@ -63,11 +63,11 @@ pub async fn to_text_content(
let text = extract_text_from_file(&file_info).await?; let text = extract_text_from_file(&file_info).await?;
Ok(TextContent::new( Ok(TextContent::new(
text, text,
instructions.into(), instructions,
category.into(), category,
Some(file_info.to_owned()), Some(file_info),
None, None,
user_id.into(), user_id,
)) ))
} }
} }
@@ -124,7 +124,7 @@ async fn fetch_text_from_url(
.replace(|c: char| c.is_control(), " ") .replace(|c: char| c.is_control(), " ")
.replace(" ", " "); .replace(" ", " ");
process_web_content(content, openai_client, &db_client).await process_web_content(content, openai_client, db_client).await
} }
pub async fn process_web_content( pub async fn process_web_content(
@@ -181,13 +181,15 @@ pub async fn process_web_content(
.build()?; .build()?;
let response = openai_client.chat().create(request).await?; let response = openai_client.chat().create(request).await?;
// Extract and return the content // Extract and return the content
response response
.choices .choices
.first() .first()
.and_then(|choice| choice.message.content.clone()) .and_then(|choice| choice.message.content.clone())
.ok_or(AppError::LLMParsing("No content found in LLM response".into())) .ok_or(AppError::LLMParsing(
"No content found in LLM response".into(),
))
} }
fn truncate_content( fn truncate_content(