Skip to content

Commit

Permalink
fix: linux build by updating
Browse files Browse the repository at this point in the history
  • Loading branch information
danielclough committed Oct 9, 2024
1 parent 7dc83b4 commit c35cefd
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 15 deletions.
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ edition = "2021"

[dependencies]
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.128"
struct_iterable = "0.1.1"
18 changes: 17 additions & 1 deletion common/src/database/user.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{fmt::Display, str::FromStr};

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand All @@ -19,7 +21,21 @@ pub struct UserForJson {
pub name: String,
pub active: bool,
}

impl Display for UserForJson {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name)
}
}
impl FromStr for UserForJson {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(UserForJson {
id: 0,
name: s.to_string(),
active: true,
})
}
}
impl UserForJson {
pub fn error() -> Self {
Self {
Expand Down
14 changes: 14 additions & 0 deletions common/src/llm/inference.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{fmt::Display, str::FromStr};

use serde::{Deserialize, Serialize};

#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -27,6 +29,18 @@ impl Default for InferenceArgsForInput {
}
}

impl FromStr for InferenceArgsForInput {
type Err = serde_json::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
serde_json::from_str(s)
}
}
impl Display for InferenceArgsForInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", serde_json::to_string(self).unwrap())
}
}

#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct InferenceArgsForJson {
pub temperature: f64,
Expand Down
15 changes: 15 additions & 0 deletions common/src/llm/model_list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{fmt::Display, str::FromStr};

use serde::{Deserialize, Serialize};
use struct_iterable::Iterable;

Expand Down Expand Up @@ -61,6 +63,19 @@ impl Default for ModelArgs {
}
}
}
impl Display for ModelArgs {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "repo_id: {}, q_lvl: {}, revision: {}, tokenizer_file: {:?}, weight_file: {:?}, quantized: {}, use_flash_attn: {}, cpu: {}", self.repo_id, self.q_lvl, self.revision, self.tokenizer_file, self.weight_file, self.quantized, self.use_flash_attn, self.cpu)
}
}
impl FromStr for ModelArgs {
type Err = serde_json::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let model_args: ModelArgs = serde_json::from_str(s)?;
Ok(model_args)
}
}

impl ModelDLList {
pub fn default() -> ModelDLList {
ModelDLList { list: vec![] }
Expand Down
4 changes: 3 additions & 1 deletion frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ console_error_panic_hook = "0.1.7"
console_log = "1.0.0"
leptos = { version = "0.6.15", features = ["csr"] }
leptos-use = { version = "0.13.5" }
leptonic = {git = "https://github.com/lpotthast/leptonic.git" }
log = "0.4.20"
web-sys = "0.3.70"
icondata = { version = "0.3" }
Expand All @@ -23,6 +22,9 @@ uuid = { version = "1.10", features = ["v4"] }

common = {path = "../common" }
leptos_icons = "0.3.1"
codee = "0.2.0"

leptonic = { git = "https://github.com/danielclough/leptonic" }

[build-dependencies]
leptonic-theme = "0.5"
14 changes: 7 additions & 7 deletions frontend/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::components::home::network_config::init_network::InitNetworkModal;
use crate::components::{index::Index, landing::index::Landing};

use codee::string::FromToStringCodec;
use common::database::user::UserForJson;
use common::llm::inference::InferenceArgsForInput;
use common::llm::model_list::ModelArgs;

use leptonic::components::{root::Root, theme::LeptonicTheme};
use leptos::*;
use leptos_use::storage::use_local_storage;
use leptos_use::utils::JsonCodec;

#[component]
pub fn App() -> impl IntoView {
Expand All @@ -22,29 +22,29 @@ pub fn App() -> impl IntoView {
// Network
//
let (database_url, set_database_url, _) =
use_local_storage::<String, JsonCodec>("database_url");
use_local_storage::<String, FromToStringCodec>("database_url");
let (_database_error, set_database_error) = create_signal(false);
let (backend_url, set_backend_url, _) = use_local_storage::<String, JsonCodec>("backend_url");
let (backend_url, set_backend_url, _) = use_local_storage::<String, FromToStringCodec>("backend_url");
let (_backend_error, set_backend_error) = create_signal(false);

// GPU
//
let (gpu_type, set_gpu_type, _) = use_local_storage::<String, JsonCodec>("gpu");
let (gpu_type, set_gpu_type, _) = use_local_storage::<String, FromToStringCodec>("gpu");
// set_gpu_type.set("None".to_string());

// User
//
let (user, set_user, _) = use_local_storage::<UserForJson, JsonCodec>("user");
let (user, set_user, _) = use_local_storage::<UserForJson, FromToStringCodec>("user");

// Model
//
let (model_args, set_model_args, _) = use_local_storage::<ModelArgs, JsonCodec>("model");
let (model_args, set_model_args, _) = use_local_storage::<ModelArgs, FromToStringCodec>("model");

// Inference Args
//
// f64 for input values
let (inference_args, set_inference_args, _) =
use_local_storage::<InferenceArgsForInput, JsonCodec>("inference");
use_local_storage::<InferenceArgsForInput, FromToStringCodec>("inference");

// View
//
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/components/chat/index.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use codee::string::FromToStringCodec;
use common::database::{
conversation::{ConversationForJson, NewConversation},
engagement::NewEngagement,
Expand All @@ -9,7 +10,7 @@ use leptonic::components::{
toast::{Toast, ToastTimeout, ToastVariant, Toasts},
};
use leptos::{html::Textarea, *};
use leptos_use::{use_websocket, UseWebsocketReturn};
use leptos_use::{use_websocket, UseWebSocketReturn};
use uuid::Uuid;
use web_sys::KeyboardEvent;

Expand Down Expand Up @@ -51,14 +52,14 @@ pub fn ChatBox(
// Instantiate addr websocket_server_address with .env or default values.
let websocket_server_address = get_llm_path("websocket", backend_url.get());

let UseWebsocketReturn {
let UseWebSocketReturn {
ready_state,
message,
send,
// open,
// close,
..
} = use_websocket(&websocket_server_address);
} = use_websocket::<String, String, FromToStringCodec>(&websocket_server_address);

let input_element: NodeRef<Input> = create_node_ref();
let textarea_element: NodeRef<Textarea> = create_node_ref();
Expand Down Expand Up @@ -116,13 +117,13 @@ pub fn ChatBox(
// register username
if username_unset.get() {
leptos_dom::log!("Trying to register username? {}", username_unset.get());
send(user.get().name.as_str());
send(&user.get().name);
leptos_dom::log!("user: {:?}", user.get());
set_time_to_send.set(false);
} else if time_to_send.get() {
// send regular messages
leptos_dom::log!("Sending now! {}", time_to_send.get());
send(input_string.get().as_str());
send(&input_string.get());
set_input_string.set(String::new());
set_time_to_send.set(false);
}
Expand Down
2 changes: 1 addition & 1 deletion tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"devUrl": "http://localhost:16982"
},
"productName": "Fireside Chat",
"version": "0.1.0-beta.16",
"version": "0.1.0-beta.17",
"identifier": "us.danielc.chat",
"plugins": {},
"app": {
Expand Down

0 comments on commit c35cefd

Please sign in to comment.