From f5518bb94d9ec78016b6e98da414647473f761e9 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 23 Jan 2024 05:02:14 +0100 Subject: Cleanup model list --- g4f/Provider/HuggingChat.py | 25 ++++++++++++++++++------- g4f/Provider/PerplexityLabs.py | 29 +++++++++++++++-------------- 2 files changed, 33 insertions(+), 21 deletions(-) (limited to 'g4f/Provider') diff --git a/g4f/Provider/HuggingChat.py b/g4f/Provider/HuggingChat.py index 4a42b3c8..3b4a520c 100644 --- a/g4f/Provider/HuggingChat.py +++ b/g4f/Provider/HuggingChat.py @@ -8,14 +8,23 @@ from ..typing import AsyncResult, Messages from .base_provider import AsyncGeneratorProvider from .helper import format_prompt, get_cookies -map = { - "openchat/openchat_3.5": "openchat/openchat-3.5-1210", -} class HuggingChat(AsyncGeneratorProvider): url = "https://huggingface.co/chat" working = True - model = "meta-llama/Llama-2-70b-chat-hf" + default_model = "meta-llama/Llama-2-70b-chat-hf" + models = [ + "mistralai/Mixtral-8x7B-Instruct-v0.1", + "meta-llama/Llama-2-70b-chat-hf", + "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO", + "codellama/CodeLlama-34b-Instruct-hf", + "mistralai/Mistral-7B-Instruct-v0.2", + "openchat/openchat-3.5-0106" + ] + model_map = { + "openchat/openchat_3.5": "openchat/openchat-3.5-1210", + "mistralai/Mixtral-8x7B-Instruct-v0.1": "mistralai/Mistral-7B-Instruct-v0.2" + } @classmethod async def create_async_generator( @@ -29,9 +38,11 @@ class HuggingChat(AsyncGeneratorProvider): **kwargs ) -> AsyncResult: if not model: - model = cls.model - elif model in map: - model = map[model] + model = cls.default_model + elif model in cls.model_map: + model = cls.model_map[model] + elif model not in cls.models: + raise ValueError(f"Model is not supported: {model}") if not cookies: cookies = get_cookies(".huggingface.co") diff --git a/g4f/Provider/PerplexityLabs.py b/g4f/Provider/PerplexityLabs.py index 7e76aeef..c989b3da 100644 --- a/g4f/Provider/PerplexityLabs.py +++ b/g4f/Provider/PerplexityLabs.py @@ -2,27 +2,28 @@ from __future__ import annotations import random import json -from aiohttp import ClientSession, WSMsgType +from aiohttp import ClientSession from ..typing import AsyncResult, Messages from .base_provider import AsyncGeneratorProvider API_URL = "https://labs-api.perplexity.ai/socket.io/" WS_URL = "wss://labs-api.perplexity.ai/socket.io/" -MODELS = ['pplx-7b-online', 'pplx-70b-online', 'pplx-7b-chat', 'pplx-70b-chat', 'mistral-7b-instruct', - 'codellama-34b-instruct', 'llama-2-70b-chat', 'llava-7b-chat', 'mixtral-8x7b-instruct', - 'mistral-medium', 'related'] -DEFAULT_MODEL = MODELS[1] -MODEL_MAP = { - "mistralai/Mistral-7B-Instruct-v0.1": "mistral-7b-instruct", - "meta-llama/Llama-2-70b-chat-hf": "llama-2-70b-chat", - "mistralai/Mixtral-8x7B-Instruct-v0.1": "mixtral-8x7b-instruct", -} class PerplexityLabs(AsyncGeneratorProvider): url = "https://labs.perplexity.ai" working = True supports_gpt_35_turbo = True + models = ['pplx-7b-online', 'pplx-70b-online', 'pplx-7b-chat', 'pplx-70b-chat', 'mistral-7b-instruct', + 'codellama-34b-instruct', 'llama-2-70b-chat', 'llava-7b-chat', 'mixtral-8x7b-instruct', + 'mistral-medium', 'related'] + default_model = 'pplx-70b-online' + model_map = { + "mistralai/Mistral-7B-Instruct-v0.1": "mistral-7b-instruct", + "meta-llama/Llama-2-70b-chat-hf": "llama-2-70b-chat", + "mistralai/Mixtral-8x7B-Instruct-v0.1": "mixtral-8x7b-instruct", + "codellama/CodeLlama-34b-Instruct-hf": "codellama-34b-instruct" + } @classmethod async def create_async_generator( @@ -33,10 +34,10 @@ class PerplexityLabs(AsyncGeneratorProvider): **kwargs ) -> AsyncResult: if not model: - model = DEFAULT_MODEL - elif model in MODEL_MAP: - model = MODEL_MAP[model] - elif model not in MODELS: + model = cls.default_model + elif model in cls.model_map: + model = cls.model_map[model] + elif model not in cls.models: raise ValueError(f"Model is not supported: {model}") headers = { "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0", -- cgit v1.2.3