返回提交历史
Added
g4f/Provider/Providers/Raycast.py
+50
-0
Modified
g4f/Provider/__init__.py
+1
-0
XFEstudio/gpt4free
Add Raycast Provider
fb1a6f4c
代码差异
2 个文件
+51
-0
@@ -0,0 +1,50 @@
1
import json
2
import os
3
4
import requests
5
from g4f.typing import get_type_hints
6
7
url = "https://backend.raycast.com/api/v1/ai/chat_completions"
8
model = ['gpt-3.5-turbo', 'gpt-4']
9
supports_stream = True
10
needs_auth = True
11
working = True
12
13
14
def _create_completion(model: str, messages: list, stream: bool, **kwargs):
15
auth = kwargs.get('auth')
16
headers = {
17
'Accept': 'application/json',
18
'Accept-Language': 'en-US,en;q=0.9',
19
'Authorization': f'Bearer {auth}',
20
'Content-Type': 'application/json',
21
'User-Agent': 'Raycast/0 CFNetwork/1410.0.3 Darwin/22.6.0',
22
}
23
parsed_messages = []
24
for message in messages:
25
parsed_messages.append({
26
'author': message['role'],
27
'content': {'text': message['content']}
28
})
29
data = {
30
"debug": False,
31
"locale": "en-CN",
32
"messages": parsed_messages,
33
"model": model,
34
"provider": "openai",
35
"source": "ai_chat",
36
"system_instruction": "markdown",
37
"temperature": 0.5
38
}
39
response = requests.post(url, headers=headers, json=data, stream=True)
40
for token in response.iter_lines():
41
if b'data: ' not in token:
42
continue
43
completion_chunk = json.loads(token.decode().replace('data: ', ''))
44
token = completion_chunk['text']
45
if token != None:
46
yield token
47
48
49
params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
50
'(%s)' % ', '.join([f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
@@ -24,6 +24,7 @@ from .Providers import (
24
24
Wewordle,
25
25
ChatgptAi,
26
26
opchatgpts,
27
Raycast,
27
28
)
28
29
29
30
Palm = Bard