diff options
author | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-27 20:16:07 +0200 |
---|---|---|
committer | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-04-27 20:16:07 +0200 |
commit | 10104774c10cccf95bbebcafd17c0a85207583e0 (patch) | |
tree | 6fec52831117ee43fe7141a153b7e123ff09d469 /unfinished/gptbz/__init__.py | |
parent | _ (diff) | |
parent | Merge pull request #205 from AymaneHrouch/reformat__code (diff) | |
download | gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.gz gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.bz2 gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.lz gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.xz gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.tar.zst gpt4free-10104774c10cccf95bbebcafd17c0a85207583e0.zip |
Diffstat (limited to 'unfinished/gptbz/__init__.py')
-rw-r--r-- | unfinished/gptbz/__init__.py | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/unfinished/gptbz/__init__.py b/unfinished/gptbz/__init__.py index ba326cf6..e95d5716 100644 --- a/unfinished/gptbz/__init__.py +++ b/unfinished/gptbz/__init__.py @@ -1,30 +1,46 @@ -import websockets from json import dumps, loads +import websockets + + +# Define the asynchronous function to test the WebSocket connection + + async def test(): + # Establish a WebSocket connection with the specified URL async with websockets.connect('wss://chatgpt.func.icu/conversation+ws') as wss: - - await wss.send(dumps(separators=(',', ':'), obj = { - 'content_type':'text', - 'engine':'chat-gpt', - 'parts':['hello world'], - 'options':{} - } - )) - + + # Prepare the message payload as a JSON object + payload = { + 'content_type': 'text', + 'engine': 'chat-gpt', + 'parts': ['hello world'], + 'options': {} + } + + # Send the payload to the WebSocket server + await wss.send(dumps(obj=payload, separators=(',', ':'))) + + # Initialize a variable to track the end of the conversation ended = None + # Continuously receive and process messages until the conversation ends while not ended: try: - response = await wss.recv() + # Receive and parse the JSON response from the server + response = await wss.recv() json_response = loads(response) + + # Print the entire JSON response print(json_response) - - ended = json_response.get('eof') - + + # Check for the end of the conversation + ended = json_response.get('eof') + + # If the conversation has not ended, print the received message if not ended: print(json_response['content']['parts'][0]) - + + # Handle cases when the connection is closed by the server except websockets.ConnectionClosed: break - |