File size: 2,059 Bytes
852c5e1
efd464a
 
 
 
 
 
30ed0b7
 
 
 
efd464a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f920af2
30ed0b7
efd464a
 
 
 
 
031f144
 
efd464a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import gradio as gr
from huggingface_hub import InferenceClient

MODEL_ID = "MiniMaxAI/MiniMax-M2.5"
SYSTEM_PROMPT = "You are a helpful assistant. Your name is MiniMax-M2.5 and is built by MiniMax."

client = InferenceClient(
    provider="novita",
    api_key=os.environ.get("HF_TOKEN"),
)


def respond(message, history, system_message, max_tokens, temperature, top_p):
    messages = [{"role": "system", "content": system_message}]

    for user_msg, assistant_msg in history:
        if user_msg:
            messages.append({"role": "user", "content": user_msg})
        if assistant_msg:
            messages.append({"role": "assistant", "content": assistant_msg})

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

    response = ""
    for chunk in client.chat_completion(
        model=MODEL_ID,
        messages=messages,
        max_tokens=max_tokens,
        stream=True,
        temperature=temperature,
        top_p=top_p,
    ):
        if chunk.choices and chunk.choices[0].delta.content:
            response += chunk.choices[0].delta.content
            yield response


demo = gr.ChatInterface(
    respond,
    title="MiniMax M2.5 Chat",
    description=(
        "Chat with [MiniMax M2.5](https://huggingface.co/MiniMaxAI/MiniMax-M2.5) — "
        "a 230B MoE model (10B active) that is SOTA in coding, agentic tool use, and more."
    ),
    additional_inputs=[
        gr.Textbox(value=SYSTEM_PROMPT, label="System message"),
        gr.Slider(minimum=1, maximum=4096, value=2048, step=1, label="Max new tokens"),
        gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.05, label="Temperature"),
        gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
    ],
    examples=[
        ["Write a Python function to check if a number is prime."],
        ["Explain the difference between TCP and UDP in simple terms."],
        ["Help me write a bash script that monitors disk usage and sends an alert."],
    ],
    cache_examples=False,
)

if __name__ == "__main__":
    demo.launch()