mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
Track live model instances in Ollama and Cohere providers, updating count on model retrieval
This commit is contained in:
parent
3df3595e63
commit
6607c82d3c
3 changed files with 14 additions and 1 deletions
|
|
@ -32,6 +32,8 @@ class Ollama(OpenaiAPI):
|
|||
api_key = AuthManager.load_api_key(cls)
|
||||
if api_key:
|
||||
models = requests.get("https://ollama.com/api/tags", {"headers": {"Authorization": f"Bearer {api_key}"}}).json()["models"]
|
||||
if models:
|
||||
cls.live += 1
|
||||
cls.models = [model["name"] for model in models]
|
||||
if api_base is None:
|
||||
host = os.getenv("OLLAMA_HOST", "127.0.0.1")
|
||||
|
|
@ -43,6 +45,8 @@ class Ollama(OpenaiAPI):
|
|||
models = requests.get(url).json()["models"]
|
||||
except requests.exceptions.RequestException as e:
|
||||
return cls.models
|
||||
if cls.live == 0 and models:
|
||||
cls.live += 1
|
||||
cls.local_models = [model["name"] for model in models]
|
||||
cls.models = cls.models + cls.local_models
|
||||
cls.default_model = next(iter(cls.models), None)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ class Cohere(AsyncGeneratorProvider, ProviderModelMixin):
|
|||
api_key = AuthManager.load_api_key(cls)
|
||||
url = "https://api.cohere.com/v1/models?page_size=500&endpoint=chat"
|
||||
models = requests.get(url, headers={"Authorization": f"Bearer {api_key}" }).json().get("models", [])
|
||||
if models:
|
||||
cls.live += 1
|
||||
cls.models = [model.get("name") for model in models if "chat" in model.get("endpoints")]
|
||||
cls.vision_models = {model.get("name") for model in models if model.get("supports_vision")}
|
||||
return cls.models
|
||||
|
|
|
|||
|
|
@ -15,9 +15,16 @@ class QwenCode(OpenaiTemplate):
|
|||
needs_auth = True
|
||||
active_by_default = True
|
||||
default_model = "qwen3-coder-plus"
|
||||
models = [default_model]
|
||||
client = QwenContentGenerator(QwenOAuth2Client())
|
||||
|
||||
@classmethod
|
||||
def get_models(cls, **kwargs):
|
||||
if not cls.models:
|
||||
cls.models = [cls.default_model]
|
||||
if cls.live == 0 and cls.client.shared_manager.isTokenValid(cls.client.shared_manager.getCurrentCredentials()):
|
||||
cls.live += 1
|
||||
return cls.models
|
||||
|
||||
@classmethod
|
||||
async def create_async_generator(
|
||||
cls,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue