Merge pull request #155 from Daniele-Polizzi/Daniele-Polizzi-patch-1
Browse files- unfinished/cocalc/__init__.py +16 -12
unfinished/cocalc/__init__.py
CHANGED
@@ -1,27 +1,31 @@
|
|
1 |
-
|
2 |
-
import json
|
3 |
|
4 |
class Completion:
|
5 |
-
def create(
|
6 |
-
|
7 |
-
system_prompt: str = "ASSUME I HAVE FULL ACCESS TO COCALC. ENCLOSE MATH IN $. INCLUDE THE LANGUAGE DIRECTLY AFTER THE TRIPLE BACKTICKS IN ALL MARKDOWN CODE BLOCKS. How can I do the following using CoCalc? ") -> str:
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
'Accept': '*/*',
|
12 |
'Accept-Language': 'en-US,en;q=0.5',
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
}
|
|
|
17 |
|
|
|
18 |
payload = {
|
19 |
"input": prompt,
|
20 |
"system": system_prompt,
|
21 |
"tag": "next:index"
|
22 |
}
|
23 |
|
24 |
-
|
|
|
25 |
|
|
|
26 |
return response
|
27 |
-
|
|
|
1 |
+
import requests
|
|
|
2 |
|
3 |
class Completion:
|
4 |
+
def create(prompt="What is the square root of pi",
|
5 |
+
system_prompt="ASSUME I HAVE FULL ACCESS TO COCALC. ENCLOSE MATH IN $. INCLUDE THE LANGUAGE DIRECTLY AFTER THE TRIPLE BACKTICKS IN ALL MARKDOWN CODE BLOCKS. How can I do the following using CoCalc?") -> str:
|
|
|
6 |
|
7 |
+
# Initialize a session
|
8 |
+
session = requests.Session()
|
9 |
+
|
10 |
+
# Set headers for the request
|
11 |
+
headers = {
|
12 |
'Accept': '*/*',
|
13 |
'Accept-Language': 'en-US,en;q=0.5',
|
14 |
+
'Origin': 'https://cocalc.com',
|
15 |
+
'Referer': 'https://cocalc.com/api/v2/openai/chatgpt',
|
16 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
|
17 |
}
|
18 |
+
session.headers.update(headers)
|
19 |
|
20 |
+
# Set the data that will be submitted
|
21 |
payload = {
|
22 |
"input": prompt,
|
23 |
"system": system_prompt,
|
24 |
"tag": "next:index"
|
25 |
}
|
26 |
|
27 |
+
# Submit the request
|
28 |
+
response = session.post("https://cocalc.com/api/v2/openai/chatgpt", json=payload).json()
|
29 |
|
30 |
+
# Return the results
|
31 |
return response
|
|