XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

moving to finished too

e2de6a01
9fo <71867245+9fo@users.noreply.github.com>
提交于

代码差异

2 个文件 +0 -54
Deleted unfinished/cocalc/__init__.py +0 -47
@@ -1,47 +0,0 @@
1 import requests
2
3
4 class Completion:
5 def create(self, prompt="What is the square root of pi",
6 system_prompt=("ASSUME I HAVE FULL ACCESS TO COCALC. ENCLOSE MATH IN $. "
7 "INCLUDE THE LANGUAGE DIRECTLY AFTER THE TRIPLE BACKTICKS "
8 "IN ALL MARKDOWN CODE BLOCKS. How can I do the following using CoCalc?")) -> str:
9 # Initialize a session with custom headers
10 session = self._initialize_session()
11
12 # Set the data that will be submitted
13 payload = self._create_payload(prompt, system_prompt)
14
15 # Submit the request and return the results
16 return self._submit_request(session, payload)
17
18 def _initialize_session(self) -> requests.Session:
19 """Initialize a session with custom headers for the request."""
20
21 session = requests.Session()
22 headers = {
23 'Accept': '*/*',
24 'Accept-Language': 'en-US,en;q=0.5',
25 'Origin': 'https://cocalc.com',
26 'Referer': 'https://cocalc.com/api/v2/openai/chatgpt',
27 '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',
28 }
29 session.headers.update(headers)
30
31 return session
32
33 def _create_payload(self, prompt: str, system_prompt: str) -> dict:
34 """Create the payload with the given prompts."""
35
36 return {
37 "input": prompt,
38 "system": system_prompt,
39 "tag": "next:index"
40 }
41
42 def _submit_request(self, session: requests.Session, payload: dict) -> str:
43 """Submit the request to the API and return the response."""
44
45 response = session.post(
46 "https://cocalc.com/api/v2/openai/chatgpt", json=payload).json()
47 return response
Deleted unfinished/cocalc/cocalc_test.py +0 -7
@@ -1,7 +0,0 @@
1 import cocalc
2
3 response = cocalc.Completion.create(
4 prompt='hello world'
5 )
6
7 print(response)