Skip to content

chore: Update benchmark websocket examplpe #248

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
May 28, 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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,9 @@ Asynchronous methods also support:
import os
import asyncio

from cozepy import TokenAuth, AsyncCoze
from cozepy import AsyncTokenAuth, AsyncCoze

coze = AsyncCoze(auth=TokenAuth(os.getenv("COZE_API_TOKEN")))
coze = AsyncCoze(auth=AsyncTokenAuth(os.getenv("COZE_API_TOKEN")))


async def main():
Expand Down Expand Up @@ -629,9 +629,9 @@ Asynchronous methods also support:
import asyncio
import os

from cozepy import TokenAuth, AsyncCoze
from cozepy import AsyncTokenAuth, AsyncCoze

coze = AsyncCoze(auth=TokenAuth(os.getenv("COZE_API_TOKEN")))
coze = AsyncCoze(auth=AsyncTokenAuth(os.getenv("COZE_API_TOKEN")))


async def main():
Expand Down
4 changes: 2 additions & 2 deletions examples/auth_pat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import os

from cozepy import COZE_CN_BASE_URL, AsyncCoze, Coze, TokenAuth
from cozepy import COZE_CN_BASE_URL, AsyncCoze, AsyncTokenAuth, Coze, TokenAuth

coze_api_token = os.getenv("COZE_API_TOKEN")
# The default access is api.coze.cn, but if you need to access api.coze.com,
Expand All @@ -31,4 +31,4 @@

# or
# Establish an asynchronous coze client by using the access_token
async_coze = AsyncCoze(auth=TokenAuth(token=coze_api_token), base_url=coze_api_base)
async_coze = AsyncCoze(auth=AsyncTokenAuth(token=coze_api_token), base_url=coze_api_base)
11 changes: 8 additions & 3 deletions examples/benchmark_websockets_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from cozepy import (
COZE_CN_BASE_URL,
AsyncCoze,
AsyncTokenAuth,
AsyncWebsocketsChatClient,
AsyncWebsocketsChatEventHandler,
AudioFormat,
Expand All @@ -17,7 +18,6 @@
ConversationMessageDeltaEvent,
DeviceOAuthApp,
InputAudioBufferAppendEvent,
TokenAuth,
WebsocketsEventType,
setup_logging,
)
Expand Down Expand Up @@ -58,6 +58,10 @@ def get_current_time_ms():
return int(time.time() * 1000)


def green_text(s: str) -> str:
return f"\033[32m{s}\033[0m"


setup_examples_logger()

kwargs = json.loads(os.getenv("COZE_KWARGS") or "{}")
Expand Down Expand Up @@ -181,7 +185,7 @@ async def main():

# Initialize Coze client
coze = AsyncCoze(
auth=TokenAuth(coze_api_token),
auth=AsyncTokenAuth(coze_api_token),
base_url=coze_api_base,
)
# Initialize Audio
Expand All @@ -201,9 +205,10 @@ async def main():
text_latency.append(text)
audio_latency.append(audio)
print(
f"[latency.ws] {i}, asr: {cal_latency(asr, asr_latency)}, text: {cal_latency(text, text_latency)}, audio: {cal_latency(audio, audio_latency)}, log: {handler.logid}"
f"[latency.ws] {i}, {green_text('asr')}: {cal_latency(asr, asr_latency)}, {green_text('text')}: {cal_latency(text, text_latency)}, {green_text('audio')}: {cal_latency(audio, audio_latency)}, {green_text('log')}: {handler.logid}"
)


if __name__ == "__main__":
# COZE_API_TOKEN=xx COZE_BOT_ID=xx COZE_TEXT=xx COZE_LOG=error python examples/benchmark_websockets_chat.py
asyncio.run(main())
Loading