Skip to content

Use new websockets API #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading