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;
mod event;
pub use code::*;
pub use event::*;
pub mod code;
pub mod event;

View File

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

View File

@ -10,7 +10,7 @@ use serde::Deserialize;
use tracing::{instrument, warn};
use utoipa::IntoParams;
use crate::api::{CodeSearch, CodeSearchError, SearchResponse};
use crate::api::code::{CodeSearch, CodeSearchError, SearchResponse};
#[derive(Deserialize, IntoParams)]
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),
components(schemas(
api::LogEventRequest,
api::event::LogEventRequest,
completions::CompletionRequest,
completions::CompletionResponse,
completions::Segments,
@ -55,9 +55,9 @@ Install following IDE / Editor extensions to get started with [Tabby](https://gi
chat::ChatCompletionChunk,
health::HealthState,
health::Version,
api::SearchResponse,
api::Hit,
api::HitDocument
api::code::SearchResponse,
api::code::Hit,
api::code::HitDocument
))
)]
struct ApiDoc;

View File

@ -16,7 +16,7 @@ use tantivy::{
use tokio::{sync::Mutex, time::sleep};
use tracing::{debug, log::info};
use crate::api::{CodeSearch, CodeSearchError, Hit, HitDocument, SearchResponse};
use crate::api::code::{CodeSearch, CodeSearchError, Hit, HitDocument, SearchResponse};
struct CodeSearchImpl {
reader: IndexReader,

View File

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

View File

@ -8,7 +8,7 @@ use textdistance::Algorithm;
use tracing::warn;
use super::{Segments, Snippet};
use crate::api::{CodeSearch, CodeSearchError};
use crate::api::code::{CodeSearch, CodeSearchError};
static MAX_SNIPPETS_TO_FETCH: usize = 20;
static MAX_SNIPPET_CHARS_IN_PROMPT: usize = 768;

View File

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