fix issue 45 - use SystemTime instead of instant for unauthenticated warning (#100)
Some checks failed
test / testbed (map[key:cached name:jaemk/cached node:false parallel:4 python:false]) (push) Has been cancelled
test / testbed (map[key:async-executor name:smol-rs/async-executor node:false parallel:4 python:false]) (push) Has been cancelled
test / testbed (map[key:constrandom name:tkaitchuck/constrandom node:false parallel:8 python:false]) (push) Has been cancelled
test / testbed (map[key:fastapi name:tiangolo/fastapi node:false parallel:8 python:true]) (push) Has been cancelled
test / testbed (map[key:helix name:helix-editor/helix node:false parallel:2 python:false]) (push) Has been cancelled
test / testbed (map[key:huggingface_hub name:huggingface/huggingface_hub node:false parallel:8 python:true]) (push) Has been cancelled
test / testbed (map[key:io-ts name:gcanti/io-ts node:true parallel:8 python:false]) (push) Has been cancelled
test / testbed (map[key:lancedb name:lancedb/lancedb node:false parallel:2 python:false]) (push) Has been cancelled
test / testbed (map[key:picklescan name:mmaitre314/picklescan node:false parallel:8 python:true]) (push) Has been cancelled
test / testbed (map[key:simple name:simple node:false parallel:8 python:false]) (push) Has been cancelled
test / testbed (map[key:starlette name:encode/starlette node:false parallel:8 python:true]) (push) Has been cancelled
test / testbed (map[key:zod name:colinhacks/zod node:true parallel:8 python:false]) (push) Has been cancelled
test / comment_results (push) Has been cancelled

Co-authored-by: Teofanovic Stefan <stefan.teofanovic@hes-so.ch>
This commit is contained in:
Stefan Teofanovic 2024-07-08 10:53:51 +02:00 committed by GitHub
parent 479401f3a5
commit 59febfea52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,7 +9,7 @@ use std::collections::HashMap;
use std::fmt::Display; use std::fmt::Display;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant, SystemTime};
use tokenizers::Tokenizer; use tokenizers::Tokenizer;
use tokio::io::AsyncWriteExt; use tokio::io::AsyncWriteExt;
use tokio::net::TcpListener; use tokio::net::TcpListener;
@ -134,7 +134,7 @@ struct LlmService {
unsafe_http_client: reqwest::Client, unsafe_http_client: reqwest::Client,
workspace_folders: Arc<RwLock<Option<Vec<WorkspaceFolder>>>>, workspace_folders: Arc<RwLock<Option<Vec<WorkspaceFolder>>>>,
tokenizer_map: Arc<RwLock<HashMap<String, Arc<Tokenizer>>>>, tokenizer_map: Arc<RwLock<HashMap<String, Arc<Tokenizer>>>>,
unauthenticated_warn_at: Arc<RwLock<Instant>>, unauthenticated_warn_at: Arc<RwLock<SystemTime>>,
position_encoding: Arc<RwLock<document::PositionEncodingKind>>, position_encoding: Arc<RwLock<document::PositionEncodingKind>>,
} }
@ -524,13 +524,13 @@ impl LlmService {
"received completion request", "received completion request",
); );
if params.api_token.is_none() && params.backend.is_using_inference_api() { if params.api_token.is_none() && params.backend.is_using_inference_api() {
let now = Instant::now(); let now = SystemTime::now();
let unauthenticated_warn_at = self.unauthenticated_warn_at.read().await; let unauthenticated_warn_at = self.unauthenticated_warn_at.read().await;
if now.duration_since(*unauthenticated_warn_at) > MAX_WARNING_REPEAT { if now.duration_since(*unauthenticated_warn_at).unwrap_or_default() > MAX_WARNING_REPEAT {
drop(unauthenticated_warn_at); drop(unauthenticated_warn_at);
self.client.show_message(MessageType::WARNING, "You are currently unauthenticated and will get rate limited. To reduce rate limiting, login with your API Token and consider subscribing to PRO: https://huggingface.co/pricing#pro").await; self.client.show_message(MessageType::WARNING, "You are currently unauthenticated and will get rate limited. To reduce rate limiting, login with your API Token and consider subscribing to PRO: https://huggingface.co/pricing#pro").await;
let mut unauthenticated_warn_at = self.unauthenticated_warn_at.write().await; let mut unauthenticated_warn_at = self.unauthenticated_warn_at.write().await;
*unauthenticated_warn_at = Instant::now(); *unauthenticated_warn_at = SystemTime::now();
} }
} }
let completion_type = should_complete(document, params.text_document_position.position)?; let completion_type = should_complete(document, params.text_document_position.position)?;
@ -767,9 +767,9 @@ async fn main() {
workspace_folders: Arc::new(RwLock::new(None)), workspace_folders: Arc::new(RwLock::new(None)),
tokenizer_map: Arc::new(RwLock::new(HashMap::new())), tokenizer_map: Arc::new(RwLock::new(HashMap::new())),
unauthenticated_warn_at: Arc::new(RwLock::new( unauthenticated_warn_at: Arc::new(RwLock::new(
Instant::now() SystemTime::now()
.checked_sub(MAX_WARNING_REPEAT) .checked_sub(MAX_WARNING_REPEAT)
.expect("instant to be in bounds"), .unwrap_or(SystemTime::now()),
)), )),
}) })
.custom_method("llm-ls/getCompletions", LlmService::get_completions) .custom_method("llm-ls/getCompletions", LlmService::get_completions)