Skip to content

Commit

Permalink
feat: Add warning for using CPU mode (#1219)
Browse files Browse the repository at this point in the history
* feat: Add warning for using CPU mode

* Adjust warning message and create helper function for printing formatted info messages

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* Apply suggestions

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
boxbeam and autofix-ci[bot] authored Jan 17, 2024
1 parent b75f12e commit a3e3ebc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 27 deletions.
1 change: 1 addition & 0 deletions crates/tabby-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod index;
pub mod languages;
pub mod path;
pub mod registry;
pub mod terminal;
pub mod usage;

use std::{
Expand Down
29 changes: 29 additions & 0 deletions crates/tabby-common/src/terminal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub enum HeaderFormat {
BoldWhite,
BoldBlue,
BoldYellow,
Blue,
}

impl HeaderFormat {
fn prefix(&self) -> &str {
match self {
HeaderFormat::BoldWhite => "\x1b[1m",
HeaderFormat::BoldBlue => "\x1b[34;1m",
HeaderFormat::BoldYellow => "\x1b[93;1m",
HeaderFormat::Blue => "\x1b[34m",
}
}

pub fn format(&self, header: &str) -> String {
format!("{}{header}\x1b[0m", self.prefix())
}
}

pub fn show_info(header: &str, style: HeaderFormat, content: &[&str]) {
eprintln!(" {}", style.format(header));
for line in content {
eprintln!(" {line}");
}
eprintln!();
}
33 changes: 14 additions & 19 deletions crates/tabby-common/src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use reqwest::Client;
use serde::Serialize;
use uuid::Uuid;

use crate::path::usage_id_file;
use crate::{
path::usage_id_file,
terminal::{show_info, HeaderFormat},
};

static USAGE_API_ENDPOINT: &str = "https://app.tabbyml.com/api/usage";

Expand All @@ -21,24 +24,16 @@ impl UsageTracker {
let id = Uuid::new_v4().to_string();
std::fs::write(usage_id_file(), id).expect("Failed to create usage id");

eprintln!(
"
\x1b[34;1mTELEMETRY\x1b[0m
As an open source project, we collect usage statistics to inform development priorities. For more
information, read https://tabby.tabbyml.com/docs/configuration#usage-collection
We will not see or any code in your development process.
To opt-out, add the TABBY_DISABLE_USAGE_COLLECTION=1 to your tabby server's environment variables.
\x1b[1mWelcome to Tabby!\x1b[0m
If you have any questions or would like to engage with the Tabby team, please join us on Slack
(https://links.tabbyml.com/join-slack-terminal).
"
);
show_info("TELEMETRY", HeaderFormat::BoldBlue, &[
"As an open source project, we collect usage statistics to inform development priorities. For more",
"information, read https://tabby.tabbyml.com/docs/configuration#usage-collection",
"",
"We will not see or any code in your development process."
]);
show_info("Welcome to Tabby!", HeaderFormat::BoldWhite, &[
"If you have any questions or would like to engage with the Tabby team, please join us on Slack",
"(https://links.tabbyml.com/join-slack-terminal)."
]);
}

let id = fs::read_to_string(usage_id_file()).expect("Failed to read usage id");
Expand Down
15 changes: 14 additions & 1 deletion crates/tabby/src/services/model.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::{fs, path::PathBuf, sync::Arc};

use serde::Deserialize;
use tabby_common::registry::{parse_model_id, ModelRegistry, GGML_MODEL_RELATIVE_PATH};
use tabby_common::{
registry::{parse_model_id, ModelRegistry, GGML_MODEL_RELATIVE_PATH},
terminal::{show_info, HeaderFormat},
};
use tabby_download::download_model;
use tabby_inference::TextGeneration;
use tracing::info;
Expand Down Expand Up @@ -65,6 +68,16 @@ impl PromptInfo {
}

fn create_ggml_engine(device: &Device, model_path: &str, parallelism: u8) -> impl TextGeneration {
if !device.ggml_use_gpu() {
show_info(
"CPU Device",
HeaderFormat::BoldBlue,
&[
"Tabby is currently running on the CPU. Completions may be slow, but it will suffice for testing purposes.",
"For better performance, consider deploying Tabby on a GPU device."
],
);
}
let options = llama_cpp_bindings::LlamaTextGenerationOptionsBuilder::default()
.model_path(model_path.to_owned())
.use_gpu(device.ggml_use_gpu())
Expand Down
12 changes: 5 additions & 7 deletions ee/tabby-webserver/src/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use juniper::{FieldError, GraphQLEnum, GraphQLObject, IntoFieldError, ScalarValu
use juniper_axum::relay;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use tabby_common::terminal::{show_info, HeaderFormat};
use thiserror::Error;
use tracing::{error, warn};
use uuid::Uuid;
Expand Down Expand Up @@ -42,13 +43,10 @@ pub fn validate_jwt(token: &str) -> jwt::errors::Result<JWTPayload> {

fn jwt_token_secret() -> String {
let jwt_secret = std::env::var("TABBY_WEBSERVER_JWT_TOKEN_SECRET").unwrap_or_else(|_| {
eprintln!("
\x1b[93;1mJWT secret is not set\x1b[0m
Tabby server will generate a one-time (non-persisted) JWT secret for the current process.
Please set the \x1b[94mTABBY_WEBSERVER_JWT_TOKEN_SECRET\x1b[0m environment variable for production usage.
"
);
show_info("JWT secret is not set", HeaderFormat::BoldYellow, &[
"Tabby server will generate a one-time (non-persisted) JWT secret for the current process.",
&format!("Please set the {} environment variable for production usage.", HeaderFormat::Blue.format("TABBY_WEBSERVER_JWT_TOKEN_SECRET")),
]);
Uuid::new_v4().to_string()
});

Expand Down

0 comments on commit a3e3ebc

Please sign in to comment.