Skip to content

Commit

Permalink
return first streaming error as http error
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Nov 5, 2024
1 parent 3fa443f commit db6ca7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 12 additions & 0 deletions llgtrt/src/routes/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,23 @@ impl ReqInfo {
async fn completions_stream(
mut client: ReqInfo,
) -> Result<Sse<impl Stream<Item = anyhow::Result<Event>>>, AppError> {
let result0 = client
.recv
.recv()
.await
.ok_or_else(|| anyhow!("no response"))?;
if let Some(err) = result0.response.error {
// return as HTTP error, not error event
return Err(anyhow!("{}", err).into());
}

let response_stream = try_stream! {
if client.is_run {
yield client.initial_run();
}

yield client.resp_to_event(result0);

while let Some(result) = client.recv.recv().await {
let is_error = result.response.error.is_some();
yield client.resp_to_event(result);
Expand Down
11 changes: 6 additions & 5 deletions scripts/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import time
import argparse

PROMPT_SIZE = 5
PROMPT_SIZE = 50_000
NUM_THREADS = 10
NUM_REPS = 3
LLG = False
Expand Down Expand Up @@ -167,7 +167,8 @@ def send_one_stream(data: dict) -> list[Results]:
break
data = json.loads(line)
if data.get("error", None):
res.error = json.dumps(data["error"])
print("ERROR", data)
results[0].error = json.dumps(data["error"])
break

if data["object"] == "initial-run":
Expand Down Expand Up @@ -283,10 +284,10 @@ def csv_line(lst):
d = req_data()
d["n"] = 1
d["temperature"] = 1.0
d["max_tokens"] = 100
d["logprobs"] = True
d["max_tokens"] = 10
# d["logprobs"] = True
# d["stop"] = ["Xked", "d ask"]
if True:
if False:
print(send_one(d))
else:
d["llg_log_level"] = "json"
Expand Down

0 comments on commit db6ca7a

Please sign in to comment.