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

View File

@@ -94,7 +94,7 @@ impl TemplateResponse {
pub fn redirect(path: impl Into<String>) -> Self {
Self {
template_kind: TemplateKind::Redirect(path.into()),
context: Value::from_serialize(&()),
context: Value::from_serialize(()),
}
}
}

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> {
app_state: HtmlState,
public_routers: Vec<Router<S>>,
protected_routers: Vec<Router<S>>,
nested_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>,
}

View File

@@ -112,7 +112,7 @@ pub async fn show_change_password(
) -> Result<impl IntoResponse, HtmlError> {
Ok(TemplateResponse::new_template(
"auth/change_password_form.html",
{},
(),
))
}
@@ -138,6 +138,6 @@ pub async fn change_password(
Ok(TemplateResponse::new_partial(
"auth/account_settings.html",
"change_password_section",
{},
(),
))
}

View File

@@ -31,9 +31,9 @@ pub async fn show_signin_form(
true => Ok(TemplateResponse::new_partial(
"auth/signin_form.html",
"body",
{},
(),
)),
false => Ok(TemplateResponse::new_template("auth/signin_form.html", {})),
false => Ok(TemplateResponse::new_template("auth/signin_form.html", ())),
}
}

View File

@@ -33,9 +33,9 @@ pub async fn show_signup_form(
true => Ok(TemplateResponse::new_partial(
"auth/signup_form.html",
"body",
{},
(),
)),
false => Ok(TemplateResponse::new_template("auth/signup_form.html", {})),
false => Ok(TemplateResponse::new_template("auth/signup_form.html", ())),
}
}

View File

@@ -92,7 +92,7 @@ pub async fn process_ingress_form(
input
.files
.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?;

View File

@@ -85,7 +85,7 @@ pub async fn show_knowledge_page(
let edge_trace = Scatter3D::new(edge_x, edge_y, edge_z)
.mode(Mode::Lines)
.line(Line::new().color("#888").width(2.0))
.hover_template(&format!(
.hover_template(format!(
"Relationship: {}<br>",
rel.metadata.relationship_type
))

View File

@@ -6,18 +6,18 @@ use async_openai::types::{
ChatCompletionRequestSystemMessage, ChatCompletionRequestUserMessage,
CreateChatCompletionRequestArgs,
};
use common::storage::db::SurrealDbClient;
use common::{
error::AppError,
storage::types::{
file_info::FileInfo, ingestion_payload::IngestionPayload, text_content::TextContent,
system_settings::SystemSettings,
file_info::FileInfo, ingestion_payload::IngestionPayload, system_settings::SystemSettings,
text_content::TextContent,
},
};
use reqwest;
use scraper::{Html, Selector};
use std::fmt::Write;
use tiktoken_rs::{o200k_base, CoreBPE};
use common::storage::db::SurrealDbClient;
pub async fn to_text_content(
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?;
Ok(TextContent::new(
text,
instructions.into(),
category.into(),
instructions,
category,
None,
Some(url.into()),
user_id.into(),
Some(url),
user_id,
))
}
IngestionPayload::Text {
@@ -47,12 +47,12 @@ pub async fn to_text_content(
category,
user_id,
} => Ok(TextContent::new(
text.into(),
instructions.into(),
category.into(),
text,
instructions,
category,
None,
None,
user_id.into(),
user_id,
)),
IngestionPayload::File {
file_info,
@@ -63,11 +63,11 @@ pub async fn to_text_content(
let text = extract_text_from_file(&file_info).await?;
Ok(TextContent::new(
text,
instructions.into(),
category.into(),
Some(file_info.to_owned()),
instructions,
category,
Some(file_info),
None,
user_id.into(),
user_id,
))
}
}
@@ -124,7 +124,7 @@ async fn fetch_text_from_url(
.replace(|c: char| c.is_control(), " ")
.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(
@@ -181,13 +181,15 @@ pub async fn process_web_content(
.build()?;
let response = openai_client.chat().create(request).await?;
// Extract and return the content
response
.choices
.first()
.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(