Skip to content

Commit

Permalink
Use new websockets API (#196)
Browse files Browse the repository at this point in the history
- Use new websockets API introduced in version 14
  • Loading branch information
vsakkas authored Jan 17, 2025
1 parent dbd36ae commit 231c347
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# <img src="https://raw.githubusercontent.com/vsakkas/sydney.py/master/images/logo.svg" width="28px" /> Sydney.py

[![Latest Release](https://img.shields.io/github/v/release/vsakkas/sydney.py.svg?color=blue)](https://github.com/vsakkas/sydney.py/releases/tag/v0.23.0)
[![Latest Release](https://img.shields.io/github/v/release/vsakkas/sydney.py.svg?color=blue)](https://github.com/vsakkas/sydney.py/releases/tag/v0.23.1)
[![Python](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![Managed](https://img.shields.io/badge/managed-poetry-bluegreen.svg?color=blue)](https://github.com/python-poetry/poetry)
[![MIT License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/vsakkas/sydney.py/blob/master/LICENSE)
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sydney-py"
version = "0.23.0"
version = "0.23.1"
description = "Python Client for Copilot (formerly named Bing Chat), also known as Sydney."
authors = ["vsakkas <[email protected]>"]
license = "MIT"
Expand Down
10 changes: 5 additions & 5 deletions sydney/sydney.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from typing import AsyncGenerator
from urllib import parse

import websockets.legacy.client as websockets
import websockets.asyncio.client as websockets
from aiohttp import ClientSession, FormData, TCPConnector
from websockets.legacy.client import WebSocketClientProtocol
from websockets.asyncio.client import ClientConnection

from sydney.constants import (
BING_BLOB_URL,
Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(
self.invocation_id: int | None = None
self.number_of_messages: int | None = None
self.max_messages: int | None = None
self.wss_client: WebSocketClientProtocol | None = None
self.wss_client: ClientConnection | None = None
self.session: ClientSession | None = None

async def __aenter__(self) -> SydneyClient:
Expand Down Expand Up @@ -365,7 +365,7 @@ async def _ask(
# Create a websocket connection with Copilot for sending and receiving messages.
try:
self.wss_client = await websockets.connect(
bing_chathub_url, extra_headers=CHATHUB_HEADERS, max_size=None
bing_chathub_url, additional_headers=CHATHUB_HEADERS, max_size=None
)
except TimeoutError:
raise ConnectionTimeoutException(
Expand Down Expand Up @@ -786,7 +786,7 @@ async def close_conversation(self) -> None:
"""
Close all connections to Copilot. Clear conversation information.
"""
if self.wss_client and not self.wss_client.closed:
if self.wss_client:
await self.wss_client.close()
self.wss_client = None

Expand Down

0 comments on commit 231c347

Please sign in to comment.