import os import requests from pathlib import Path from ctransformers import AutoModelForCausalLM # ✅ Auto-download TinyLlama from your HF repo if not present MODEL_URL = "https://huggingface.co/abhidgp1978/abhi-model/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf" MODEL_PATH = Path("models/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf") MODEL_PATH.parent.mkdir(parents=True, exist_ok=True) if not MODEL_PATH.exists(): print("🔁 Downloading TinyLlama model...") r = requests.get(MODEL_URL, stream=True) with open(MODEL_PATH, "wb") as f: for chunk in r.iter_content(chunk_size=8192): if chunk: f.write(chunk) print("✅ Model download complete.") # ✅ Load TinyLlama locally llm = AutoModelForCausalLM.from_pretrained( str(MODEL_PATH), model_type="llama", gpu_layers=0 ) # ✅ Standard LLM call def llm_call(prompt, max_tokens=256, stream=False): return llm( prompt, max_new_tokens=max_tokens, temperature=0.7, stop=["User:", "Assistant:"], stream=stream )