File size: 1,261 Bytes
4519526
48f1030
38facca
 
48f1030
d451934
 
48f1030
38facca
4519526
d451934
 
 
 
 
 
38facca
 
48f1030
38facca
48f1030
d451934
 
 
 
4519526
 
48f1030
 
d451934
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from ctransformers import AutoModelForCausalLM
from huggingface_hub import hf_hub_download
import gradio as gr

model_path = hf_hub_download(
    repo_id="RavikxxBGamin/MinecraftAI",
    filename="llama-3.2-3b-instruct.Q4_K_M.gguf"
)

llm = AutoModelForCausalLM.from_pretrained(
    model_path,
    model_type="llama",
    context_length=4096,
    max_new_tokens=1024,
    temperature=0.7,
    local_files_only=True
)

SYSTEM_PROMPT = "You are a helpful Minecraft plugin development and Java programming assistant. You are patient and explanatory. Always format code inside code blocks."

def chat(message, history):
    prompt = "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n" + SYSTEM_PROMPT + "<|eot_id|>"
    for user_msg, assistant_msg in history:
        prompt += "<|start_header_id|>user<|end_header_id|>\n" + user_msg + "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n" + assistant_msg + "<|eot_id|>"
    prompt += "<|start_header_id|>user<|end_header_id|>\n" + message + "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n"
    response = llm(prompt)
    return response

gr.ChatInterface(
    fn=chat,
    title="MinecraftAI",
    description="A Minecraft plugin development and Java programming assistant"
).launch()