variphx commited on
Commit
43270c7
·
1 Parent(s): a0f3c89

fix: refactor all constants into constants separate module

Browse files
src/constants/mod.rs ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pub const EMBEDDING_MODEL_NAME: &str = "openai/clip-vit-base-patch32";
2
+ pub const QDRANT_KEYFRAME_COLLECTION_NAME: &str = "keyframes";
3
+ pub const OPENAPI_TAG: &str = "AIC Server";
src/controllers/v1/keyframes/mod.rs CHANGED
@@ -6,7 +6,7 @@ use axum::{
6
  use utoipa_axum::{router::OpenApiRouter, routes};
7
 
8
  use crate::{
9
- docs::OPENAPI_TAG,
10
  models::{dtos::keyframes::KeyframeDto, states::AppState},
11
  services::keyframes::KeyframeService,
12
  };
 
6
  use utoipa_axum::{router::OpenApiRouter, routes};
7
 
8
  use crate::{
9
+ constants::OPENAPI_TAG,
10
  models::{dtos::keyframes::KeyframeDto, states::AppState},
11
  services::keyframes::KeyframeService,
12
  };
src/controllers/v1/vectors/keyframes/mod.rs CHANGED
@@ -2,7 +2,7 @@ use axum::{Json, extract::State, http::StatusCode};
2
  use utoipa_axum::{router::OpenApiRouter, routes};
3
 
4
  use crate::{
5
- docs::OPENAPI_TAG,
6
  models::{
7
  dtos::vectors::keyframes::{VectorizedKeyframeDto, VectorizedKeyframeRequestDto},
8
  states::AppState,
 
2
  use utoipa_axum::{router::OpenApiRouter, routes};
3
 
4
  use crate::{
5
+ constants::OPENAPI_TAG,
6
  models::{
7
  dtos::vectors::keyframes::{VectorizedKeyframeDto, VectorizedKeyframeRequestDto},
8
  states::AppState,
src/controllers/v1/videos/mod.rs CHANGED
@@ -6,7 +6,7 @@ use axum::{
6
  use utoipa_axum::{router::OpenApiRouter, routes};
7
 
8
  use crate::{
9
- docs::OPENAPI_TAG,
10
  models::{dtos::videos::VideoDto, states::AppState},
11
  services::videos::VideoService,
12
  };
 
6
  use utoipa_axum::{router::OpenApiRouter, routes};
7
 
8
  use crate::{
9
+ constants::OPENAPI_TAG,
10
  models::{dtos::videos::VideoDto, states::AppState},
11
  services::videos::VideoService,
12
  };
src/docs/mod.rs CHANGED
@@ -1,6 +1,6 @@
1
  use utoipa::OpenApi;
2
 
3
- pub const OPENAPI_TAG: &str = "AIC Server";
4
 
5
  #[derive(OpenApi)]
6
  #[openapi(
 
1
  use utoipa::OpenApi;
2
 
3
+ use crate::constants::OPENAPI_TAG;
4
 
5
  #[derive(OpenApi)]
6
  #[openapi(
src/main.rs CHANGED
@@ -18,6 +18,7 @@ use utoipa_swagger_ui::SwaggerUi;
18
 
19
  use crate::{docs::ApiDoc, models::states::AppState};
20
 
 
21
  mod controllers;
22
  mod docs;
23
  mod models;
 
18
 
19
  use crate::{docs::ApiDoc, models::states::AppState};
20
 
21
+ mod constants;
22
  mod controllers;
23
  mod docs;
24
  mod models;
src/models/states/mod.rs CHANGED
@@ -13,7 +13,7 @@ use hf_hub::api::tokio::ApiRepo;
13
  use qdrant_client::Qdrant;
14
  use tokenizers::Tokenizer;
15
 
16
- const MODEL_NAME: &str = "openai/clip-vit-base-patch32";
17
 
18
  #[derive(Clone)]
19
  pub struct AppState {
@@ -26,7 +26,7 @@ pub struct AppState {
26
 
27
  impl AppState {
28
  pub async fn new() -> anyhow::Result<Self> {
29
- let api = hf_hub::api::tokio::Api::new()?.model(MODEL_NAME.to_owned());
30
  let device = Device::cuda_if_available(0)?;
31
 
32
  Ok(Self {
@@ -47,9 +47,8 @@ impl AppState {
47
  }
48
 
49
  fn qdrant_client_helper() -> anyhow::Result<Arc<Qdrant>> {
50
- Ok(Arc::new(
51
- Qdrant::from_url(&std::env::var("QDRANT_URL")?).build()?,
52
- ))
53
  }
54
 
55
  async fn model_helper(api: &ApiRepo, device: &Device) -> anyhow::Result<Arc<ClipModel>> {
 
13
  use qdrant_client::Qdrant;
14
  use tokenizers::Tokenizer;
15
 
16
+ use crate::constants::EMBEDDING_MODEL_NAME;
17
 
18
  #[derive(Clone)]
19
  pub struct AppState {
 
26
 
27
  impl AppState {
28
  pub async fn new() -> anyhow::Result<Self> {
29
+ let api = hf_hub::api::tokio::Api::new()?.model(EMBEDDING_MODEL_NAME.to_owned());
30
  let device = Device::cuda_if_available(0)?;
31
 
32
  Ok(Self {
 
47
  }
48
 
49
  fn qdrant_client_helper() -> anyhow::Result<Arc<Qdrant>> {
50
+ let client = Qdrant::from_url(&std::env::var("QDRANT_URL")?).build()?;
51
+ Ok(Arc::new(client))
 
52
  }
53
 
54
  async fn model_helper(api: &ApiRepo, device: &Device) -> anyhow::Result<Arc<ClipModel>> {