File size: 986 Bytes
bab69fa
c4045db
9674609
 
 
 
cb5378b
9674609
 
c4045db
 
9674609
c4045db
9674609
c4045db
 
 
bab69fa
c4045db
 
 
 
 
bab69fa
 
 
c4045db
 
 
 
 
 
 
 
 
 
 
 
 
bab69fa
 
9674609
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
34
35
36
37
38
39
40
41
42
import gradio as gr
from llama_cpp import Llama
from huggingface_hub import hf_hub_download

# GGUF λ‹€μš΄λ‘œλ“œ
model_path = hf_hub_download(
    repo_id="HaGPT/news-intelligence-chatbot",
    filename="meta-llama-3.1-8b.Q4_K_M.gguf",
)

llm = Llama(
    model_path=model_path,
    n_ctx=4096,
    n_threads=6,
    n_gpu_layers=0,
    verbose=False
)

def chat_fn(message, history):
    messages = []
    for user, bot in history:
        messages.append({"role": "user", "content": user})
        messages.append({"role": "assistant", "content": bot})

    messages.append({"role": "user", "content": message})

    response = llm.create_chat_completion(
        messages=messages,
        max_tokens=512,
        temperature=0.7
    )

    answer = response["choices"][0]["message"]["content"]
    return answer

interface = gr.ChatInterface(
    fn=chat_fn,
    title="πŸ“° News Intelligence Bot",
    description="Your local GGUF chatbot running on llama.cpp"
)

interface.launch()