Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only warn of rate-limits when using HF endpoint #58

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/llm-ls/src/adaptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ fn parse_openai_text(text: &str) -> Result<Vec<Generation>, jsonrpc::Error> {
}
}

const TGI: &str = "tgi";
const HUGGING_FACE: &str = "huggingface";
const OLLAMA: &str = "ollama";
const OPENAI: &str = "openai";
const DEFAULT_ADAPTOR: &str = HUGGING_FACE;
pub(crate) const TGI: &str = "tgi";
pub(crate) const HUGGING_FACE: &str = "huggingface";
pub(crate) const OLLAMA: &str = "ollama";
pub(crate) const OPENAI: &str = "openai";
pub(crate) const DEFAULT_ADAPTOR: &str = HUGGING_FACE;
McPatate marked this conversation as resolved.
Show resolved Hide resolved

fn unknown_adaptor_error(adaptor: Option<&String>) -> jsonrpc::Error {
internal_error(format!("Unknown adaptor {:?}", adaptor))
Expand Down
6 changes: 4 additions & 2 deletions crates/llm-ls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod language_id;
const MAX_WARNING_REPEAT: Duration = Duration::from_secs(3_600);
pub const NAME: &str = "llm-ls";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
const HF_INFERENCE_API_HOSTNAME: &str = "api-inference.huggingface.co";

fn get_position_idx(rope: &Rope, row: usize, col: usize) -> Result<usize> {
Ok(rope.try_line_to_char(row).map_err(internal_error)?
Expand Down Expand Up @@ -584,7 +585,7 @@ fn build_url(model: &str) -> String {
if model.starts_with("http://") || model.starts_with("https://") {
model.to_owned()
} else {
format!("https://api-inference.huggingface.co/models/{model}")
format!("https://{HF_INFERENCE_API_HOSTNAME}/models/{model}")
}
}

Expand Down Expand Up @@ -613,7 +614,8 @@ impl Backend {
"received completion request for {}",
params.text_document_position.text_document.uri
);
if params.api_token.is_none() {
let is_using_inference_api = params.adaptor.as_ref().unwrap_or(&adaptors::DEFAULT_ADAPTOR.to_owned()).as_str() == adaptors::HUGGING_FACE;
if params.api_token.is_none() && is_using_inference_api {
let now = Instant::now();
let unauthenticated_warn_at = self.unauthenticated_warn_at.read().await;
if now.duration_since(*unauthenticated_warn_at) > MAX_WARNING_REPEAT {
Expand Down
Loading