Skip to content

Conversation

@codegen-sh
Copy link

@codegen-sh codegen-sh bot commented Oct 13, 2025

Summary

Successfully consolidated redundant bash scripts into 4 clean, functional workflow scripts that are fully tested and working.

What Changed

Replaced multiple redundant scripts with 4 main scripts:

1. setup.sh - Full Program Setup

  • Installs uv package manager if not present
  • Installs Python dependencies using Python 3.11
  • Creates .env configuration file with sensible defaults
  • Prepares database initialization

2. start.sh - Start Configured Server

  • Verifies setup completion
  • Starts FastAPI server with Granian
  • Provides URLs for admin panel and API docs

3. send_request.sh - API Testing

  • Waits for server readiness
  • Tests non-streaming chat completions
  • Tests streaming responses
  • Tests models list endpoint
  • Provides colored output with test results

4. all.sh - Complete Workflow

  • Orchestrates full workflow: setup → start → test
  • Runs server in background with logging
  • Executes all tests automatically
  • Handles cleanup on exit

Technical Fixes

Fixed critical Python version compatibility issues:

  • ✅ Explicitly uses Python 3.11 via uv sync --python /usr/bin/python3.11
  • ✅ Runs with .venv/bin/python directly (no activation needed)
  • ✅ Clears PYTHONPATH to prevent sys.path conflicts with Python 3.13

Testing Results

All scripts tested successfully with Z.AI authentication:

export ZAI_EMAIL="developer@pixelium.uk"
export ZAI_PASSWORD="developer1?"
bash scripts/all.sh

Test Output

✅ Server started successfully on port 8080
✅ Non-streaming chat completion: PASSED
✅ Streaming chat completion: PASSED
✅ Models list retrieval: PASSED

Available Models:

  • GLM-4.5, GLM-4.5-Thinking, GLM-4.5-Search, GLM-4.5-Air
  • GLM-4.6, GLM-4.6-Thinking, GLM-4.6-Search
  • MBZUAI-IFM/K2-Think
  • LongCat, LongCat-Flash, LongCat-Search

Usage

# Full workflow (recommended for first time)
bash scripts/all.sh

# Individual scripts
bash scripts/setup.sh       # Setup only
bash scripts/start.sh       # Start server
bash scripts/send_request.sh # Test API

Files Changed

  • Added: scripts/all.sh (3.1KB)
  • Added: scripts/send_request.sh (4.8KB)
  • Added: scripts/setup.sh (2.3KB)
  • Added: scripts/start.sh (1.1KB)

💻 View my work • 👤 Initiated by @ZeeeepaAbout Codegen
⛔ Remove Codegen from PR🚫 Ban action checks


Summary by cubic

Consolidated many bash scripts into four simple workflow scripts (setup, start, test, all) to streamline local setup, running, and testing. Ensures a consistent Python 3.11 runtime and reduces setup errors.

  • New Features

    • setup.sh: Installs uv deps with Python 3.11 and creates a .env with sensible defaults.
    • start.sh: Starts the FastAPI server with helpful URLs.
    • send_request.sh: Runs basic API tests (non-streaming, streaming, models).
    • all.sh: One command to setup → start → test with logging and cleanup.
  • Bug Fixes

    • Pins Python to 3.11 via uv sync.
    • Runs with .venv/bin/python and clears PYTHONPATH to avoid 3.13 path conflicts.

- setup.sh: Full program setup (dependencies + configuration)
- start.sh: Start configured server
- send_request.sh: Test API with multiple request types
- all.sh: Complete workflow (setup + start + test)

Fixed Python version compatibility issues by:
- Using Python 3.11 explicitly via uv sync
- Running with .venv/bin/python directly
- Clearing PYTHONPATH to avoid sys.path conflicts

All scripts tested and working with Z.AI authentication.

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 4 files

Prompt for AI agents (all 2 issues)

Understand the root cause of the following 2 issues and fix them.


<file name="scripts/setup.sh">

<violation number="1" location="scripts/setup.sh:34">
Hardcoding `/usr/bin/python3.11` makes `uv sync` fail on machines without that interpreter (common on macOS and many Linux distros), aborting setup under `set -e`. Please detect the interpreter dynamically or fall back gracefully.</violation>
</file>

<file name="scripts/start.sh">

<violation number="1" location="scripts/start.sh:21">
This dependency check should abort when either the virtual environment or the uv lockfile is missing; otherwise the server attempts to run without installed dependencies.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

scripts/setup.sh Outdated

# Install Python dependencies
echo -e "${YELLOW}📦 Installing Python dependencies with Python 3.11...${NC}"
uv sync --python /usr/bin/python3.11
Copy link

@cubic-dev-ai cubic-dev-ai bot Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding /usr/bin/python3.11 makes uv sync fail on machines without that interpreter (common on macOS and many Linux distros), aborting setup under set -e. Please detect the interpreter dynamically or fall back gracefully.

Prompt for AI agents
Address the following comment on scripts/setup.sh at line 34:

<comment>Hardcoding `/usr/bin/python3.11` makes `uv sync` fail on machines without that interpreter (common on macOS and many Linux distros), aborting setup under `set -e`. Please detect the interpreter dynamically or fall back gracefully.</comment>

<file context>
@@ -0,0 +1,77 @@
+
+# Install Python dependencies
+echo -e &quot;${YELLOW}📦 Installing Python dependencies with Python 3.11...${NC}&quot;
+uv sync --python /usr/bin/python3.11
+echo -e &quot;${GREEN}✅ Dependencies installed${NC}&quot;
+
</file context>

✅ Addressed in 4d52055

scripts/start.sh Outdated
exit 1
fi

if [ ! -d .venv ] && [ ! -f uv.lock ]; then
Copy link

@cubic-dev-ai cubic-dev-ai bot Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency check should abort when either the virtual environment or the uv lockfile is missing; otherwise the server attempts to run without installed dependencies.

Prompt for AI agents
Address the following comment on scripts/start.sh at line 21:

<comment>This dependency check should abort when either the virtual environment or the uv lockfile is missing; otherwise the server attempts to run without installed dependencies.</comment>

<file context>
@@ -0,0 +1,39 @@
+    exit 1
+fi
+
+if [ ! -d .venv ] &amp;&amp; [ ! -f uv.lock ]; then
+    echo -e &quot;${RED}❌ Error: Dependencies not installed. Run setup first:${NC}&quot;
+    echo -e &quot;   ${YELLOW}bash scripts/setup.sh${NC}&quot;
</file context>
Suggested change
if [ ! -d .venv ] && [ ! -f uv.lock ]; then
if [ ! -d .venv ] || [ ! -f uv.lock ]; then
Fix with Cubic

codegen-sh bot and others added 12 commits October 13, 2025 23:23
- Implement CaptchaSolver class with support for 3 major services:
  * 2Captcha (recommended)
  * AntiCaptcha
  * CapSolver

- Support 3 captcha types:
  * reCAPTCHA v2
  * hCaptcha
  * Cloudflare Turnstile

- Integration Features:
  * Automatic captcha detection and solving
  * Multi-type captcha fallback chain
  * Async/await implementation for non-blocking operation
  * Configurable timeout (default 120s)
  * Detailed logging for debugging

- Configuration:
  * Added CAPTCHA_SERVICE, CAPTCHA_API_KEY, CAPTCHA_SITE_KEY to settings
  * Environment variable support via .env
  * Example configuration file (.env.captcha.example)

- Documentation:
  * Comprehensive CAPTCHA_SETUP.md guide
  * Step-by-step setup instructions
  * Pricing information for all services
  * Troubleshooting guide
  * Security best practices

- ZAI Provider Updates:
  * Integrated captcha solver into login_with_credentials()
  * Automatic captcha solving when configured
  * Graceful fallback to non-captcha login
  * Fixed login endpoint to /api/v1/auths/signin

This allows automated Z.AI authentication even with captcha protection.

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
- Three authentication options clearly explained
- Step-by-step instructions for each method
- Scripts overview and usage
- Troubleshooting section
- Recommendations for different use cases

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
- Add import for get_captcha_solver
- Implement captcha solving before login attempt
- Try multiple captcha types (reCAPTCHA → hCaptcha → Turnstile)
- Add captcha response to login data when solved
- Graceful fallback if captcha solving fails

This completes the captcha solver implementation that was
partially added in the previous commit.

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
… variable

- Updated start.sh to use main.py directly (not as module)
- Fixed port variable handling (LISTEN_PORT vs PORT)
- Enhanced all.sh with better server management
- Improved send_request.sh test coverage
- All scripts now executable and properly consolidated

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
- Add compatibility for both PORT and LISTEN_PORT environment variables
- Ensures port detection works consistently across all scripts
- Tested and verified working with live server on port 8080

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
- Create init_tokens.py for automated token retrieval and database storage
- Update setup.sh to initialize tokens during setup
- Integrate with TokenDAO for persistent token management
- Add comprehensive error handling and user feedback

Note: Z.AI requires CAPTCHA verification for login
Either configure CAPTCHA solver or extract token manually from browser

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
- Create browser_login.py for automated CAPTCHA-aware login
- Automatically opens browser, fills credentials, extracts tokens
- Falls back to API login if browser automation unavailable
- Saves debug screenshots for troubleshooting
- Update setup.sh to try browser login first
- Add comprehensive BROWSER_LOGIN.md documentation

This solves the Z.AI CAPTCHA requirement by using real browser
automation instead of direct API calls.

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
- Step-by-step guide for extracting tokens from browser
- Multiple methods: environment variable, database, .env file
- Troubleshooting tips and pro tips
- Verification commands to test server

This provides a fast workaround for CAPTCHA requirement

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
Scripts created:
1. setup.sh - Environment setup with token initialization
2. start.sh - Clean server startup with port management
3. send_request.sh - Comprehensive API test suite (8 tests)
4. all.sh - Complete workflow automation with live logs

Features:
- OpenAI SDK compatible (client sends to localhost, routes to Z.AI)
- Automatic token management (browser/API/manual)
- Port conflict detection and cleanup
- Streaming and non-streaming tests
- Real-time log viewing
- Background server management
- Color-coded output and progress indicators

Usage: bash scripts/all.sh

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
Improvements:
- Better page load waiting strategies (networkidle + timeouts)
- More email/password field selectors (11 patterns)
- Fallback to ANY visible input if selectors fail
- Increased wait times for dynamic content
- Better error handling and debug logging
- Multiple screenshot capture points

This should handle most modern login form variations

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
The Z.AI login page requires clicking 'Continue with Email' button
before the email/password input fields appear.

Changes:
- Navigate directly to https://chat.z.ai/auth
- Click 'Continue with Email' button first
- Then fill email/password fields
- Handles CAPTCHA with 30s wait

✅ FULLY WORKING - Successfully extracts and stores token!

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
- setup.sh: Complete env setup + browser login with Playwright
- start.sh: Clean server startup with health checks
- send_request.sh: Comprehensive API testing suite
- all.sh: Master orchestrator with beautiful output

All scripts now work with the proven browser automation!

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>

Co-authored-by: Zeeeepa <zeeeepa@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants