Skip to content

Commit

Permalink
Use custom axum fork to fix sse leading space.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryscan committed Jul 22, 2023
1 parent 1617b09 commit 5a16143
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ exclude = ["assets"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = "0.6.11"
axum = { git = "https://github.com/cryscan/axum", branch = "sse-leading-space" }
tower-http = { version = "0.4", features = ["full"] }
tokio = { version = "1", features = ["full"] }
web-rwkv = { git = "https://github.com/cryscan/web-rwkv" }
web-rwkv = "0.1.12"
memmap = "0.7"
clap = { version = "4.3", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub async fn chat_completions_stream(
finish_reason,
..Default::default()
},
Token::Done => return Ok(Event::default().data(" [DONE]")),
Token::Done => return Ok(Event::default().data("[DONE]")),
_ => unreachable!(),
};

Expand All @@ -232,7 +232,7 @@ pub async fn chat_completions_stream(
model: model_name.clone(),
choices: vec![choice],
})?;
Ok(Event::default().data(format!(" {json}")))
Ok(Event::default().data(json))
});

Sse::new(stream)
Expand Down
4 changes: 2 additions & 2 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub async fn completions_stream(
finish_reason,
..Default::default()
},
Token::Done => return Ok(Event::default().data(" [DONE]")),
Token::Done => return Ok(Event::default().data("[DONE]")),
_ => unreachable!(),
};

Expand All @@ -185,7 +185,7 @@ pub async fn completions_stream(
model: model_name.clone(),
choices: vec![choice],
})?;
Ok(Event::default().data(format!(" {json}")))
Ok(Event::default().data(json))
});

Sse::new(stream)
Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::{
ffi::OsStr,
fs::File,
io::{BufReader, Read, Write},
net::SocketAddr,
path::PathBuf,
str::FromStr,
};
Expand Down Expand Up @@ -324,9 +325,10 @@ async fn main() -> Result<()> {
.route("/embeddings", post(embedding::embeddings))
.route("/v1/embeddings", post(embedding::embeddings))
.with_state(ThreadState { sender, model_name });
axum::Server::bind(&format!("0.0.0.0:{0}", args.port).parse().unwrap())
.serve(app.into_make_service())
.await?;

let addr = SocketAddr::from(([127, 0, 0, 1], args.port));
let listener = tokio::net::TcpListener::bind(addr).await?;
axum::serve(listener, app).await?;

Ok(())
}

0 comments on commit 5a16143

Please sign in to comment.