返回提交历史
Added
g4f/Provider/FlowGpt.py
+75
-0
Modified
g4f/Provider/__init__.py
+1
-0
Modified
g4f/api/__init__.py
+2
-3
Modified
g4f/gui/client/js/chat.v1.js
+1
-1
XFEstudio/gpt4free
Add FlowGpt provider, Fix issue with None values in api
55caf8e7
代码差异
4 个文件
+79
-4
@@ -0,0 +1,75 @@
1
from __future__ import annotations
2
3
import json
4
from aiohttp import ClientSession
5
6
from ..typing import AsyncResult, Messages
7
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
8
9
class FlowGpt(AsyncGeneratorProvider, ProviderModelMixin):
10
url = "https://flowgpt.com/chat"
11
working = True
12
supports_gpt_35_turbo = True
13
supports_gpt_4 = True
14
supports_message_history = True
15
default_model = "gpt-3.5-turbo"
16
models = [
17
"gpt-4",
18
"gpt-3.5-turbo",
19
"gpt-3.5-long",
20
"google-gemini",
21
"claude-v2",
22
"llama2-13b"
23
]
24
model_aliases = {
25
"gemini": "google-gemini",
26
"gemini-pro": "google-gemini"
27
}
28
29
@classmethod
30
async def create_async_generator(
31
cls,
32
model: str,
33
messages: Messages,
34
proxy: str = None,
35
**kwargs
36
) -> AsyncResult:
37
model = cls.get_model(model)
38
headers = {
39
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0",
40
"Accept": "*/*",
41
"Accept-Language": "en-US;q=0.7,en;q=0.3",
42
"Accept-Encoding": "gzip, deflate, br",
43
"Referer": "https://flowgpt.com/",
44
"Content-Type": "application/json",
45
"Authorization": "Bearer null",
46
"Origin": "https://flowgpt.com",
47
"Connection": "keep-alive",
48
"Sec-Fetch-Dest": "empty",
49
"Sec-Fetch-Mode": "cors",
50
"Sec-Fetch-Site": "same-site",
51
"TE": "trailers"
52
}
53
async with ClientSession(headers=headers) as session:
54
data = {
55
"model": model,
56
"nsfw": False,
57
"question": messages[-1]["content"],
58
"history": [{"role": "assistant", "content": "Hello, how can I help you today?"}, *messages[:-1]],
59
"system": "You are helpful assitant. Follow the user's instructions carefully. Respond using markdown",
60
"temperature": kwargs.get("temperature", 0.7),
61
"promptId": f"model-{model}",
62
"documentIds": [],
63
"chatFileDocumentIds": [],
64
"generateImage": False,
65
"generateAudio": False
66
}
67
async with session.post("https://backend-k8s.flowgpt.com/v2/chat-anonymous", json=data, proxy=proxy) as response:
68
response.raise_for_status()
69
async for chunk in response.content:
70
if chunk.strip():
71
message = json.loads(chunk)
72
if "event" not in message:
73
continue
74
if message["event"] == "text":
75
yield message["data"]
@@ -31,6 +31,7 @@ from .ChatgptX import ChatgptX
31
31
from .Chatxyz import Chatxyz
32
32
from .DeepInfra import DeepInfra
33
33
from .FakeGpt import FakeGpt
34
from .FlowGpt import FlowGpt
34
35
from .FreeChatgpt import FreeChatgpt
35
36
from .FreeGpt import FreeGpt
36
37
from .GeekGpt import GeekGpt
@@ -86,9 +86,8 @@ class Api:
86
86
auth_header = request.headers.get("Authorization")
87
87
if auth_header is not None:
88
88
config.api_key = auth_header.split(None, 1)[-1]
89
90
89
response = self.client.chat.completions.create(
91
**dict(config),
90
**config.dict(exclude_none=True),
92
91
ignored=self.list_ignored_providers
93
92
)
94
93
except Exception as e:
@@ -121,7 +120,7 @@ class Api:
121
120
def format_exception(e: Exception, config: ChatCompletionsConfig) -> str:
122
121
last_provider = g4f.get_last_provider(True)
123
122
return json.dumps({
124
"error": {"message": f"ChatCompletionsError: {e.__class__.__name__}: {e}"},
123
"error": {"message": f"{e.__class__.__name__}: {e}"},
125
124
"model": last_provider.get("model") if last_provider else config.model,
126
125
"provider": last_provider.get("name") if last_provider else config.provider
127
126
})
@@ -11,7 +11,7 @@ const imageInput = document.querySelector('#image');
11
11
const cameraInput = document.querySelector('#camera');
12
12
const fileInput = document.querySelector('#file');
13
13
14
let prompt_lock = false;
14
let prompt_lock = false;
15
15
16
16
hljs.addPlugin(new CopyButtonPlugin());
17
17