From 8c6d0480af22d162a888458b772cc6785a0e10aa Mon Sep 17 00:00:00 2001 From: chyroc Date: Wed, 28 May 2025 20:54:20 +0800 Subject: [PATCH 1/2] examples --- examples/benchmark_websockets_chat.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/benchmark_websockets_chat.py b/examples/benchmark_websockets_chat.py index 95ec1596..13eb217d 100644 --- a/examples/benchmark_websockets_chat.py +++ b/examples/benchmark_websockets_chat.py @@ -8,6 +8,7 @@ from cozepy import ( COZE_CN_BASE_URL, AsyncCoze, + AsyncTokenAuth, AsyncWebsocketsChatClient, AsyncWebsocketsChatEventHandler, AudioFormat, @@ -17,7 +18,6 @@ ConversationMessageDeltaEvent, DeviceOAuthApp, InputAudioBufferAppendEvent, - TokenAuth, WebsocketsEventType, setup_logging, ) @@ -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 "{}") @@ -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 @@ -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()) From a6142846f8dc10e2e44baedf1094537391ca44ad Mon Sep 17 00:00:00 2001 From: chyroc Date: Wed, 28 May 2025 20:55:53 +0800 Subject: [PATCH 2/2] udate --- README.md | 8 ++++---- examples/auth_pat.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1b581f43..017bf63a 100644 --- a/README.md +++ b/README.md @@ -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(): @@ -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(): diff --git a/examples/auth_pat.py b/examples/auth_pat.py index b57157c5..42f739e4 100644 --- a/examples/auth_pat.py +++ b/examples/auth_pat.py @@ -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, @@ -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)