-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: Enhance OAuth configuration and improve example scripts #162
Conversation
Caution Review failedThe pull request is closed. WalkthroughThis pull request introduces a new function Changes
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (8)
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
5fab83c
to
a430938
Compare
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## main #162 +/- ##
==========================================
- Coverage 90.13% 89.87% -0.27%
==========================================
Files 63 63
Lines 5748 5767 +19
==========================================
+ Hits 5181 5183 +2
- Misses 567 584 +17
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
examples/chat_stream.py (1)
Line range hint
12-57
: Move utility functions to a shared module to avoid duplication.These utility functions (
get_coze_api_base()
,get_coze_api_token()
, andsetup_examples_logger()
) are duplicated across all example files. Consider moving them to a shared module (e.g.,examples/utils.py
) to:
- Eliminate code duplication
- Centralize configuration management
- Make maintenance easier
- Ensure consistent behavior across examples
Here's a suggested approach:
- Create a shared utilities module:
# examples/utils.py import logging import os from typing import Optional from cozepy import COZE_CN_BASE_URL, DeviceOAuthApp, setup_logging # Move the common client ID to a constant COZE_CLIENT_ID = "57294420732781205987760324720643.app.coze" def get_coze_api_base() -> str: # ... (existing implementation) def get_coze_api_token(workspace_id: Optional[str] = None) -> str: # ... (existing implementation using COZE_CLIENT_ID) def setup_examples_logger(): # ... (existing implementation)
- Update the example files to import from utils:
from examples.utils import get_coze_api_base, get_coze_api_token, setup_examples_logger
🧹 Nitpick comments (3)
examples/websockets_audio_transcriptions.py (1)
Line range hint
89-101
: Consider moving the helper function to shared utilities.The
wrap_coze_speech_to_iterator
helper function could be useful across different examples. Consider moving it to the shared utilities module along with the other common functions.examples/websockets_chat.py (1)
Line range hint
108-122
: Enhance documentation for the fake plugin implementation.The
fake_run_local_plugin
function could benefit from better documentation explaining:
- The purpose of the fake implementation
- Expected real-world usage
- Format of the expected outputs
Add docstring to clarify the implementation:
def fake_run_local_plugin(): + """ + Simulates a local plugin execution for demonstration purposes. + In a real implementation, this would: + 1. Execute actual plugin logic + 2. Process the tool call arguments + 3. Return properly formatted outputs + """ # this is just fake outputs return event.data.required_action.submit_tool_outputs.tool_calls[0].function.argumentsexamples/websockets_chat_realtime_gui.py (1)
36-40
: Consider enhancing the logging configuration.The function provides basic logging setup but could be improved:
- Add docstring to explain the function's purpose and environment variable usage.
- Consider adding a default log level when
COZE_LOG
is not set.- Add error handling for invalid log level names.
Apply this diff to enhance the logging configuration:
def setup_examples_logger(): + """Configure logging based on COZE_LOG environment variable. + + The log level can be set using COZE_LOG environment variable (e.g., DEBUG, INFO, WARNING, ERROR). + If not set or invalid, defaults to INFO level. + """ coze_log = os.getenv("COZE_LOG") + default_level = logging.INFO if coze_log: - setup_logging(logging.getLevelNamesMapping().get(coze_log.upper(), logging.INFO)) + try: + level = logging.getLevelNamesMapping()[coze_log.upper()] + setup_logging(level) + except KeyError: + setup_logging(default_level) + else: + setup_logging(default_level)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
cozepy/__init__.py
(2 hunks)cozepy/auth/__init__.py
(2 hunks)examples/chat_stream.py
(1 hunks)examples/utils/__init__.py
(0 hunks)examples/websockets_audio_speech.py
(1 hunks)examples/websockets_audio_transcriptions.py
(1 hunks)examples/websockets_chat.py
(2 hunks)examples/websockets_chat_realtime_gui.py
(3 hunks)
💤 Files with no reviewable changes (1)
- examples/utils/init.py
🧰 Additional context used
🪛 GitHub Check: codecov/patch
cozepy/auth/__init__.py
[warning] 664-667: cozepy/auth/init.py#L664-L667
Added lines #L664 - L667 were not covered by tests
[warning] 669-679: cozepy/auth/init.py#L669-L679
Added lines #L669 - L679 were not covered by tests
[warning] 681-681: cozepy/auth/init.py#L681
Added line #L681 was not covered by tests
🔇 Additional comments (4)
examples/chat_stream.py (1)
4-4
: Add tests for the chat stream functionality.The TODO comment indicates missing tests. Consider adding tests to verify:
- Proper handling of chat events
- Error scenarios
- Stream completion
Would you like me to help create a test suite for this functionality?
examples/websockets_audio_speech.py (1)
Line range hint
55-120
: Well-structured async implementation!The WebSocket audio speech implementation demonstrates good practices:
- Proper async/await usage
- Comprehensive error handling
- Clear event handling structure
cozepy/__init__.py (1)
21-21
: LGTM!The changes correctly expose the new
load_oauth_app_from_config
function in the module's public API.Also applies to: 163-163
examples/websockets_chat_realtime_gui.py (1)
22-22
: LGTM!The imports are correctly updated to use the main package exports.
Also applies to: 25-25
a430938
to
d37c7f3
Compare
Summary by CodeRabbit
New Features
load_oauth_app_from_config
function to simplify OAuth app configuration.Refactor
examples/utils/__init__.py
and integrated its functions directly into example scripts.Documentation