Spaces:
Sleeping
Sleeping
caiocampos-hotmart
commited on
Commit
·
fcba0d8
1
Parent(s):
a6981fd
chore: improve logs
Browse files- Dockerfile +4 -0
- app.py +18 -18
Dockerfile
CHANGED
@@ -8,6 +8,10 @@ ENV PATH="/home/user/.local/bin:$PATH"
|
|
8 |
ENV CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS"
|
9 |
ENV FORCE_CMAKE=1
|
10 |
|
|
|
|
|
|
|
|
|
11 |
WORKDIR /app
|
12 |
|
13 |
COPY --chown=user ./requirements.txt requirements.txt
|
|
|
8 |
ENV CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS"
|
9 |
ENV FORCE_CMAKE=1
|
10 |
|
11 |
+
# Forçar logs em tempo real
|
12 |
+
ENV PYTHONUNBUFFERED=1
|
13 |
+
ENV PYTHONIOENCODING=utf-8
|
14 |
+
|
15 |
WORKDIR /app
|
16 |
|
17 |
COPY --chown=user ./requirements.txt requirements.txt
|
app.py
CHANGED
@@ -22,25 +22,25 @@ class LocalLLMAgent:
|
|
22 |
model_path = "./llama-2-7b-chat.Q4_K_M.gguf"
|
23 |
|
24 |
if not os.path.exists(model_path):
|
25 |
-
print("📥 Baixando modelo Llama-2-7B-Chat (Q4_K_M)...")
|
26 |
-
print(" Isso pode levar alguns minutos...")
|
27 |
model_path = hf_hub_download(
|
28 |
repo_id="TheBloke/Llama-2-7B-Chat-GGUF",
|
29 |
filename="llama-2-7b-chat.Q4_K_M.gguf",
|
30 |
local_dir="./"
|
31 |
)
|
32 |
-
print("✅ Modelo baixado com sucesso!")
|
33 |
else:
|
34 |
-
print("📁 Modelo já existe, carregando...")
|
35 |
|
36 |
# Configura para usar todas as CPUs disponíveis
|
37 |
n_threads = multiprocessing.cpu_count()
|
38 |
-
print(f"🔧 Configurando llama-cpp-python:")
|
39 |
-
print(f" - CPUs disponíveis: {n_threads}")
|
40 |
-
print(f" - Threads: {n_threads}")
|
41 |
-
print(f" - Contexto: 2048 tokens")
|
42 |
|
43 |
-
print("🚀 Inicializando modelo...")
|
44 |
self.llm = Llama(
|
45 |
model_path=model_path,
|
46 |
chat_format="llama-2",
|
@@ -49,7 +49,7 @@ class LocalLLMAgent:
|
|
49 |
n_threads_batch=n_threads,
|
50 |
verbose=False
|
51 |
)
|
52 |
-
print(f"✅ Modelo carregado! Usando {n_threads} threads")
|
53 |
self.messages = [
|
54 |
{"role": "system", "content": "Responda sempre em português brasileiro de forma natural e conversacional."}
|
55 |
]
|
@@ -77,18 +77,18 @@ agent = None
|
|
77 |
|
78 |
@app.on_event("startup")
|
79 |
async def startup_event():
|
80 |
-
print("=== INICIANDO LLM AGENT API ===")
|
81 |
-
print(f"CPUs disponíveis: {multiprocessing.cpu_count()}")
|
82 |
-
print(f"Memória total: {round(psutil.virtual_memory().total / (1024**3), 2)} GB")
|
83 |
|
84 |
global agent
|
85 |
agent = LocalLLMAgent()
|
86 |
|
87 |
-
print("✅ API pronta para uso!")
|
88 |
-
print("Endpoints disponíveis:")
|
89 |
-
print(" - POST /chat")
|
90 |
-
print(" - GET /health")
|
91 |
-
print(" - GET /system")
|
92 |
|
93 |
@app.post("/chat", response_model=ChatResponse)
|
94 |
async def chat_endpoint(request: ChatRequest):
|
|
|
22 |
model_path = "./llama-2-7b-chat.Q4_K_M.gguf"
|
23 |
|
24 |
if not os.path.exists(model_path):
|
25 |
+
print("📥 Baixando modelo Llama-2-7B-Chat (Q4_K_M)...", flush=True)
|
26 |
+
print(" Isso pode levar alguns minutos...", flush=True)
|
27 |
model_path = hf_hub_download(
|
28 |
repo_id="TheBloke/Llama-2-7B-Chat-GGUF",
|
29 |
filename="llama-2-7b-chat.Q4_K_M.gguf",
|
30 |
local_dir="./"
|
31 |
)
|
32 |
+
print("✅ Modelo baixado com sucesso!", flush=True)
|
33 |
else:
|
34 |
+
print("📁 Modelo já existe, carregando...", flush=True)
|
35 |
|
36 |
# Configura para usar todas as CPUs disponíveis
|
37 |
n_threads = multiprocessing.cpu_count()
|
38 |
+
print(f"🔧 Configurando llama-cpp-python:", flush=True)
|
39 |
+
print(f" - CPUs disponíveis: {n_threads}", flush=True)
|
40 |
+
print(f" - Threads: {n_threads}", flush=True)
|
41 |
+
print(f" - Contexto: 2048 tokens", flush=True)
|
42 |
|
43 |
+
print("🚀 Inicializando modelo...", flush=True)
|
44 |
self.llm = Llama(
|
45 |
model_path=model_path,
|
46 |
chat_format="llama-2",
|
|
|
49 |
n_threads_batch=n_threads,
|
50 |
verbose=False
|
51 |
)
|
52 |
+
print(f"✅ Modelo carregado! Usando {n_threads} threads", flush=True)
|
53 |
self.messages = [
|
54 |
{"role": "system", "content": "Responda sempre em português brasileiro de forma natural e conversacional."}
|
55 |
]
|
|
|
77 |
|
78 |
@app.on_event("startup")
|
79 |
async def startup_event():
|
80 |
+
print("=== INICIANDO LLM AGENT API ===", flush=True)
|
81 |
+
print(f"CPUs disponíveis: {multiprocessing.cpu_count()}", flush=True)
|
82 |
+
print(f"Memória total: {round(psutil.virtual_memory().total / (1024**3), 2)} GB", flush=True)
|
83 |
|
84 |
global agent
|
85 |
agent = LocalLLMAgent()
|
86 |
|
87 |
+
print("✅ API pronta para uso!", flush=True)
|
88 |
+
print("Endpoints disponíveis:", flush=True)
|
89 |
+
print(" - POST /chat", flush=True)
|
90 |
+
print(" - GET /health", flush=True)
|
91 |
+
print(" - GET /system", flush=True)
|
92 |
|
93 |
@app.post("/chat", response_model=ChatResponse)
|
94 |
async def chat_endpoint(request: ChatRequest):
|