Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
New GPT-4 API provider: Dfehub
Browse files Browse the repository at this point in the history
  • Loading branch information
ramon-victor committed Jul 10, 2023
1 parent b4c1592 commit df737e5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<i class="fa-brands fa-github"></i>
<span class="conversation-title">
Author: @ramonvc<br />
Version: 0.0.8-Alpha<br />
Version: 0.0.9-Alpha<br />
</span>
</a>
</div>
Expand Down Expand Up @@ -75,7 +75,7 @@
<option value="gpt-3.5-turbo-0613">GPT-3.5-0613</option>
<option value="gpt-3.5-turbo-16k">GPT-3.5-turbo-16k</option>
<option value="gpt-3.5-turbo-16k-0613" selected>GPT-3.5-turbo-16k-0613</option>
<option value="gpt-4-0613" disabled>GPT-4 (offline)</option>
<option value="gpt-4">GPT-4 (unstable)</option>
</select>
</div>
<div class="field">
Expand Down
49 changes: 49 additions & 0 deletions g4f/Provider/Providers/Dfehub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import requests
from ...typing import sha256, Dict, get_type_hints

url = "https://chat.dfehub.com"
model = ['gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-4']
supports_stream = True
needs_auth = False


def _create_completion(model: str, messages: list, stream: bool, **kwargs):
headers = {
'Authority': 'chat.dfehub.com',
'Content-Type': 'application/json',
'Method': 'POST',
'Path': '/api/openai/v1/chat/completions',
'Scheme': 'https',
'Accept': 'text/event-stream',
'Accept-Language': 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6,zh;q=0.5',
'Content-Type': 'application/json',
'Origin': 'https://chat.dfehub.com',
'Referer': 'https://chat.dfehub.com/',
'Sec-Ch-Ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
'Sec-Ch-Ua-Mobile': '?0',
'Sec-Ch-Ua-Platform': '"Windows"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
}

data = {
'model': model,
'temperature': 0.7,
'max_tokens': '8000',
'presence_penalty': 0,
'messages': messages,
}

response = requests.post(url + '/api/openai/v1/chat/completions',
headers=headers, json=data, stream=stream)

yield response.json()['choices'][0]['message']['content']


params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
'(%s)' % ', '.join(
[f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
1 change: 1 addition & 0 deletions g4f/Provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ChatgptLogin,
ChatgptLogin,
DeepAi,
Dfehub,
Easychat,
Ezcht,
Fakeopen,
Expand Down
3 changes: 1 addition & 2 deletions g4f/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class gpt_4_dev:
class gpt_4:
name: str = 'gpt-4'
base_provider: str = 'openai'
best_provider: Provider.Provider = Provider.Lockchat
best_providers: list = [Provider.Bing, Provider.Lockchat]
best_provider: Provider.Provider = Provider.Dfehub

class gpt_4_0613:
name: str = 'gpt-4-0613'
Expand Down

0 comments on commit df737e5

Please sign in to comment.