ElonGates commited on
Commit
0ae0268
1 Parent(s): c7a7c7b

Basic cocalc impl

Browse files
Files changed (1) hide show
  1. cocalc/__init__.py +28 -0
cocalc/__init__.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from requests import Session
2
+ import json
3
+
4
+ class Completion:
5
+ def create(
6
+ prompt: str = "What is the square root of pi",
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? "
8
+ ) -> str:
9
+
10
+ client = Session(client_identifier="chrome_108")
11
+ client.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
+ 'cookie' : "Cookie: CC_ANA=c68b16f3-f74c-403f-8e18-1d89168b2d13; "
17
+ "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",
18
+ }
19
+ payload = {
20
+ "input": prompt,
21
+ "system": system_prompt,
22
+ "tag": "next:index"
23
+ }
24
+
25
+ response = client.post(f"https://cocalc.com/api/v2/openai/chatgpt", json=payload)
26
+
27
+ return json.loads(response)["output"]
28
+