Skip to content

Commit

Permalink
fix: handle non utf-8 / utf-16 error
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys committed Nov 2, 2023
1 parent eb34850 commit acb3a33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 7 additions & 2 deletions crates/llama-cpp-bindings/src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,14 @@ class TextInferenceEngineImpl : public TextInferenceEngine {
}

if (request.multibyte_pending == 0) {
rust::String generated_text = is_eos ? "" : request.generated_text;
result.push_back({request.id, generated_text});
rust::String generated_text;
try {
generated_text = is_eos ? "" : request.generated_text;
} catch (const std::invalid_argument& e) {
fprintf(stderr, "%s:%d [%s] - ignoring non utf-8/utf-16 output\n", __FILE__, __LINE__, __func__);
}

result.push_back({request.id, generated_text});
request.generated_text.clear();
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/llama-cpp-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ impl AsyncTextInferenceEngine {

let result = match engine.as_mut().unwrap().step() {
Ok(result) => result,
Err(err) => panic!("Failed to step: {}", err),
Err(err) => {
panic!("Failed to step: {}", err)
}
};

for ffi::StepOutput { request_id, text } in result {
Expand Down

0 comments on commit acb3a33

Please sign in to comment.