Skip to content

Commit

Permalink
chore(tabby): Reduce usage of unwrap in the tabby crate (#1465)
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam authored Feb 17, 2024
1 parent 1ab58a2 commit 575ec4a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/tabby/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn init_logging(otlp_endpoint: Option<String>) {

if let Ok(tracer) = tracer {
layers.push(tracing_opentelemetry::layer().with_tracer(tracer).boxed());
axum_tracing_opentelemetry::init_propagator().unwrap();
axum_tracing_opentelemetry::init_propagator().expect("Initializing telemetry");
};
}

Expand Down
4 changes: 3 additions & 1 deletion crates/tabby/src/services/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ impl ChatService {
if let Some(temperature) = temperature {
builder.sampling_temperature(temperature);
}
builder.build().unwrap()
builder
.build()
.expect("Failed to create text generation options")
}

pub async fn generate<'a>(
Expand Down
2 changes: 1 addition & 1 deletion crates/tabby/src/services/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl CodeSearch for CodeSearchImpl {
fn get_field(doc: &Document, field: Field) -> String {
doc.get_first(field)
.and_then(|x| x.as_text())
.unwrap()
.expect("Missing field")
.to_owned()
}

Expand Down
4 changes: 3 additions & 1 deletion crates/tabby/src/services/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ impl CompletionService {
if let Some(temperature) = temperature {
builder.sampling_temperature(temperature);
}
builder.build().unwrap()
builder
.build()
.expect("Failed to create text generation options")
}

pub async fn generate(
Expand Down
13 changes: 3 additions & 10 deletions crates/tabby/src/services/completion/completion_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,9 @@ impl PromptBuilder {
}

fn get_default_suffix(suffix: Option<String>) -> String {
if suffix.is_none() {
return "\n".to_owned();
}

let suffix = suffix.unwrap();
if suffix.is_empty() {
"\n".to_owned()
} else {
suffix
}
suffix
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "\n".to_string())
}

fn rewrite_with_snippets(language: &str, segments: Segments, snippets: &[Snippet]) -> Segments {
Expand Down
2 changes: 1 addition & 1 deletion crates/tabby/src/services/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn create_ggml_engine(device: &Device, model_path: &str, parallelism: u8) -> imp
.use_gpu(device.ggml_use_gpu())
.parallelism(parallelism)
.build()
.unwrap();
.expect("Failed to create llama text generation options");

make_text_generation(llama_cpp_bindings::LlamaTextGeneration::new(options))
}
Expand Down
9 changes: 6 additions & 3 deletions crates/tabby/tests/goldentests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ fn workspace_dir() -> PathBuf {
.output()
.unwrap()
.stdout;
let cargo_path = std::path::Path::new(std::str::from_utf8(&output).unwrap().trim());
cargo_path.parent().unwrap().to_path_buf()
let cargo_path = std::path::Path::new(std::str::from_utf8(&output).expect("Valid path").trim());
cargo_path
.parent()
.expect("Path must have a parent folder")
.to_path_buf()
}

fn tabby_path() -> PathBuf {
Expand All @@ -46,7 +49,7 @@ fn initialize_server(gpu_device: Option<&str>) {
.expect("Failed to start server")
.wait()
.await
.unwrap();
.expect("Failed to start server");
});
}

Expand Down

0 comments on commit 575ec4a

Please sign in to comment.