lift api into sub packages

extract-routes
Meng Zhang 2023-11-12 21:26:31 -08:00
parent 5b502c452f
commit a0f7a8b91c
8 changed files with 19 additions and 18 deletions

View File

@ -1,5 +1,2 @@
mod code; pub mod code;
mod event; pub mod event;
pub use code::*;
pub use event::*;

View File

@ -7,7 +7,7 @@ use axum::{
use hyper::StatusCode; use hyper::StatusCode;
use utoipa::ToSchema; use utoipa::ToSchema;
use crate::api::{Event, EventLogger, LogEventRequest, SelectKind}; use crate::api::event::{Event, EventLogger, LogEventRequest, SelectKind};
#[utoipa::path( #[utoipa::path(
post, post,

View File

@ -10,7 +10,7 @@ use serde::Deserialize;
use tracing::{instrument, warn}; use tracing::{instrument, warn};
use utoipa::IntoParams; use utoipa::IntoParams;
use crate::api::{CodeSearch, CodeSearchError, SearchResponse}; use crate::api::code::{CodeSearch, CodeSearchError, SearchResponse};
#[derive(Deserialize, IntoParams)] #[derive(Deserialize, IntoParams)]
pub struct SearchQuery { pub struct SearchQuery {

View File

@ -42,7 +42,7 @@ Install following IDE / Editor extensions to get started with [Tabby](https://gi
), ),
paths(routes::log_event, routes::completions, routes::completions, routes::health, routes::search), paths(routes::log_event, routes::completions, routes::completions, routes::health, routes::search),
components(schemas( components(schemas(
api::LogEventRequest, api::event::LogEventRequest,
completions::CompletionRequest, completions::CompletionRequest,
completions::CompletionResponse, completions::CompletionResponse,
completions::Segments, completions::Segments,
@ -55,9 +55,9 @@ Install following IDE / Editor extensions to get started with [Tabby](https://gi
chat::ChatCompletionChunk, chat::ChatCompletionChunk,
health::HealthState, health::HealthState,
health::Version, health::Version,
api::SearchResponse, api::code::SearchResponse,
api::Hit, api::code::Hit,
api::HitDocument api::code::HitDocument
)) ))
)] )]
struct ApiDoc; struct ApiDoc;

View File

@ -16,7 +16,7 @@ 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}; use crate::api::code::{CodeSearch, CodeSearchError, Hit, HitDocument, SearchResponse};
struct CodeSearchImpl { struct CodeSearchImpl {
reader: IndexReader, reader: IndexReader,

View File

@ -9,7 +9,11 @@ use thiserror::Error;
use tracing::debug; use tracing::debug;
use utoipa::ToSchema; use utoipa::ToSchema;
use crate::api::{self, CodeSearch, Event, EventLogger}; use crate::api::{
self,
code::CodeSearch,
event::{Event, EventLogger},
};
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum CompletionError { pub enum CompletionError {
@ -95,9 +99,9 @@ pub struct Segments {
suffix: Option<String>, suffix: Option<String>,
} }
impl From<Segments> for api::Segments { impl From<Segments> for api::event::Segments {
fn from(val: Segments) -> Self { fn from(val: Segments) -> Self {
api::Segments { Self {
prefix: val.prefix, prefix: val.prefix,
suffix: val.suffix, suffix: val.suffix,
} }
@ -234,7 +238,7 @@ impl CompletionService {
language: &language, language: &language,
prompt: &prompt, prompt: &prompt,
segments: &segments, segments: &segments,
choices: vec![api::Choice { choices: vec![api::event::Choice {
index: 0, index: 0,
text: &text, text: &text,
}], }],

View File

@ -8,7 +8,7 @@ use textdistance::Algorithm;
use tracing::warn; use tracing::warn;
use super::{Segments, Snippet}; use super::{Segments, Snippet};
use crate::api::{CodeSearch, CodeSearchError}; use crate::api::code::{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

@ -13,7 +13,7 @@ use tokio::{
time::{self}, time::{self},
}; };
use crate::api::{Event, EventLogger}; use crate::api::event::{Event, EventLogger};
lazy_static! { lazy_static! {
static ref WRITER: UnboundedSender<String> = { static ref WRITER: UnboundedSender<String> = {