Create ai.py
Browse files
ai.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
+
|
| 5 |
+
# Define the model details
|
| 6 |
+
model_name = "mradermacher/Llama3.3-8B-Instruct-Thinking-Heretic-Uncensored-Claude-4.5-Opus-High-Reasoning-i1-GGUF" # Changing to Deepseek Coder Instruct (6.7B parameters)
|
| 7 |
+
model_file = "Llama3.3-8B-Instruct-Thinking-Heretic-Uncensored-Claude-4.5-Opus-High-Reasoning.i1-Q6_K.gguf" # A quantized model file for Deepseek Coder
|
| 8 |
+
|
| 9 |
+
# Define the path where the model will be downloaded
|
| 10 |
+
model_path = os.path.join(os.getcwd(), model_file)
|
| 11 |
+
|
| 12 |
+
# Download the model if it doesn't exist
|
| 13 |
+
if not os.path.exists(model_path):
|
| 14 |
+
print(f"Downloading {model_file} from Hugging Face Hub...")
|
| 15 |
+
hf_hub_download(
|
| 16 |
+
repo_id=model_name,
|
| 17 |
+
filename=model_file,
|
| 18 |
+
local_dir=os.getcwd(),
|
| 19 |
+
local_dir_use_symlinks=False,
|
| 20 |
+
)
|
| 21 |
+
print("Download complete.")
|
| 22 |
+
else:
|
| 23 |
+
print(f"{model_file} already exists, skipping download.")
|
| 24 |
+
|
| 25 |
+
# Initialize the Llama model
|
| 26 |
+
print("Initializing Llama model...")
|
| 27 |
+
llm = Llama(model_path=model_path, n_ctx=2048, n_gpu_layers=-1)
|
| 28 |
+
print("Model initialized.")
|
| 29 |
+
|
| 30 |
+
# Example of using the model
|
| 31 |
+
prompt = "Q: What is the capital of China? A:"
|
| 32 |
+
print(f"\nUser: {prompt}")
|
| 33 |
+
|
| 34 |
+
output = llm(
|
| 35 |
+
prompt,
|
| 36 |
+
max_tokens=2048,
|
| 37 |
+
stop=["Q:", "\n"],
|
| 38 |
+
echo=True,
|
| 39 |
+
temperature=0.7,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
print("LLM Output:")
|
| 43 |
+
print(output["choices"][0]["text"])
|
| 44 |
+
|
| 45 |
+
print("\nThis demonstrates how to run a local LLM using llama-cpp-python in Colab.")
|