File size: 1,150 Bytes
90c2c03
 
 
 
2aa136b
90c2c03
 
58e6740
 
90c2c03
 
 
58e6740
 
 
 
 
 
90c2c03
58e6740
90c2c03
 
 
aaf6200
90c2c03
 
 
 
 
 
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
import gradio as gr
from huggingface_hub import InferenceClient

# 1. Pilih model coding terbaik yang gratis via API
client = InferenceClient("Qwen/Qwen3-Coder-30B-A3B-Instruct")

def respond(message, history):
    # System prompt
    system_prompt = "Anda adalah Senior AI Software Architect. Berikan solusi kode yang bersih dan efisien."
    
    messages = [{"role": "system", "content": system_prompt}]
    
    # Perbaikan: Menggunakan format history yang kompatibel dengan Gradio terbaru
    for item in history:
        # Jika history berisi list [user, bot]
        if isinstance(item, (list, tuple)) and len(item) == 2:
            messages.append({"role": "user", "content": item[0]})
            messages.append({"role": "assistant", "content": item[1]})
    
    # Tambahkan pesan user terbaru
    messages.append({"role": "user", "content": message})
    
    response = ""
    for chunk in client.chat_completion(messages, max_tokens=8192, stream=True):
        response += chunk.choices[0].delta.content or ""
        yield response

# 5. UI Gradio
demo = gr.ChatInterface(fn=respond, title="AI Coding Assistant Pribadi")
demo.launch()