返回提交历史
Modified
gpt4free/README.md
+0
-5
Modified
gpt4free/__init__.py
+0
-7
Deleted
gpt4free/cocalc/__init__.py
+0
-67
Deleted
gpt4free/cocalc/readme.md
+0
-19
XFEstudio/gpt4free
remove cocalc; all non-authenticated access has been disabled
- cocalc is my website - i have disabled *all* non-authenticated access, so gpt4free will no longer work with cocalc. - it's better to remove it so you don't confuse your users, who might expect cocalc to work with gpt4free
42b8450b
代码差异
4 个文件
+0
-98
@@ -42,9 +42,6 @@ print(f'END')
42
42
response = gpt4free.Completion.create(Provider.Theb, prompt='Write a poem on Lionel Messi')
43
43
print(response)
44
44
45
# usage cocalc
46
response = gpt4free.Completion.create(Provider.CoCalc, prompt='Write a poem on Lionel Messi', cookie_input='')
47
print(response)
48
45
49
46
```
50
47
@@ -73,8 +70,6 @@ Some of the keyword arguments are optional, while others are required.
73
70
74
71
- Theb:
75
72
(no keyword arguments required)
76
- CoCalc:
77
- `cookie_input`: str - this needs to be provided by user
78
73
79
74
#### Token generation of quora
80
75
```python
@@ -1,6 +1,5 @@
1
1
from enum import Enum
2
2
3
from gpt4free import cocalc
4
3
from gpt4free import forefront
5
4
from gpt4free import quora
6
5
from gpt4free import theb
@@ -15,7 +14,6 @@ class Provider(Enum):
15
14
Poe = 'poe'
16
15
ForeFront = 'fore_front'
17
16
Theb = 'theb'
18
CoCalc = 'cocalc'
19
17
UseLess = 'useless'
20
18
21
19
@@ -40,8 +38,6 @@ class Completion:
40
38
return Completion.__fore_front_service(prompt, **kwargs)
41
39
elif provider == Provider.Theb:
42
40
return Completion.__theb_service(prompt, **kwargs)
43
elif provider == Provider.CoCalc:
44
return Completion.__cocalc_service(prompt, **kwargs)
45
41
elif provider == Provider.UseLess:
46
42
return Completion.__useless_service(prompt, **kwargs)
47
43
else:
@@ -67,6 +63,3 @@ class Completion:
67
63
def __theb_service(prompt: str, **kwargs):
68
64
return ''.join(theb.Completion.create(prompt=prompt))
69
65
70
@staticmethod
71
def __cocalc_service(prompt: str, **kwargs):
72
return cocalc.Completion.create(prompt, cookie_input=kwargs.get('cookie_input', '')).text
@@ -1,67 +0,0 @@
1
import requests
2
from fake_useragent import UserAgent
3
from pydantic import BaseModel
4
5
6
class CoCalcResponse(BaseModel):
7
text: str
8
status: bool
9
10
11
class Completion:
12
"""A class for generating text completions using CoCalc's GPT-based chatbot."""
13
14
API_ENDPOINT = "https://cocalc.com/api/v2/openai/chatgpt"
15
DEFAULT_SYSTEM_PROMPT = "ASSUME I HAVE FULL ACCESS TO COCALC. "
16
17
@staticmethod
18
def create(prompt: str, cookie_input: str) -> CoCalcResponse:
19
"""
20
Generate a text completion for the given prompt using CoCalc's GPT-based chatbot.
21
22
Args:
23
prompt: The text prompt to complete.
24
cookie_input: The cookie required to authenticate the chatbot API request.
25
26
Returns:
27
A CoCalcResponse object containing the text completion and a boolean indicating
28
whether the request was successful.
29
"""
30
31
# Initialize a session with custom headers
32
session = Completion._initialize_session(cookie_input)
33
34
# Set the data that will be submitted
35
payload = Completion._create_payload(prompt, Completion.DEFAULT_SYSTEM_PROMPT)
36
37
try:
38
# Submit the request and return the results
39
response = session.post(Completion.API_ENDPOINT, json=payload).json()
40
return CoCalcResponse(text=response['output'], status=response['success'])
41
except requests.exceptions.RequestException as e:
42
# Handle exceptions that may occur during the request
43
print(f"Error: {e}")
44
return CoCalcResponse(text="", status=False)
45
46
@classmethod
47
def _initialize_session(cls, conversation_cookie: str) -> requests.Session:
48
"""Initialize a session with custom headers for the request."""
49
50
session = requests.Session()
51
headers = {
52
"Accept": "*/*",
53
"Accept-Language": "en-US,en;q=0.5",
54
"Origin": "https://cocalc.com",
55
"Referer": "https://cocalc.com/api/v2/openai/chatgpt",
56
"Cookie": conversation_cookie,
57
"User-Agent": UserAgent().random,
58
}
59
session.headers.update(headers)
60
61
return session
62
63
@staticmethod
64
def _create_payload(prompt: str, system_prompt: str) -> dict:
65
"""Create the payload for the API request."""
66
67
return {"input": prompt, "system": system_prompt, "tag": "next:index"}
@@ -1,19 +0,0 @@
1
### Example: `cocalc` <a name="example-cocalc"></a>
2
3
```python
4
# import library
5
from gpt4free import cocalc
6
7
cocalc.Completion.create(prompt="How are you!", cookie_input="cookieinput") ## Tutorial
8
```
9
10
### How to grab cookie input
11
```js
12
// input this into ur developer tools console and the exact response u get from this u put into ur cookieInput!
13
var cookies = document.cookie.split("; ");
14
var cookieString = "";
15
for (var i = 0; i < cookies.length; i++) {
16
cookieString += cookies[i] + "; ";
17
}
18
console.log(cookieString);
19
```