Improve LLM

This commit is contained in:
Andras Schmelczer 2026-03-15 14:05:34 +00:00
parent 02712f41e8
commit 80c093b7ba
16 changed files with 898 additions and 278 deletions

View file

@ -94,13 +94,13 @@ struct Cli {
#[arg(long, env = "POCKETBASE_ADMIN_PASSWORD")]
pocketbase_admin_password: String,
/// Ollama server URL (e.g. http://ollama:11434)
#[arg(long, env = "OLLAMA_URL")]
ollama_url: String,
/// Gemini API key
#[arg(long, env = "GEMINI_API_KEY")]
gemini_api_key: String,
/// Ollama model name
#[arg(long, env = "OLLAMA_MODEL")]
ollama_model: String,
/// Gemini model name (e.g. gemini-2.0-flash)
#[arg(long, env = "GEMINI_MODEL")]
gemini_model: String,
/// Path to precomputed travel times directory (contains mode subdirs with parquet files)
#[arg(long, env = "TRAVEL_TIMES")]
@ -301,9 +301,7 @@ async fn main() -> anyhow::Result<()> {
"Precomputed features response"
);
let ai_filters_schema = routes::build_ollama_schema(&features_response);
let ai_filters_system_prompt = routes::build_system_prompt(&features_response);
info!("Precomputed AI filters schema and system prompt");
// AI filters system prompt built after travel_time_store is loaded (needs mode counts)
// Record data loading metrics
metrics::record_data_stats(
@ -331,10 +329,7 @@ async fn main() -> anyhow::Result<()> {
&cli.google_oauth_client_secret,
)
.await?;
info!(
"Ollama configured: {} (model: {})",
cli.ollama_url, cli.ollama_model
);
info!("Gemini configured (model: {})", cli.gemini_model);
let tt_path = &cli.travel_times;
if !tt_path.exists() {
bail!(
@ -352,6 +347,23 @@ async fn main() -> anyhow::Result<()> {
Arc::new(store)
};
let mode_destinations: Vec<(String, usize)> = travel_time_store
.available_modes
.iter()
.map(|mode| {
let count = travel_time_store
.destinations
.get(mode.as_str())
.map(|slugs| slugs.len())
.unwrap_or(0);
(mode.clone(), count)
})
.filter(|(_, count)| *count > 0)
.collect();
let ai_filters_system_prompt =
routes::build_system_prompt(&features_response, &mode_destinations);
info!("Precomputed AI filters system prompt");
let token_cache = Arc::new(auth::TokenCache::new());
let state = Arc::new(AppState {
@ -370,16 +382,16 @@ async fn main() -> anyhow::Result<()> {
features_response,
screenshot_url: cli.screenshot_url,
public_url: cli.public_url,
is_dev: index_html.is_none(),
index_html,
http_client,
pocketbase_url: cli.pocketbase_url,
pocketbase_admin_email: cli.pocketbase_admin_email,
pocketbase_admin_password: cli.pocketbase_admin_password,
ollama_url: cli.ollama_url,
ollama_model: cli.ollama_model,
gemini_api_key: cli.gemini_api_key,
gemini_model: cli.gemini_model,
travel_time_store,
token_cache,
ai_filters_schema,
ai_filters_system_prompt,
google_maps_api_key: cli.google_maps_api_key,
stripe_secret_key: cli.stripe_secret_key,
@ -504,7 +516,7 @@ async fn main() -> anyhow::Result<()> {
)
.route(
"/api/ai-filters",
post(move |body| routes::post_ai_filters(state_ai_filters.clone(), body))
post(move |ext, body| routes::post_ai_filters(state_ai_filters.clone(), ext, body))
.layer(ConcurrencyLimitLayer::new(5)),
)
.route(