Skip to content

Commit

Permalink
Revert "feat: make --model optional (#668)"
Browse files Browse the repository at this point in the history
This reverts commit c55e448.
  • Loading branch information
wsxiaoys authored Oct 30, 2023
1 parent f991b8b commit 9f85c0b
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 54 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* Switch cpu backend to llama.cpp: https://github.com/TabbyML/tabby/pull/638
* add `server.completion_timeout` to control the code completion interface timeout: https://github.com/TabbyML/tabby/pull/637
* Switch cuda backend to llama.cpp: https://github.com/TabbyML/tabby/pull/656
* Make `--model` optional, so users can create a chat only instance.

# v0.4.0

Expand Down
2 changes: 1 addition & 1 deletion crates/tabby/src/serve/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use utoipa::ToSchema;

#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)]
pub struct HealthState {
model: Option<String>,
model: String,
#[serde(skip_serializing_if = "Option::is_none")]
chat_model: Option<String>,
device: String,
Expand Down
49 changes: 15 additions & 34 deletions crates/tabby/src/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Device {
pub struct ServeArgs {
/// Model id for `/completions` API endpoint.
#[clap(long)]
model: Option<String>,
model: String,

/// Model id for `/chat/completions` API endpoints.
#[clap(long)]
Expand All @@ -129,9 +129,7 @@ pub async fn main(config: &Config, args: &ServeArgs) {
valid_args(args);

if args.device != Device::ExperimentalHttp {
if let Some(model) = &args.model {
download_model(model).await;
}
download_model(&args.model).await;
if let Some(chat_model) = &args.chat_model {
download_model(chat_model).await;
}
Expand Down Expand Up @@ -173,22 +171,20 @@ pub async fn main(config: &Config, args: &ServeArgs) {

fn api_router(args: &ServeArgs, config: &Config) -> Router {
let index_server = Arc::new(IndexServer::new());
let completion_state = if let Some(model) = &args.model {
let completion_state = {
let (
engine,
EngineInfo {
prompt_template, ..
},
) = create_engine(model, args);
) = create_engine(&args.model, args);
let engine = Arc::new(engine);
let state = completions::CompletionState::new(
engine.clone(),
index_server.clone(),
prompt_template,
);
Some(Arc::new(state))
} else {
None
Arc::new(state)
};

let chat_state = if let Some(chat_model) = &args.chat_model {
Expand Down Expand Up @@ -219,18 +215,16 @@ fn api_router(args: &ServeArgs, config: &Config) -> Router {
)
});

if let Some(completion_state) = completion_state {
routers.push({
Router::new()
.route(
"/v1/completions",
routing::post(completions::completions).with_state(completion_state),
)
.layer(TimeoutLayer::new(Duration::from_secs(
config.server.completion_timeout,
)))
});
}
routers.push({
Router::new()
.route(
"/v1/completions",
routing::post(completions::completions).with_state(completion_state),
)
.layer(TimeoutLayer::new(Duration::from_secs(
config.server.completion_timeout,
)))
});

if let Some(chat_state) = chat_state {
routers.push({
Expand Down Expand Up @@ -285,19 +279,6 @@ trait OpenApiOverride {

impl OpenApiOverride for utoipa::openapi::OpenApi {
fn override_doc(&mut self, args: &ServeArgs) {
if args.model.is_none() {
self.paths.paths.remove("/v1/completions");
if let Some(components) = self.components.as_mut() {
components.schemas.remove("CompletionRequest");
components.schemas.remove("CompletionResponse");
components.schemas.remove("Choice");
components.schemas.remove("DebugData");
components.schemas.remove("DebugOptions");
components.schemas.remove("Segments");
components.schemas.remove("Snippet");
}
}

if args.chat_model.is_none() {
self.paths.paths.remove("/v1beta/chat/completions");

Expand Down
2 changes: 1 addition & 1 deletion crates/tabby/ui/404.html

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9f85c0b

Please sign in to comment.