fix format error

This commit is contained in:
geoffsee
2025-08-31 19:59:09 -04:00
parent 8d2b85b0b9
commit d1a7d5b28e
5 changed files with 34 additions and 43 deletions

View File

@@ -29,7 +29,7 @@ cd crates/chat-ui
This starts the development server on port 8788 with auto-reload capabilities.
### Usage
1. Start the predict-otron-9000 server: `./scripts/run_server.sh`
1. Start the predict-otron-9000 server: `./scripts/run.sh`
2. Start the chat-ui: `cd crates/chat-ui && ./run.sh`
3. Navigate to `http://localhost:8788`
4. Start chatting with your AI models!

View File

@@ -12,7 +12,6 @@ pub struct AppConfig {
impl Default for AppConfig {
fn default() -> Self {
let conf = get_configuration(Some(concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml")))
.expect("failed to read config");
@@ -41,6 +40,7 @@ pub fn create_router(leptos_options: LeptosOptions) -> Router {
.with_state(leptos_options)
}
use gloo_net::http::Request;
use leptos::prelude::*;
use leptos_meta::{provide_meta_context, MetaTags, Stylesheet, Title};
use leptos_router::{
@@ -48,7 +48,6 @@ use leptos_router::{
StaticSegment,
};
use serde::{Deserialize, Serialize};
use gloo_net::http::Request;
use web_sys::console;
// Remove spawn_local import as we'll use different approach
@@ -122,7 +121,10 @@ pub async fn fetch_models() -> Result<Vec<ModelInfo>, String> {
}
// API client function to send chat completion requests
pub async fn send_chat_completion(messages: Vec<ChatMessage>, model: String) -> Result<String, String> {
pub async fn send_chat_completion(
messages: Vec<ChatMessage>,
model: String,
) -> Result<String, String> {
let request = ChatRequest {
model,
messages,
@@ -206,20 +208,20 @@ pub fn App() -> impl IntoView {
fn ChatPage() -> impl IntoView {
// State for conversation messages
let messages = RwSignal::new(Vec::<ChatMessage>::new());
// State for current user input
let input_text = RwSignal::new(String::new());
// State for loading indicator
let is_loading = RwSignal::new(false);
// State for error messages
let error_message = RwSignal::new(Option::<String>::None);
// State for available models and selected model
let available_models = RwSignal::new(Vec::<ModelInfo>::new());
let selected_model = RwSignal::new(String::from("gemma-3-1b-it")); // Default model
// Client-side only: Fetch models on component mount
#[cfg(target_arch = "wasm32")]
{
@@ -249,7 +251,7 @@ fn ChatPage() -> impl IntoView {
role: "user".to_string(),
content: user_input.clone(),
};
messages.update(|msgs| msgs.push(user_message.clone()));
input_text.set(String::new());
is_loading.set(true);
@@ -259,11 +261,11 @@ fn ChatPage() -> impl IntoView {
#[cfg(target_arch = "wasm32")]
{
use leptos::task::spawn_local;
// Prepare messages for API call
let current_messages = messages.get();
let current_model = selected_model.get();
// Spawn async task to call API
spawn_local(async move {
match send_chat_completion(current_messages, current_model).await {
@@ -307,7 +309,7 @@ fn ChatPage() -> impl IntoView {
<h1>"Predict-Otron-9000 Chat"</h1>
<div class="model-selector">
<label for="model-select">"Model:"</label>
<select
<select
id="model-select"
prop:value=move || selected_model.get()
on:change=move |ev| {
@@ -329,7 +331,7 @@ fn ChatPage() -> impl IntoView {
</select>
</div>
</div>
<div class="chat-messages">
<For
each=move || messages.get().into_iter().enumerate()
@@ -344,7 +346,7 @@ fn ChatPage() -> impl IntoView {
}
}
/>
{move || {
if is_loading.get() {
view! {
@@ -379,7 +381,7 @@ fn ChatPage() -> impl IntoView {
on:keydown=on_key_down
class:disabled=move || is_loading.get()
/>
<button
<button
on:click=on_button_click
class:disabled=move || is_loading.get() || input_text.get().trim().is_empty()
>

View File

@@ -1,14 +1,11 @@
#[cfg(feature = "ssr")]
#[tokio::main]
async fn main() {
use axum::Router;
use chat_ui::app::*;
use leptos::logging::log;
use leptos::prelude::*;
use leptos_axum::{generate_route_list, LeptosRoutes};
use chat_ui::app::*;
let conf = get_configuration(None).expect("failed to read config");
let addr = conf.leptos_options.site_addr;
@@ -26,4 +23,4 @@ async fn main() {
#[cfg(not(feature = "ssr"))]
pub fn main() {
// no client-side main function
}
}

View File

@@ -4,27 +4,27 @@ mod middleware;
mod standalone_mode;
use crate::standalone_mode::create_standalone_router;
use axum::handler::Handler;
use axum::http::StatusCode as AxumStatusCode;
use axum::http::header;
use axum::response::IntoResponse;
use axum::routing::get;
use axum::{Router, http::Uri, response::Html, serve, ServiceExt};
use axum::{Router, ServiceExt, http::Uri, response::Html, serve};
use config::ServerConfig;
use ha_mode::create_ha_router;
use inference_engine::AppState;
use log::info;
use middleware::{MetricsLayer, MetricsLoggerFuture, MetricsStore};
use mime_guess::from_path;
use rust_embed::Embed;
use std::env;
use std::path::Component::ParentDir;
use axum::handler::Handler;
use axum::http::header;
use mime_guess::from_path;
use tokio::net::TcpListener;
use tower::MakeService;
use tower_http::classify::ServerErrorsFailureClass::StatusCode;
use tower_http::cors::{Any, CorsLayer};
use tower_http::trace::TraceLayer;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use axum::http::{StatusCode as AxumStatusCode };
use log::info;
#[derive(Embed)]
#[folder = "../../target/site"]
@@ -34,7 +34,6 @@ use log::info;
#[include = "*.ico"]
struct Asset;
async fn static_handler(uri: Uri) -> axum::response::Response {
// Strip the leading `/`
let path = uri.path().trim_start_matches('/');
@@ -49,18 +48,12 @@ async fn static_handler(uri: Uri) -> axum::response::Response {
let body = content.data.into_owned();
let mime = from_path(path).first_or_octet_stream();
(
[(header::CONTENT_TYPE, mime.as_ref())],
body,
)
.into_response()
([(header::CONTENT_TYPE, mime.as_ref())], body).into_response()
}
None => (AxumStatusCode::NOT_FOUND, "404 Not Found").into_response(),
}
}
#[tokio::main]
async fn main() {
// Initialize tracing
@@ -123,7 +116,6 @@ async fn main() {
// Create the leptos router for the web frontend
let leptos_router = chat_ui::app::create_router(leptos_config.config.leptos_options);
// Merge the service router with base routes and add middleware layers
let app = Router::new()
.route("/pkg/{*path}", get(static_handler))