Spaces:
Runtime error
Runtime error
| 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() | |