diff options
author | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-29 00:54:36 +0200 |
---|---|---|
committer | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-29 00:54:36 +0200 |
commit | 5c2896ed5e8ea8993aa69804b864d7c2e13b8a44 (patch) | |
tree | 83930d7f7e091cf587ce43549e2e211662526e8c /unfinished | |
parent | _ (diff) | |
parent | Merge pull request #242 from ezerinz/main (diff) | |
download | gpt4free-5c2896ed5e8ea8993aa69804b864d7c2e13b8a44.tar gpt4free-5c2896ed5e8ea8993aa69804b864d7c2e13b8a44.tar.gz gpt4free-5c2896ed5e8ea8993aa69804b864d7c2e13b8a44.tar.bz2 gpt4free-5c2896ed5e8ea8993aa69804b864d7c2e13b8a44.tar.lz gpt4free-5c2896ed5e8ea8993aa69804b864d7c2e13b8a44.tar.xz gpt4free-5c2896ed5e8ea8993aa69804b864d7c2e13b8a44.tar.zst gpt4free-5c2896ed5e8ea8993aa69804b864d7c2e13b8a44.zip |
Diffstat (limited to 'unfinished')
-rw-r--r-- | unfinished/chatpdf/__init__.py | 75 | ||||
-rw-r--r-- | unfinished/openai/README.md | 2 |
2 files changed, 76 insertions, 1 deletions
diff --git a/unfinished/chatpdf/__init__.py b/unfinished/chatpdf/__init__.py new file mode 100644 index 00000000..4c9d2d3e --- /dev/null +++ b/unfinished/chatpdf/__init__.py @@ -0,0 +1,75 @@ +import requests +import json + +class Completion: + + def request(prompt: str): + '''TODO: some sort of authentication + upload PDF from URL or local file + Then you should get the atoken and chat ID + ''' + + token = "your_token_here" + chat_id = "your_chat_id_here" + + url = "https://chat-pr4yueoqha-ue.a.run.app/" + + payload = json.dumps({ + "v": 2, + "chatSession": { + "type": "join", + "chatId": chat_id + }, + "history": [ + { + "id": "VNsSyJIq_0", + "author": "p_if2GPSfyN8hjDoA7unYe", + "msg": "<start>", + "time": 1682672009270 + }, + { + "id": "Zk8DRUtx_6", + "author": "uplaceholder", + "msg": prompt, + "time": 1682672181339 + } + ] + }) + + # TODO: fix headers, use random user-agent, streaming response, etc + headers = { + 'authority': 'chat-pr4yueoqha-ue.a.run.app', + 'accept': '*/*', + 'accept-language': 'en-US,en;q=0.9', + 'atoken': token, + 'content-type': 'application/json', + 'origin': 'https://www.chatpdf.com', + 'referer': 'https://www.chatpdf.com/', + 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"', + 'sec-ch-ua-mobile': '?0', + 'sec-ch-ua-platform': '"Windows"', + 'sec-fetch-dest': 'empty', + 'sec-fetch-mode': 'cors', + 'sec-fetch-site': 'cross-site', + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36' + } + + response = requests.request("POST", url, headers=headers, data=payload).text + Completion.stream_completed = True + return {'response': response} + + @staticmethod + def create(prompt: str): + Thread(target=Completion.request, args=[prompt]).start() + + while Completion.stream_completed != True or not Completion.message_queue.empty(): + try: + message = Completion.message_queue.get(timeout=0.01) + for message in findall(Completion.regex, message): + yield loads(Completion.part1 + message + Completion.part2)['delta'] + + except Empty: + pass + + @staticmethod + def handle_stream_response(response): + Completion.message_queue.put(response.decode()) diff --git a/unfinished/openai/README.md b/unfinished/openai/README.md index 67e8645c..39196729 100644 --- a/unfinished/openai/README.md +++ b/unfinished/openai/README.md @@ -1,2 +1,2 @@ to do: -- code refractoring
\ No newline at end of file +- code refactoring |