2023-04-22 02:02:10 +00:00
from requests import Session
import json
class Completion :
def create (
prompt : str = " What is the square root of pi " ,
2023-04-22 12:47:03 +00:00
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 :
2023-04-22 02:02:10 +00:00
2023-04-22 12:47:03 +00:00
client = Session ( )
2023-04-22 02:02:10 +00:00
client . headers = {
2023-04-22 12:47:03 +00:00
' Accept ' : ' */* ' ,
' Accept-Language ' : ' en-US,en;q=0.5 ' ,
2023-04-22 02:02:10 +00:00
" origin " : " https://cocalc.com " ,
" referer " : " https://cocalc.com/api/v2/openai/chatgpt " ,
" 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 " ,
}
2023-04-22 12:47:03 +00:00
2023-04-22 02:02:10 +00:00
payload = {
" input " : prompt ,
" system " : system_prompt ,
" tag " : " next:index "
}
2023-04-22 12:47:03 +00:00
response = client . post ( f " https://cocalc.com/api/v2/openai/chatgpt " , json = payload ) . json ( )
2023-04-22 02:02:10 +00:00
2023-04-22 12:47:03 +00:00
return response
2023-04-22 02:02:10 +00:00