From 20dabf5add3d88a65332a6cb55e2ef4bdc9927f6 Mon Sep 17 00:00:00 2001 From: Wei Zhang Date: Wed, 27 Nov 2024 10:33:10 +0800 Subject: [PATCH] chore: log openai completion error --- Cargo.lock | 1 + crates/http-api-bindings/Cargo.toml | 1 + crates/http-api-bindings/src/completion/openai.rs | 11 +++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f41733878345..011eb5f01e0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1912,6 +1912,7 @@ dependencies = [ "tabby-common", "tabby-inference", "tokio", + "tracing", ] [[package]] diff --git a/crates/http-api-bindings/Cargo.toml b/crates/http-api-bindings/Cargo.toml index fa9563767951..9ac1541ba882 100644 --- a/crates/http-api-bindings/Cargo.toml +++ b/crates/http-api-bindings/Cargo.toml @@ -20,6 +20,7 @@ ollama-api-bindings = { path = "../ollama-api-bindings" } async-openai.workspace = true ratelimit = "0.10" tokio.workspace = true +tracing.workspace = true [dev-dependencies] tokio = { workspace = true, features = ["rt", "macros"] } diff --git a/crates/http-api-bindings/src/completion/openai.rs b/crates/http-api-bindings/src/completion/openai.rs index 6f1bfd024183..9be21b5d3e74 100644 --- a/crates/http-api-bindings/src/completion/openai.rs +++ b/crates/http-api-bindings/src/completion/openai.rs @@ -4,6 +4,7 @@ use futures::{stream::BoxStream, StreamExt}; use reqwest_eventsource::{Event, EventSource}; use serde::{Deserialize, Serialize}; use tabby_inference::{CompletionOptions, CompletionStream}; +use tracing::warn; use super::split_fim_prompt; @@ -100,8 +101,14 @@ impl CompletionStream for OpenAICompletionEngine { } } } - Err(_) => { - // StreamEnd + Err(e) => { + match e { + reqwest_eventsource::Error::StreamEnded => {}, + reqwest_eventsource::Error::InvalidStatusCode(code, resp) => + warn!("Error in completion event source: {}, {}", + code, resp.text().await.unwrap_or_default().replace('\n', "")), + _ => warn!("Error in completion event source: {}", e), + } break; } }