|
|
|
""" |
|
Simple test script to check if llama-cpp-python works |
|
""" |
|
|
|
import os |
|
import logging |
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
logger = logging.getLogger(__name__) |
|
|
|
def test_llama_cpp(): |
|
"""Test llama-cpp-python import and basic functionality""" |
|
try: |
|
logger.info("π§ͺ Testing llama-cpp-python import...") |
|
from llama_cpp import Llama |
|
logger.info("β
llama-cpp-python imported successfully") |
|
|
|
|
|
logger.info("π§ͺ Testing Gemma 3n GGUF model loading...") |
|
try: |
|
llm = Llama.from_pretrained( |
|
repo_id="unsloth/gemma-3n-E4B-it-GGUF", |
|
filename="*q4_k_m.gguf", |
|
verbose=True, |
|
n_ctx=1024, |
|
n_threads=2, |
|
n_gpu_layers=0, |
|
) |
|
logger.info("β
Successfully loaded Gemma 3n GGUF model!") |
|
|
|
|
|
logger.info("π§ͺ Testing simple generation...") |
|
response = llm("Hello", max_tokens=10, echo=False) |
|
logger.info(f"β
Generation test successful: {response}") |
|
|
|
except Exception as model_error: |
|
logger.warning(f"β οΈ Model loading failed (expected): {model_error}") |
|
logger.info("π‘ This is normal if you haven't downloaded the GGUF model file yet") |
|
logger.info("π‘ To download, visit: https://huggingface.co/unsloth/gemma-3n-E4B-it-GGUF") |
|
|
|
return True |
|
|
|
except ImportError as e: |
|
logger.error(f"β llama-cpp-python import failed: {e}") |
|
return False |
|
except Exception as e: |
|
logger.error(f"β Unexpected error: {e}") |
|
return False |
|
|
|
def test_minimal_fastapi(): |
|
"""Test a minimal FastAPI setup without transformers""" |
|
try: |
|
logger.info("π§ͺ Testing minimal FastAPI setup...") |
|
from fastapi import FastAPI |
|
from uvicorn import run |
|
logger.info("β
FastAPI imports successful") |
|
|
|
app = FastAPI(title="Test API") |
|
|
|
@app.get("/") |
|
def root(): |
|
return {"message": "Hello from test API!"} |
|
|
|
@app.get("/health") |
|
def health(): |
|
return {"status": "healthy", "llama_cpp_available": True} |
|
|
|
logger.info("β
Minimal FastAPI app created successfully") |
|
logger.info("π You can test this by running: uvicorn test_gguf:app --reload") |
|
|
|
return app |
|
|
|
except Exception as e: |
|
logger.error(f"β FastAPI test failed: {e}") |
|
return None |
|
|
|
if __name__ == "__main__": |
|
logger.info("π§ͺ Starting GGUF model integration tests...") |
|
|
|
|
|
llama_success = test_llama_cpp() |
|
|
|
|
|
app = test_minimal_fastapi() |
|
|
|
if llama_success and app: |
|
logger.info("β
All tests passed! Ready for GGUF model integration") |
|
logger.info("π‘ Next steps:") |
|
logger.info("π‘ 1. Download GGUF model: https://huggingface.co/unsloth/gemma-3n-E4B-it-GGUF") |
|
logger.info("π‘ 2. Run: uvicorn test_gguf:app --reload") |
|
logger.info("π‘ 3. Test at: http://localhost:8000/health") |
|
else: |
|
logger.error("β Some tests failed. Check the logs above.") |
|
|