XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Update HuggingFaceAPI.py

b5a04052
H Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +3 -35
Modified g4f/Provider/needs_auth/hf/HuggingFaceAPI.py +3 -35
@@ -13,8 +13,8 @@ from .models import model_aliases, vision_models, default_model, default_vision_
13 13 class HuggingFaceAPI(OpenaiTemplate):
14 14 label = "HuggingFace (Text Generation)"
15 15 parent = "HuggingFace"
16 url = "https://api-inference.huggingface.com"
17 base_url = "https://api-inference.huggingface.co/v1"
16 url = "https://huggingface.com"
17 base_url = "https://router.huggingface.co/v1"
18 18 working = True
19 19 needs_auth = True
20 20
@@ -24,37 +24,8 @@ class HuggingFaceAPI(OpenaiTemplate):
24 24 model_aliases = model_aliases
25 25 fallback_models = text_models + vision_models
26 26
27 provider_mapping: dict[str, dict] = {
28 "google/gemma-3-27b-it": {
29 "hf-inference/models/google/gemma-3-27b-it": {
30 "task": "conversational",
31 "providerId": "google/gemma-3-27b-it"}}}
27 provider_mapping: dict[str, dict] = {}
32 28
33 @classmethod
34 def get_model(cls, model: str, **kwargs) -> str:
35 try:
36 return super().get_model(model, **kwargs)
37 except ModelNotFoundError:
38 return model
39
40 @classmethod
41 def get_models(cls, **kwargs) -> list[str]:
42 if not cls.models:
43 url = "https://huggingface.co/api/models?inference=warm&&expand[]=inferenceProviderMapping"
44 response = requests.get(url)
45 if response.ok:
46 cls.models = [
47 model["id"]
48 for model in response.json()
49 if [
50 provider
51 for provider in model.get("inferenceProviderMapping")
52 if provider.get("status") == "live" and provider.get("task") == "conversational"
53 ]
54 ] + list(cls.provider_mapping.keys())
55 else:
56 cls.models = cls.fallback_models
57 return cls.models
58 29
59 30 @classmethod
60 31 async def get_mapping(cls, model: str, api_key: str = None):
@@ -127,6 +98,3 @@ class HuggingFaceAPI(OpenaiTemplate):
127 98 continue
128 99 if error is not None:
129 100 raise error
130
131 # def calculate_lenght(messages: Messages) -> int:
132 # return sum([len(message["content"]) + 16 for message in messages])