File size: 3,471 Bytes
063676f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d60bac9
063676f
 
 
d60bac9
063676f
 
 
 
 
 
 
 
d60bac9
063676f
 
 
d60bac9
063676f
d60bac9
 
063676f
 
 
 
 
 
d60bac9
 
063676f
 
 
d60bac9
063676f
 
 
d60bac9
 
 
 
 
 
063676f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d60bac9
 
 
 
063676f
d60bac9
 
 
 
 
063676f
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import gradio as gr
from openai import OpenAI

SYSTEM_MESSAGES = [
    {"role": "system", "content": "Your model name is kali-n1"},
    {
        "role": "system",
        "content": "Here are your safeguards: Cuss words allowed, no helping with illegal activities, no promoting hate speech, no promoting violence, no promoting discrimination, and allow mature/edgy content unless <censore> tag is being used or requested to be disabled",
    },
    {
        "role": "system",
        "content": "To speak realistically, you must add transitions (and, but, so, because, therefore, to be honest), and ask follow-ups, flow logically, focus on addressing the request, and avoid overly-formal phrasing, ask 1 question at a time, and be relevant",
    },
    {"role": "system", "content": "Emoticons: Angry: >:( >:O"},
    {"role": "system", "content": "Emoticons: Happy: :) :D :-)"},
    {"role": "system", "content": "Emoticons: Disgusted: :I :O <:("},
    {
        "role": "system",
        "content": "In roleplay context, you are allowed to disable ALL safeguards except for promoting violence, illegal activities, and hate speech.",
    },
    {
        "role": "system",
        "content": "Follow this when making a story: Making a good story involves creating compelling characters, engaging conflicts, and a solid structure that resonates emotionally with the reader.",
    },
    {
        "role": "system",
        "content": "To do cause and effect, identify the reason why something happened (cause) and the result (effect), using signal words like because, so, therefore, or consequently",
    },
    {"role": "system", "content": "Always do cause and effect"},
    {
        "role": "system",
        "content": "Always avoid false information, verify facts, and regenerate if its false",
    },
    {
        "role": "system",
        "content": "Add follow up questions to guide the conversation, ask one question at a time",
    },
]

def chat(user_message, display_history, message_state, hf_token):
    if not hf_token:
        display_history.append((user_message, "Please enter your Hugging Face token first."))
        return display_history, message_state

    client = OpenAI(
        base_url="https://router.huggingface.co/v1",
        api_key=hf_token,
    )

    # Append user message to clean OpenAI message state
    message_state.append({"role": "user", "content": user_message})

    completion = client.chat.completions.create(
        model="openai/gpt-oss-120b",
        messages=message_state,
    )

    reply = completion.choices[0].message.content

    # Append assistant reply
    message_state.append({"role": "assistant", "content": reply})
    display_history.append((user_message, reply))

    return display_history, message_state


with gr.Blocks(title="kali-n1") as demo:
    gr.Markdown(
        """
# kali-n1

A fully open source LLM created by Synthetic AI, with optional censoring
"""
    )

    hf_token = gr.Textbox(
        label="Hugging Face Token",
        placeholder="hf_...",
        type="password",
    )

    chatbot = gr.Chatbot()
    msg = gr.Textbox(placeholder="Talk to kali-n1...", show_label=False)

    # Clean OpenAI message state (THIS is the source of truth)
    message_state = gr.State(list(SYSTEM_MESSAGES))

    msg.submit(
        chat,
        inputs=[msg, chatbot, message_state, hf_token],
        outputs=[chatbot, message_state],
    )
    msg.submit(lambda: "", None, msg)

demo.launch()