refactor: move code api to tabby/serve (#771)

extract-routes
Meng Zhang 2023-11-12 14:58:15 -08:00 committed by GitHub
parent 3a9b4d9ef5
commit febfa18e4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 27 additions and 22 deletions

View File

@ -48,6 +48,9 @@ jobs:
~/.cargo/registry ~/.cargo/registry
~/.cargo/git ~/.cargo/git
- name: Cargo Machete
uses: bnjbvr/cargo-machete@main
- run: bash ./ci/prepare_build_environment.sh - run: bash ./ci/prepare_build_environment.sh
- run: make fix - run: make fix

4
Cargo.lock generated
View File

@ -4307,6 +4307,7 @@ dependencies = [
"tabby-webserver", "tabby-webserver",
"tantivy", "tantivy",
"textdistance", "textdistance",
"thiserror",
"tokio", "tokio",
"tower-http 0.4.0", "tower-http 0.4.0",
"tracing", "tracing",
@ -4323,7 +4324,6 @@ name = "tabby-common"
version = "0.6.0-dev" version = "0.6.0-dev"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait",
"chrono", "chrono",
"filenamify", "filenamify",
"lazy_static", "lazy_static",
@ -4332,9 +4332,7 @@ dependencies = [
"serde-jsonlines", "serde-jsonlines",
"serdeconv", "serdeconv",
"tantivy", "tantivy",
"thiserror",
"tokio", "tokio",
"utoipa",
"uuid 1.4.1", "uuid 1.4.1",
] ]

View File

@ -6,7 +6,9 @@ else
endif endif
fix: fix:
cargo +nightly clippy --fix --allow-dirty --allow-staged && cargo +nightly fmt cargo machete --fix
cargo +nightly fmt
cargo +nightly clippy --fix --allow-dirty --allow-staged
fix-ui: fix-ui:
cd ee/tabby-ui && yarn format:write && yarn lint:fix cd ee/tabby-ui && yarn format:write && yarn lint:fix

View File

@ -15,9 +15,6 @@ tokio = { workspace = true, features = ["rt", "macros"] }
uuid = { version = "1.4.1", features = ["v4"] } uuid = { version = "1.4.1", features = ["v4"] }
tantivy.workspace = true tantivy.workspace = true
anyhow.workspace = true anyhow.workspace = true
async-trait.workspace = true
thiserror.workspace = true
utoipa = { workspace = true, features = ["axum_extras", "preserve_order"] }
[features] [features]
testutils = [] testutils = []

View File

@ -1 +0,0 @@
pub mod code;

View File

@ -1,4 +1,3 @@
pub mod api;
pub mod config; pub mod config;
pub mod events; pub mod events;
pub mod index; pub mod index;

View File

@ -45,6 +45,7 @@ llama-cpp-bindings = { path = "../llama-cpp-bindings" }
futures.workspace = true futures.workspace = true
async-trait.workspace = true async-trait.workspace = true
tabby-webserver = { path = "../../ee/tabby-webserver" } tabby-webserver = { path = "../../ee/tabby-webserver" }
thiserror.workspace = true
[dependencies.uuid] [dependencies.uuid]
version = "1.3.3" version = "1.3.3"

View File

@ -0,0 +1,3 @@
mod code;
pub use code::*;

View File

@ -1,3 +1,4 @@
mod api;
mod download; mod download;
mod serve; mod serve;

View File

@ -5,11 +5,13 @@ use std::sync::Arc;
use axum::{extract::State, Json}; use axum::{extract::State, Json};
use hyper::StatusCode; use hyper::StatusCode;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tabby_common::{api::code::CodeSearch, events, languages::get_language}; use tabby_common::{events, languages::get_language};
use tabby_inference::{TextGeneration, TextGenerationOptionsBuilder}; use tabby_inference::{TextGeneration, TextGenerationOptionsBuilder};
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use utoipa::ToSchema; use utoipa::ToSchema;
use crate::api::CodeSearch;
#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] #[derive(Serialize, Deserialize, ToSchema, Clone, Debug)]
#[schema(example=json!({ #[schema(example=json!({
"language": "python", "language": "python",

View File

@ -3,14 +3,12 @@ use std::sync::Arc;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use strfmt::strfmt; use strfmt::strfmt;
use tabby_common::{ use tabby_common::languages::get_language;
api::code::{CodeSearch, CodeSearchError},
languages::get_language,
};
use textdistance::Algorithm; use textdistance::Algorithm;
use tracing::warn; use tracing::warn;
use super::{Segments, Snippet}; use super::{Segments, Snippet};
use crate::api::{CodeSearch, CodeSearchError};
static MAX_SNIPPETS_TO_FETCH: usize = 20; static MAX_SNIPPETS_TO_FETCH: usize = 20;
static MAX_SNIPPET_CHARS_IN_PROMPT: usize = 768; static MAX_SNIPPET_CHARS_IN_PROMPT: usize = 768;

View File

@ -15,11 +15,7 @@ use std::{
use axum::{routing, Router, Server}; use axum::{routing, Router, Server};
use axum_tracing_opentelemetry::opentelemetry_tracing_layer; use axum_tracing_opentelemetry::opentelemetry_tracing_layer;
use clap::Args; use clap::Args;
use tabby_common::{ use tabby_common::{config::Config, usage};
api::code::{Hit, HitDocument, SearchResponse},
config::Config,
usage,
};
use tabby_download::download_model; use tabby_download::download_model;
use tabby_webserver::attach_webserver; use tabby_webserver::attach_webserver;
use tokio::time::sleep; use tokio::time::sleep;
@ -32,7 +28,11 @@ use self::{
engine::{create_engine, EngineInfo}, engine::{create_engine, EngineInfo},
health::HealthState, health::HealthState,
}; };
use crate::{fatal, services::chat::ChatService}; use crate::{
api::{Hit, HitDocument, SearchResponse},
fatal,
services::chat::ChatService,
};
#[derive(OpenApi)] #[derive(OpenApi)]
#[openapi( #[openapi(

View File

@ -7,10 +7,11 @@ use axum::{
}; };
use hyper::StatusCode; use hyper::StatusCode;
use serde::Deserialize; use serde::Deserialize;
use tabby_common::api::code::{CodeSearch, CodeSearchError, SearchResponse};
use tracing::{instrument, warn}; use tracing::{instrument, warn};
use utoipa::IntoParams; use utoipa::IntoParams;
use crate::api::{CodeSearch, CodeSearchError, SearchResponse};
#[derive(Deserialize, IntoParams)] #[derive(Deserialize, IntoParams)]
pub struct SearchQuery { pub struct SearchQuery {
#[param(default = "get")] #[param(default = "get")]

View File

@ -3,7 +3,6 @@ use std::{sync::Arc, time::Duration};
use anyhow::Result; use anyhow::Result;
use async_trait::async_trait; use async_trait::async_trait;
use tabby_common::{ use tabby_common::{
api::code::{CodeSearch, CodeSearchError, Hit, HitDocument, SearchResponse},
index::{self, register_tokenizers, CodeSearchSchema}, index::{self, register_tokenizers, CodeSearchSchema},
path, path,
}; };
@ -17,6 +16,8 @@ use tantivy::{
use tokio::{sync::Mutex, time::sleep}; use tokio::{sync::Mutex, time::sleep};
use tracing::{debug, log::info}; use tracing::{debug, log::info};
use crate::api::{CodeSearch, CodeSearchError, Hit, HitDocument, SearchResponse};
struct CodeSearchImpl { struct CodeSearchImpl {
reader: IndexReader, reader: IndexReader,
query_parser: QueryParser, query_parser: QueryParser,