Skip to content

Commit

Permalink
Add labels to provider list
Browse files Browse the repository at this point in the history
  • Loading branch information
hlohaus committed Apr 12, 2024
1 parent a107d3f commit f724c07
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 11 deletions.
18 changes: 11 additions & 7 deletions g4f/Provider/Bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import asyncio
from urllib import parse
from datetime import datetime
from datetime import datetime, date
from aiohttp import ClientSession, ClientTimeout, BaseConnector, WSMsgType

from ..typing import AsyncResult, Messages, ImageType, Cookies
Expand All @@ -32,6 +32,7 @@ class Bing(AsyncGeneratorProvider, ProviderModelMixin):
"""
Bing provider for generating responses using the Bing API.
"""
label = "Microsoft Copilot in Bing"
url = "https://bing.com/chat"
working = True
supports_message_history = True
Expand All @@ -47,7 +48,7 @@ def create_async_generator(
proxy: str = None,
timeout: int = 900,
api_key: str = None,
cookies: Cookies = {},
cookies: Cookies = None,
connector: BaseConnector = None,
tone: str = None,
image: ImageType = None,
Expand All @@ -69,8 +70,6 @@ def create_async_generator(
:return: An asynchronous result object.
"""
prompt = messages[-1]["content"]
if api_key is not None:
cookies["_U"] = api_key
if context is None:
context = create_context(messages[:-1]) if len(messages) > 1 else None
if tone is None:
Expand All @@ -79,7 +78,7 @@ def create_async_generator(
gpt4_turbo = True if model.startswith("gpt-4-turbo") else False

return stream_generate(
prompt, tone, image, context, cookies,
prompt, tone, image, context, api_key, cookies,
get_connector(connector, proxy, True),
proxy, web_search, gpt4_turbo, timeout,
**kwargs
Expand Down Expand Up @@ -110,11 +109,15 @@ def get_default_cookies():
'SUID' : '',
'SRCHUSR' : '',
'SRCHHPGUSR' : f'HV={int(time.time())}',
'BCP' : 'AD=1&AL=1&SM=1',
'_Rwho' : f'u=d&ts={date.today().isoformat()}',
}

def create_headers(cookies: Cookies = None) -> dict:
def create_headers(cookies: Cookies = None, api_key: str = None) -> dict:
if cookies is None:
cookies = get_default_cookies()
if api_key is not None:
cookies["_U"] = api_key
headers = Defaults.headers.copy()
headers["cookie"] = "; ".join(f"{k}={v}" for k, v in cookies.items())
headers["x-forwarded-for"] = get_ip_address()
Expand Down Expand Up @@ -364,6 +367,7 @@ async def stream_generate(
image: ImageType = None,
context: str = None,
cookies: dict = None,
api_key: str = None,
connector: BaseConnector = None,
proxy: str = None,
web_search: bool = False,
Expand All @@ -389,7 +393,7 @@ async def stream_generate(
:param timeout: Timeout for the request.
:return: An asynchronous generator yielding responses.
"""
headers = create_headers(cookies)
headers = create_headers(cookies, api_key)
new_conversation = conversation is None
max_retries = (5 if new_conversation else 0) if max_retries is None else max_retries
async with ClientSession(
Expand Down
1 change: 1 addition & 0 deletions g4f/Provider/BingCreateImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .bing.create_images import create_images, create_session, get_cookies_from_browser

class BingCreateImages(AsyncGeneratorProvider, ProviderModelMixin):
label = "Microsoft Designer"
url = "https://www.bing.com/images/create"
working = True

Expand Down
1 change: 1 addition & 0 deletions g4f/Provider/DeepInfra.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .needs_auth.Openai import Openai

class DeepInfra(Openai):
label = "DeepInfra"
url = "https://deepinfra.com"
working = True
needs_auth = False
Expand Down
2 changes: 1 addition & 1 deletion g4f/Provider/HuggingChat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin):
url = "https://huggingface.co/chat"
working = True
default_model = "meta-llama/Llama-2-70b-chat-hf"
default_model = "mistralai/Mixtral-8x7B-Instruct-v0.1"
models = [
"mistralai/Mixtral-8x7B-Instruct-v0.1",
"google/gemma-7b-it",
Expand Down
1 change: 1 addition & 0 deletions g4f/Provider/Local.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ..errors import MissingRequirementsError

class Local(AbstractProvider, ProviderModelMixin):
label = "gpt4all"
working = True
supports_message_history = True
supports_system_message = True
Expand Down
1 change: 1 addition & 0 deletions g4f/Provider/needs_auth/Groq.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ...typing import AsyncResult, Messages

class Groq(Openai):
lebel = "Groq"
url = "https://console.groq.com/playground"
working = True
default_model = "mixtral-8x7b-32768"
Expand Down
1 change: 1 addition & 0 deletions g4f/Provider/needs_auth/OpenRouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ...typing import AsyncResult, Messages

class OpenRouter(Openai):
label = "OpenRouter"
url = "https://openrouter.ai"
working = True
default_model = "openrouter/auto"
Expand Down
1 change: 1 addition & 0 deletions g4f/Provider/needs_auth/Openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ...errors import MissingAuthError, ResponseError

class Openai(AsyncGeneratorProvider, ProviderModelMixin):
label = "OpenAI API"
url = "https://openai.com"
working = True
needs_auth = True
Expand Down
1 change: 1 addition & 0 deletions g4f/Provider/needs_auth/OpenaiChat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class OpenaiChat(AsyncGeneratorProvider, ProviderModelMixin):
"""A class for creating and managing conversations with OpenAI chat service"""

lebel = "OpenAI ChatGPT"
url = "https://chat.openai.com"
working = True
supports_gpt_35_turbo = True
Expand Down
1 change: 1 addition & 0 deletions g4f/Provider/needs_auth/Theb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
}

class Theb(AbstractProvider):
label = "TheB.AI"
url = "https://beta.theb.ai"
working = True
supports_gpt_35_turbo = True
Expand Down
1 change: 1 addition & 0 deletions g4f/Provider/needs_auth/ThebApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
}

class ThebApi(Openai):
label = "TheB.AI API"
url = "https://theb.ai"
working = True
needs_auth = True
Expand Down
5 changes: 3 additions & 2 deletions g4f/gui/client/static/js/chat.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,10 @@ async function on_api() {
});

providers = await api("providers")
providers.forEach((provider) => {
Object.entries(providers).forEach(([provider, label]) => {
let option = document.createElement("option");
option.value = option.text = provider;
option.value = provider;
option.text = label;
providerSelect.appendChild(option);
})

Expand Down
11 changes: 10 additions & 1 deletion g4f/gui/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ def get_providers(self) -> list[str]:
"""
Return a list of all working providers.
"""
return [provider.__name__ for provider in __providers__ if provider.working]
return {
provider.__name__: (provider.label
if hasattr(provider, "label")
else provider.__name__) +
(" (WebDriver)"
if "webdriver" in provider.get_parameters()
else "")
for provider in __providers__
if provider.working
}

def get_version(self):
"""
Expand Down

0 comments on commit f724c07

Please sign in to comment.