feat: only show /v1/chat api if --chat-model is set (#498)
parent
f05dd3a2f6
commit
80a17aea37
|
|
@ -0,0 +1 @@
|
|||
NEXT_PUBLIC_TABBY_SERVER_URL=http://127.0.0.1:8080
|
||||
|
|
@ -4,7 +4,7 @@ import { TabbyStream } from '@/lib/tabby-stream'
|
|||
import { useEffect } from 'react'
|
||||
|
||||
const serverUrl =
|
||||
process.env.NEXT_PUBLIC_TABBY_SERVER_URL || 'http://localhost:8080'
|
||||
process.env.NEXT_PUBLIC_TABBY_SERVER_URL || ''
|
||||
|
||||
export function usePatchFetch() {
|
||||
useEffect(() => {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,13 +1,13 @@
|
|||
1:HL["/playground/_next/static/media/86fdec36ddd9097e-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}]
|
||||
2:HL["/playground/_next/static/media/c9a5bc6a7c948fb0-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}]
|
||||
3:HL["/playground/_next/static/css/d091dc2da2a795e4.css","style"]
|
||||
0:["9a4m76mRTGOnagTYXSPKd",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],"$L4",[[["$","link","0",{"rel":"stylesheet","href":"/playground/_next/static/css/d091dc2da2a795e4.css","precedence":"next"}]],"$L5"]]]]
|
||||
0:["DttDCgJnB6_eQ0H4kMFI8",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],"$L4",[[["$","link","0",{"rel":"stylesheet","href":"/playground/_next/static/css/d091dc2da2a795e4.css","precedence":"next"}]],"$L5"]]]]
|
||||
6:I{"id":5925,"chunks":["346:static/chunks/346-c4227fa5fd95e485.js","524:static/chunks/524-6309ecb76a77fdcf.js","185:static/chunks/app/layout-38d79c8bb16c51be.js"],"name":"Toaster","async":false}
|
||||
7:I{"id":78495,"chunks":["346:static/chunks/346-c4227fa5fd95e485.js","524:static/chunks/524-6309ecb76a77fdcf.js","185:static/chunks/app/layout-38d79c8bb16c51be.js"],"name":"Providers","async":false}
|
||||
8:I{"id":78963,"chunks":["346:static/chunks/346-c4227fa5fd95e485.js","524:static/chunks/524-6309ecb76a77fdcf.js","185:static/chunks/app/layout-38d79c8bb16c51be.js"],"name":"Header","async":false}
|
||||
9:I{"id":81443,"chunks":["272:static/chunks/webpack-e23fff8c5b5084ca.js","971:static/chunks/fd9d1056-5dfc77aa37d8c76f.js","864:static/chunks/864-1669531662d5540a.js"],"name":"","async":false}
|
||||
a:I{"id":18639,"chunks":["272:static/chunks/webpack-e23fff8c5b5084ca.js","971:static/chunks/fd9d1056-5dfc77aa37d8c76f.js","864:static/chunks/864-1669531662d5540a.js"],"name":"","async":false}
|
||||
c:I{"id":10413,"chunks":["346:static/chunks/346-c4227fa5fd95e485.js","978:static/chunks/978-342eae78521d80e5.js","524:static/chunks/524-6309ecb76a77fdcf.js","931:static/chunks/app/page-2ebc2d344df80bd2.js"],"name":"Chat","async":false}
|
||||
c:I{"id":10413,"chunks":["346:static/chunks/346-c4227fa5fd95e485.js","302:static/chunks/302-3913277f61891f44.js","524:static/chunks/524-6309ecb76a77fdcf.js","931:static/chunks/app/page-9f3e177623a8fc2f.js"],"name":"Chat","async":false}
|
||||
5:[["$","meta","0",{"charSet":"utf-8"}],["$","title","1",{"children":"Tabby Playground"}],["$","meta","2",{"name":"description","content":"Tabby, an opensource, self-hosted AI coding assistant."}],["$","meta","3",{"name":"theme-color","media":"(prefers-color-scheme: light)","content":"white"}],["$","meta","4",{"name":"theme-color","media":"(prefers-color-scheme: dark)","content":"black"}],["$","meta","5",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","6",{"name":"next-size-adjust"}]]
|
||||
4:[null,["$","html",null,{"lang":"en","suppressHydrationWarning":true,"children":[["$","head",null,{}],["$","body",null,{"className":"font-sans antialiased __variable_4e6684 __variable_3d950d","children":[["$","$L6",null,{}],["$","$L7",null,{"attribute":"class","defaultTheme":"system","enableSystem":true,"children":[["$","div",null,{"className":"flex flex-col min-h-screen","children":[["$","$L8",null,{}],["$","main",null,{"className":"flex flex-col flex-1 bg-muted/50","children":["$","$L9",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","template":["$","$La",null,{}],"templateStyles":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"childProp":{"current":["$Lb",["$","$Lc",null,{"id":"Z43ogQe"}],null],"segment":"__PAGE__"},"styles":[]}]}]]}],null]}]]}]]}],null]
|
||||
4:[null,["$","html",null,{"lang":"en","suppressHydrationWarning":true,"children":[["$","head",null,{}],["$","body",null,{"className":"font-sans antialiased __variable_4e6684 __variable_3d950d","children":[["$","$L6",null,{}],["$","$L7",null,{"attribute":"class","defaultTheme":"system","enableSystem":true,"children":[["$","div",null,{"className":"flex flex-col min-h-screen","children":[["$","$L8",null,{}],["$","main",null,{"className":"flex flex-col flex-1 bg-muted/50","children":["$","$L9",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","template":["$","$La",null,{}],"templateStyles":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"childProp":{"current":["$Lb",["$","$Lc",null,{"id":"5aAK2M3"}],null],"segment":"__PAGE__"},"styles":[]}]}]]}],null]}]]}]]}],null]
|
||||
b:null
|
||||
|
|
|
|||
|
|
@ -14,7 +14,10 @@ use std::{
|
|||
use axum::{routing, Router, Server};
|
||||
use axum_tracing_opentelemetry::opentelemetry_tracing_layer;
|
||||
use clap::Args;
|
||||
use tabby_common::{config::Config, usage};
|
||||
use tabby_common::{
|
||||
config::{Config, SwaggerConfig},
|
||||
usage,
|
||||
};
|
||||
use tabby_download::Downloader;
|
||||
use tokio::time::sleep;
|
||||
use tower_http::cors::CorsLayer;
|
||||
|
|
@ -158,8 +161,9 @@ pub async fn main(config: &Config, args: &ServeArgs) {
|
|||
|
||||
info!("Starting server, this might takes a few minutes...");
|
||||
|
||||
let doc = add_localhost_server(ApiDoc::openapi(), args.port);
|
||||
let doc = add_proxy_server(doc, config.swagger.server_url.clone());
|
||||
let mut doc = ApiDoc::openapi();
|
||||
doc.override_doc(args, &config.swagger);
|
||||
|
||||
let app = Router::new()
|
||||
.merge(api_router(args, config))
|
||||
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", doc))
|
||||
|
|
@ -259,42 +263,6 @@ fn start_heartbeat(args: &ServeArgs) {
|
|||
});
|
||||
}
|
||||
|
||||
fn add_localhost_server(doc: utoipa::openapi::OpenApi, port: u16) -> utoipa::openapi::OpenApi {
|
||||
let mut doc = doc;
|
||||
if let Some(servers) = doc.servers.as_mut() {
|
||||
servers.push(
|
||||
ServerBuilder::new()
|
||||
.url(format!("http://localhost:{}", port))
|
||||
.description(Some("Local server"))
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
doc
|
||||
}
|
||||
|
||||
fn add_proxy_server(
|
||||
doc: utoipa::openapi::OpenApi,
|
||||
server_url: Option<String>,
|
||||
) -> utoipa::openapi::OpenApi {
|
||||
if server_url.is_none() {
|
||||
return doc;
|
||||
}
|
||||
|
||||
let server_url: String = server_url.unwrap();
|
||||
let mut doc = doc;
|
||||
if let Some(servers) = doc.servers.as_mut() {
|
||||
servers.push(
|
||||
ServerBuilder::new()
|
||||
.url(server_url)
|
||||
.description(Some("Swagger Server"))
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
doc
|
||||
}
|
||||
|
||||
async fn download_model(model: &str, device: &Device) {
|
||||
let downloader = Downloader::new(model, /* prefer_local_file= */ true);
|
||||
let handler = |err| fatal!("Failed to fetch model '{}' due to '{}'", model, err,);
|
||||
|
|
@ -306,3 +274,39 @@ async fn download_model(model: &str, device: &Device) {
|
|||
|
||||
download_result.unwrap_or_else(handler);
|
||||
}
|
||||
|
||||
trait OpenApiOverride {
|
||||
fn override_doc(&mut self, args: &ServeArgs, config: &SwaggerConfig);
|
||||
}
|
||||
|
||||
impl OpenApiOverride for utoipa::openapi::OpenApi {
|
||||
fn override_doc(&mut self, args: &ServeArgs, config: &SwaggerConfig) {
|
||||
if let Some(servers) = self.servers.as_mut() {
|
||||
servers.push(
|
||||
ServerBuilder::new()
|
||||
.url(format!("http://localhost:{}", args.port))
|
||||
.description(Some("Local server"))
|
||||
.build(),
|
||||
);
|
||||
|
||||
if let Some(server_url) = &config.server_url {
|
||||
servers.push(
|
||||
ServerBuilder::new()
|
||||
.url(server_url)
|
||||
.description(Some("Swagger Server"))
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if args.chat_model.is_none() {
|
||||
self.paths.paths.remove("/v1beta/chat/completions");
|
||||
|
||||
if let Some(components) = self.components.as_mut() {
|
||||
components.schemas.remove("ChatCompletionRequest");
|
||||
components.schemas.remove("ChatCompletionChunk");
|
||||
components.schemas.remove("Message");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue