forked from phoenix/litellm-mirror
Litellm ruff linting enforcement (#5992)
* ci(config.yml): add a 'check_code_quality' step Addresses https://github.com/BerriAI/litellm/issues/5991 * ci(config.yml): check why circle ci doesn't pick up this test * ci(config.yml): fix to run 'check_code_quality' tests * fix(__init__.py): fix unprotected import * fix(__init__.py): don't remove unused imports * build(ruff.toml): update ruff.toml to ignore unused imports * fix: fix: ruff + pyright - fix linting + type-checking errors * fix: fix linting errors * fix(lago.py): fix module init error * fix: fix linting errors * ci(config.yml): cd into correct dir for checks * fix(proxy_server.py): fix linting error * fix(utils.py): fix bare except causes ruff linting errors * fix: ruff - fix remaining linting errors * fix(clickhouse.py): use standard logging object * fix(__init__.py): fix unprotected import * fix: ruff - fix linting errors * fix: fix linting errors * ci(config.yml): cleanup code qa step (formatting handled in local_testing) * fix(_health_endpoints.py): fix ruff linting errors * ci(config.yml): just use ruff in check_code_quality pipeline for now * build(custom_guardrail.py): include missing file * style(embedding_handler.py): fix ruff check
This commit is contained in:
parent
3fc4ae0d65
commit
d57be47b0f
263 changed files with 1687 additions and 3320 deletions
|
@ -13,6 +13,7 @@ import requests
|
|||
|
||||
import litellm
|
||||
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
||||
from litellm.secret_managers.main import get_secret_str
|
||||
from litellm.types.completion import ChatCompletionMessageToolCallParam
|
||||
from litellm.utils import Choices, CustomStreamWrapper, Message, ModelResponse, Usage
|
||||
|
||||
|
@ -181,7 +182,7 @@ class HuggingfaceConfig:
|
|||
return optional_params
|
||||
|
||||
def get_hf_api_key(self) -> Optional[str]:
|
||||
return litellm.utils.get_secret("HUGGINGFACE_API_KEY")
|
||||
return get_secret_str("HUGGINGFACE_API_KEY")
|
||||
|
||||
|
||||
def output_parser(generated_text: str):
|
||||
|
@ -240,7 +241,7 @@ def read_tgi_conv_models():
|
|||
# Cache the set for future use
|
||||
conv_models_cache = conv_models
|
||||
return tgi_models, conv_models
|
||||
except:
|
||||
except Exception:
|
||||
return set(), set()
|
||||
|
||||
|
||||
|
@ -372,7 +373,7 @@ class Huggingface(BaseLLM):
|
|||
]["finish_reason"]
|
||||
sum_logprob = 0
|
||||
for token in completion_response[0]["details"]["tokens"]:
|
||||
if token["logprob"] != None:
|
||||
if token["logprob"] is not None:
|
||||
sum_logprob += token["logprob"]
|
||||
setattr(model_response.choices[0].message, "_logprob", sum_logprob) # type: ignore
|
||||
if "best_of" in optional_params and optional_params["best_of"] > 1:
|
||||
|
@ -386,7 +387,7 @@ class Huggingface(BaseLLM):
|
|||
):
|
||||
sum_logprob = 0
|
||||
for token in item["tokens"]:
|
||||
if token["logprob"] != None:
|
||||
if token["logprob"] is not None:
|
||||
sum_logprob += token["logprob"]
|
||||
if len(item["generated_text"]) > 0:
|
||||
message_obj = Message(
|
||||
|
@ -417,7 +418,7 @@ class Huggingface(BaseLLM):
|
|||
prompt_tokens = len(
|
||||
encoding.encode(input_text)
|
||||
) ##[TODO] use the llama2 tokenizer here
|
||||
except:
|
||||
except Exception:
|
||||
# this should remain non blocking we should not block a response returning if calculating usage fails
|
||||
pass
|
||||
output_text = model_response["choices"][0]["message"].get("content", "")
|
||||
|
@ -429,7 +430,7 @@ class Huggingface(BaseLLM):
|
|||
model_response["choices"][0]["message"].get("content", "")
|
||||
)
|
||||
) ##[TODO] use the llama2 tokenizer here
|
||||
except:
|
||||
except Exception:
|
||||
# this should remain non blocking we should not block a response returning if calculating usage fails
|
||||
pass
|
||||
else:
|
||||
|
@ -559,7 +560,7 @@ class Huggingface(BaseLLM):
|
|||
True
|
||||
if "stream" in optional_params
|
||||
and isinstance(optional_params["stream"], bool)
|
||||
and optional_params["stream"] == True # type: ignore
|
||||
and optional_params["stream"] is True # type: ignore
|
||||
else False
|
||||
),
|
||||
}
|
||||
|
@ -595,7 +596,7 @@ class Huggingface(BaseLLM):
|
|||
data["stream"] = ( # type: ignore
|
||||
True # type: ignore
|
||||
if "stream" in optional_params
|
||||
and optional_params["stream"] == True
|
||||
and optional_params["stream"] is True
|
||||
else False
|
||||
)
|
||||
input_text = prompt
|
||||
|
@ -631,7 +632,7 @@ class Huggingface(BaseLLM):
|
|||
### ASYNC COMPLETION
|
||||
return self.acompletion(api_base=completion_url, data=data, headers=headers, model_response=model_response, task=task, encoding=encoding, input_text=input_text, model=model, optional_params=optional_params, timeout=timeout) # type: ignore
|
||||
### SYNC STREAMING
|
||||
if "stream" in optional_params and optional_params["stream"] == True:
|
||||
if "stream" in optional_params and optional_params["stream"] is True:
|
||||
response = requests.post(
|
||||
completion_url,
|
||||
headers=headers,
|
||||
|
@ -691,7 +692,7 @@ class Huggingface(BaseLLM):
|
|||
completion_response = response.json()
|
||||
if isinstance(completion_response, dict):
|
||||
completion_response = [completion_response]
|
||||
except:
|
||||
except Exception:
|
||||
import traceback
|
||||
|
||||
raise HuggingfaceError(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue