File size: 2,204 Bytes
72e55e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
"""

Main application entry point for ContinuumAgent

Starts the FastAPI server and initializes all components

"""

import os
import sys
import uvicorn
from huggingface_hub import hf_hub_download
from fastapi import FastAPI
from app.main import app as fastapi_app

def ensure_model_exists():
    """

    Ensure the GGUF model exists, download if needed

    

    Returns:

        Path to the model file

    """
    model_dir = "models/slow"
    os.makedirs(model_dir, exist_ok=True)
    
    # Look for existing model
    model_files = [f for f in os.listdir(model_dir) if f.endswith(".gguf")]
    
    if model_files:
        model_path = os.path.join(model_dir, model_files[0])
        print(f"Using existing model: {model_path}")
        return model_path
    
    # Download model
    try:
        print("Downloading Mistral-7B-Instruct model (quantized)...")
        model_path = hf_hub_download(
            repo_id="TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
            filename="mistral-7b-instruct-v0.2.Q4_K_M.gguf",
            local_dir=model_dir
        )
        print(f"Successfully downloaded model to: {model_path}")
        return model_path
    except Exception as e:
        print(f"Error downloading model: {e}")
        print("Please download the model manually and place it in the models/slow directory")
        sys.exit(1)

def create_directory_structure():
    """Create required directory structure"""
    os.makedirs("models/slow", exist_ok=True)
    os.makedirs("models/patches", exist_ok=True)
    os.makedirs("models/registry", exist_ok=True)
    os.makedirs("models/gates", exist_ok=True)
    os.makedirs("data/wiki_edits", exist_ok=True)

def main():
    """Main entry point"""
    # Create directory structure
    create_directory_structure()
    
    # Ensure model exists
    model_path = ensure_model_exists()
    
    # Run server
    host = os.environ.get("HOST", "0.0.0.0")
    port = int(os.environ.get("PORT", "8000"))
    
    print(f"Starting ContinuumAgent server on {host}:{port}")
    uvicorn.run(fastapi_app, host=host, port=port)

if __name__ == "__main__":
    main()