|
|
|
|
|
"""
|
|
|
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)
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
model_path = ensure_model_exists()
|
|
|
|
|
|
|
|
|
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() |