summaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authormtul0729 <52401682+mtul0729@users.noreply.github.com>2025-03-26 08:34:00 +0800
committerGitHub <noreply@github.com>2025-03-26 08:34:00 +0800
commitdd8f3e4528d45b7602df7ea6380b92a87dc4f711 (patch)
treefaf8368ed6e06a78547959414710848ff19a06ff /src/client
parenta71e7c6be72965afd537aae076e0aee9e6f0755e (diff)
downloadaichat-dd8f3e4528d45b7602df7ea6380b92a87dc4f711.tar.gz
refactor: replace `lazy_static` with `std::sync::LazyLock` (#1246)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/access_token.rs7
-rw-r--r--src/client/common.rs19
2 files changed, 15 insertions, 11 deletions
diff --git a/src/client/access_token.rs b/src/client/access_token.rs
index 0f69d9a..e09e02c 100644
--- a/src/client/access_token.rs
+++ b/src/client/access_token.rs
@@ -2,11 +2,10 @@ use anyhow::{anyhow, Result};
use chrono::Utc;
use indexmap::IndexMap;
use parking_lot::RwLock;
+use std::sync::LazyLock;
-lazy_static::lazy_static! {
- static ref ACCESS_TOKENS: RwLock<IndexMap<String, (String, i64)>> =
- RwLock::new(IndexMap::new());
-}
+static ACCESS_TOKENS: LazyLock<RwLock<IndexMap<String, (String, i64)>>> =
+ LazyLock::new(|| RwLock::new(IndexMap::new()));
pub fn get_access_token(client_name: &str) -> Result<String> {
ACCESS_TOKENS
diff --git a/src/client/common.rs b/src/client/common.rs
index 89e0367..3b89d11 100644
--- a/src/client/common.rs
+++ b/src/client/common.rs
@@ -16,18 +16,23 @@ use inquire::{
use reqwest::{Client as ReqwestClient, RequestBuilder};
use serde::Deserialize;
use serde_json::{json, Value};
+use std::sync::LazyLock;
use std::time::Duration;
use tokio::sync::mpsc::unbounded_channel;
const MODELS_YAML: &str = include_str!("../../models.yaml");
-lazy_static::lazy_static! {
- pub static ref ALL_PROVIDER_MODELS: Vec<ProviderModels> = {
- Config::loal_models_override().ok().unwrap_or_else(|| serde_yaml::from_str(MODELS_YAML).unwrap())
- };
- static ref EMBEDDING_MODEL_RE: Regex = Regex::new(r"((^|/)(bge-|e5-|uae-|gte-|text-)|embed|multilingual|minilm)").unwrap();
- static ref ESCAPE_SLASH_RE: Regex = Regex::new(r"(?<!\\)/").unwrap();
-}
+pub static ALL_PROVIDER_MODELS: LazyLock<Vec<ProviderModels>> = LazyLock::new(|| {
+ Config::loal_models_override()
+ .ok()
+ .unwrap_or_else(|| serde_yaml::from_str(MODELS_YAML).unwrap())
+});
+
+static EMBEDDING_MODEL_RE: LazyLock<Regex> = LazyLock::new(|| {
+ Regex::new(r"((^|/)(bge-|e5-|uae-|gte-|text-)|embed|multilingual|minilm)").unwrap()
+});
+
+static ESCAPE_SLASH_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?<!\\)/").unwrap());
#[async_trait::async_trait]
pub trait Client: Sync + Send {