Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import json
|
| 3 |
from fastapi import FastAPI, HTTPException
|
| 4 |
from fastapi.responses import StreamingResponse
|
|
|
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from typing import List, Dict
|
| 7 |
from pymongo import MongoClient
|
|
@@ -10,6 +11,17 @@ from llama_cpp import Llama
|
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# --- CONFIGURATION LAYER ---
|
| 14 |
REPO_ID = "Qwen/Qwen2.5-Coder-7B-Instruct-GGUF"
|
| 15 |
MODEL_FILENAME = "qwen2.5-coder-7b-instruct-q4_k_m.gguf"
|
|
@@ -65,15 +77,12 @@ if not os.path.exists(MODEL_PATH):
|
|
| 65 |
raise RuntimeError(f"Failed to automatically pull weights from Hugging Face Hub: {str(e)}")
|
| 66 |
|
| 67 |
print("Allocating system RAM pool and pinning LLM matrix...")
|
| 68 |
-
|
| 69 |
-
# --- ALL CRITICAL ARGUMENTS CONSOLIDATED HERE ---
|
| 70 |
llm = Llama(
|
| 71 |
model_path=MODEL_PATH,
|
| 72 |
-
n_ctx=2048,
|
| 73 |
-
n_threads=4,
|
| 74 |
chat_format="chatml" # Forces the model to use ChatML formatting so it doesn't speak gibberish
|
| 75 |
)
|
| 76 |
-
# ------------------------------------------------
|
| 77 |
|
| 78 |
# Populate the RAM cache immediately on server startup
|
| 79 |
refresh_knowledge_cache()
|
|
|
|
| 2 |
import json
|
| 3 |
from fastapi import FastAPI, HTTPException
|
| 4 |
from fastapi.responses import StreamingResponse
|
| 5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from typing import List, Dict
|
| 8 |
from pymongo import MongoClient
|
|
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
| 14 |
+
# --- CORS SECURITY MIDDLEWARE LAYER ---
|
| 15 |
+
# This permits browser-based applications (like Chatbox Web) to connect seamlessly
|
| 16 |
+
app.add_middleware(
|
| 17 |
+
CORSMiddleware,
|
| 18 |
+
allow_origins=["*"], # Permits connections from any domain origin
|
| 19 |
+
allow_credentials=True,
|
| 20 |
+
allow_methods=["*"], # Permits all HTTP methods (GET, POST, OPTIONS, etc.)
|
| 21 |
+
allow_headers=["*"], # Permits all network headers
|
| 22 |
+
)
|
| 23 |
+
# --------------------------------------
|
| 24 |
+
|
| 25 |
# --- CONFIGURATION LAYER ---
|
| 26 |
REPO_ID = "Qwen/Qwen2.5-Coder-7B-Instruct-GGUF"
|
| 27 |
MODEL_FILENAME = "qwen2.5-coder-7b-instruct-q4_k_m.gguf"
|
|
|
|
| 77 |
raise RuntimeError(f"Failed to automatically pull weights from Hugging Face Hub: {str(e)}")
|
| 78 |
|
| 79 |
print("Allocating system RAM pool and pinning LLM matrix...")
|
|
|
|
|
|
|
| 80 |
llm = Llama(
|
| 81 |
model_path=MODEL_PATH,
|
| 82 |
+
n_ctx=2048,
|
| 83 |
+
n_threads=4,
|
| 84 |
chat_format="chatml" # Forces the model to use ChatML formatting so it doesn't speak gibberish
|
| 85 |
)
|
|
|
|
| 86 |
|
| 87 |
# Populate the RAM cache immediately on server startup
|
| 88 |
refresh_knowledge_cache()
|