HonestAI / TEST_NOVITA_CONNECTION.md
JatsTheAIGen's picture
Integrate Novita AI as exclusive inference provider - Add Novita AI API integration with DeepSeek-R1-Distill-Qwen-7B model - Remove all local model dependencies - Optimize token allocation for user inputs and context - Add Anaconda environment setup files - Add comprehensive test scripts and documentation
927854c

Testing Novita AI Connection

Quick Test Instructions

Option 1: Run Test Script (Recommended)

  1. Ensure Python is available:

    # Check Python version
    python --version
    # OR
    python3 --version
    # OR (Windows)
    py --version
    
  2. Install dependencies if needed:

    pip install openai>=1.0.0
    pip install -r requirements.txt
    
  3. Set environment variables:

    # Windows (PowerShell)
    $env:NOVITA_API_KEY="your_api_key_here"
    $env:NOVITA_BASE_URL="https://api.novita.ai/dedicated/v1/openai"
    $env:NOVITA_MODEL="deepseek-ai/DeepSeek-R1-Distill-Qwen-7B:de-1a706eeafbf3ebc2"
    
    # Windows (CMD)
    set NOVITA_API_KEY=your_api_key_here
    set NOVITA_BASE_URL=https://api.novita.ai/dedicated/v1/openai
    set NOVITA_MODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-7B:de-1a706eeafbf3ebc2
    
    # Linux/Mac
    export NOVITA_API_KEY=your_api_key_here
    export NOVITA_BASE_URL=https://api.novita.ai/dedicated/v1/openai
    export NOVITA_MODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-7B:de-1a706eeafbf3ebc2
    
  4. Run the test script:

    python test_novita_connection.py
    # OR
    python3 test_novita_connection.py
    # OR (Windows)
    py test_novita_connection.py
    

Option 2: Manual Python Test

Create a simple test file quick_test.py:

import os
from openai import OpenAI

# Get API key from environment
api_key = os.getenv("NOVITA_API_KEY")
base_url = os.getenv("NOVITA_BASE_URL", "https://api.novita.ai/dedicated/v1/openai")
model = os.getenv("NOVITA_MODEL", "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B:de-1a706eeafbf3ebc2")

if not api_key:
    print("ERROR: NOVITA_API_KEY not set!")
    exit(1)

print(f"Testing Novita AI connection...")
print(f"Base URL: {base_url}")
print(f"Model: {model}")

client = OpenAI(
    base_url=base_url,
    api_key=api_key,
)

try:
    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": "Say 'Hello' if you can hear me."}],
        max_tokens=20,
        temperature=0.6
    )
    
    if response.choices:
        print(f"\nβœ“ SUCCESS! Connection working.")
        print(f"Response: {response.choices[0].message.content}")
    else:
        print("\n❌ No response received")
        
except Exception as e:
    print(f"\n❌ ERROR: {e}")

Run it:

python quick_test.py

Option 3: Test via API Endpoint

If the Flask server is running:

  1. Start the server:

    python flask_api_standalone.py
    
  2. Test health endpoint:

    curl http://localhost:7860/api/health
    # OR
    # Visit http://localhost:7860/api/health in browser
    
  3. Test chat endpoint:

    curl -X POST http://localhost:7860/api/chat \
      -H "Content-Type: application/json" \
      -d '{"message": "Hello", "session_id": "test-123"}'
    

Expected Test Results

Successful Test Output:

============================================================
NOVITA AI CONNECTION TEST
============================================================

============================================================
TEST 1: Configuration Loading
============================================================
βœ“ Configuration loaded successfully
  Novita API Key: Set
  Base URL: https://api.novita.ai/dedicated/v1/openai
  Model: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B:de-1a706eeafbf3ebc2
  Temperature: 0.6
  Force Reasoning: True
  User Input Max Tokens: 8000
  Context Preparation Budget: 28000

============================================================
TEST 2: OpenAI Package Check
============================================================
βœ“ OpenAI package is available

============================================================
TEST 3: Novita AI Client Initialization
============================================================
βœ“ Novita AI client initialized successfully
  Base URL: https://api.novita.ai/dedicated/v1/openai
  API Key: nv-****

============================================================
TEST 4: Simple API Call
============================================================
Sending test request to: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B:de-1a706eeafbf3ebc2
Prompt: 'Hello, this is a test. Please respond briefly.'
βœ“ API call successful!
  Response length: XX characters
  Response preview: ...

============================================================
TEST 5: LLM Router Initialization
============================================================
Initializing LLM Router...
βœ“ LLM Router initialized successfully

Testing health check...
βœ“ Health check result: {'provider': 'novita_api', 'status': 'healthy', ...}

============================================================
TEST 6: Inference Test
============================================================
Test prompt: What is the capital of France? Answer in one sentence.
βœ“ Inference successful!
  Response length: XX characters
  Response: ...

============================================================
TEST SUMMARY
============================================================
  CONFIG: βœ“ PASS
  PACKAGE: βœ“ PASS
  CLIENT: βœ“ PASS
  API_CALL: βœ“ PASS
  ROUTER: βœ“ PASS
  INFERENCE: βœ“ PASS

Total: 6/6 tests passed

πŸŽ‰ All tests passed! Novita AI connection is working correctly.

Troubleshooting

Error: "NOVITA_API_KEY is required"

Solution: Set the environment variable:

export NOVITA_API_KEY=your_key_here

Error: "openai package not available"

Solution: Install the package:

pip install openai>=1.0.0

Error: "Failed to initialize Novita AI client"

Solution:

  • Verify API key is correct
  • Check base URL matches your endpoint
  • Verify network connectivity

Error: "API call failed"

Solution:

  • Check API key has proper permissions
  • Verify model ID matches your deployment
  • Check Novita AI service status