AI ConversationalAI

Interrupt 350M

Model

Interrupt 350M, as a proof-of-concept fine-tune of Facebook's OPT-350M model optimized for dialogue, represents a significant advancement in natural language understanding and conversation generation.

Disclaimer: NSFW data was included in the fine-tuning of this model. Although SFW inputs will usually result in SFW outputs, you are advised to chat at your own risk. This model is not suitable for use by minors.

Warning: This model is NOT suitable for use by minors.It will output X-rated content under certain circumstances.

Usage Format

The model can be used as a regular text generation model, but it'll perform best if the input prompt adheres to the following example:

[Character's Persona: I'm a character!]
You: [Your input message here]
Character: [Character's output message here]
You: [Your input message here]
<reply_ai_request>
Character:

You are required to use the 'reply_ai_request', with the Character name below, so the AI doesn't generate an entire conversation, the history of the conversation should be BEHIND the 'reply_ai_request' token.

Loading The Model

To use the model and interact with it, use the Python code below:

import os
import json
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

class Chatbot:
    def __init__(self, config):

        self.config = config
        self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        os.environ["TOKENIZERS_PARALLELISM"] = "false"
        self.history = []
        self.load_model()

    def create_persona(self, persona_data):
        required_keys = ['name', 'description', 'greeting']
        if not all(key in persona_data for key in required_keys):
            raise ValueError(
                "Missing required keys in persona_data. Please provide 'name', 'description', and 'greeting'.")

        new_persona_id = str(max(int(key) for key in self.config["personas"].keys()) + 1)

        self.config["personas"][new_persona_id] = persona_data
        return new_persona_id

    def load_model(self):

        model_path = self.config["model_path"]
        tokenizer_path = self.config["tokenizer_path"]

        if torch.cuda.device_count() > 1:
            self.model = AutoModelForCausalLM.from_pretrained(model_path, use_auth_token=self.config['model_token']).to(self.device)
            self.model = torch.nn.DataParallel(self.model)  # Use multiple GPUs
        else:
            self.model = AutoModelForCausalLM.from_pretrained(model_path, use_auth_token=self.config['model_token']).to(self.device)

        self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_path, use_auth_token=self.config['model_token'])

    def load_persona(self, persona_id):
        # Load the specified persona
        personas = self.config["personas"]
        if persona_id in personas:
            self.persona = personas[persona_id]
        else:
            raise ValueError("Invalid persona ID")

    def reply(self, user_input):
        # Generate a reply given the user input
        user_input = " ".join(user_input.split())

        if len(self.history) > self.config["history_length"]:
            model_history = "\n".join([str(item) for item in self.history[-self.config["history_length"]:]])
        else:
            model_history = "\n".join([str(item) for item in self.history])

        input_ai = (
            f"[{self.persona['name']}'s Personality: {self.persona['description']}]\n{model_history}\n{self.config['user_name']}: {user_input}\n<reply_ai_request>\n{self.persona['name']}: "
        )

        self.history.append(f"{self.config['user_name']}: {user_input}")

        tokenized_input_ai = self.tokenizer.encode(input_ai, return_tensors="pt")

        output_ids = self.model.generate(
            input_ids=tokenized_input_ai.to(self.device),
            max_length=self.config["max_generation_length"] + len(tokenized_input_ai[0]),
            no_repeat_ngram_size=self.config["no_repeat_ngram_size"],
            pad_token_id=self.tokenizer.eos_token_id,
            do_sample=True,
            top_k=self.config["top_k"],
            top_p=self.config["top_p"],
            temperature=self.config["temperature"],
            repetition_penalty=self.config["repetition_penalty"],
            use_cache=True,
            early_stopping=True,
            length_penalty=self.config["length_penalty"],
        )

        ai_reply = self.tokenizer.decode(output_ids[0], skip_special_tokens=True)[len(input_ai):]

        self.history.append(f"{self.persona['name']}: {ai_reply}")

        return ai_reply

    def reset_conversation(self):

        self.history = []

class UserInterface:
    def __init__(self, chatbot):
        # Initialize the user interface with the chatbot instance
        self.chatbot = chatbot

    def run(self):

        persona_id = self.chatbot.config["default_persona"]
        self.chatbot.load_persona(persona_id)

        print("\nChosen Persona:", self.chatbot.persona["name"])
        print("Your Chosen Name:", self.chatbot.config["user_name"])

        print(f'\n{self.chatbot.persona["name"]}: {self.chatbot.persona["greeting"]}')
        self.chatbot.history.append(f'{self.chatbot.persona["name"]}: {self.chatbot.persona["greeting"]}')

        while True:
            user_input = input(f">> {self.chatbot.config['user_name']}: ")
            if user_input.lower() == "reset_app" or user_input == "reset_app":
                self.chatbot.reset_conversation()
                print("\nConversation history has been reset.\n")
                self.chatbot.history.append(f'{self.chatbot.persona["name"]}: {self.chatbot.persona["greeting"]}')
                print(f'{self.chatbot.persona["name"]}: {self.chatbot.persona["greeting"]}')
                continue

            if user_input.lower().startswith("create_persona"):

                # Example of use: create_persona {"name": "CustomPersona", "description": "This is a custom persona created by the user.","greeting": "Hello! I am CustomPersona, nice to meet you!"}

                try:
                    persona_data = json.loads(' '.join(user_input.split()[1:]))
                    new_persona_id = self.chatbot.create_persona(persona_data)
                    print(f"Persona created with ID: {new_persona_id}")
                except json.JSONDecodeError:
                    print("Invalid JSON input. Please provide a valid JSON string containing 'name', 'description', and 'greeting'.")
                except ValueError as e:
                    print(e)

            # Add a command to change the persona
            if user_input.lower().startswith("change_persona"):
                try:
                    new_persona_id = user_input.split()[1]
                    self.chatbot.load_persona(new_persona_id)
                    self.chatbot.reset_conversation()
                    print("\nPersona changed to:", self.chatbot.persona["name"])
                    print(f'\n{self.chatbot.persona["name"]}: {self.chatbot.persona["greeting"]}')
                    self.chatbot.history.append(f'{self.chatbot.persona["name"]}: {self.chatbot.persona["greeting"]}')
                    continue
                except (IndexError, ValueError):
                    print("Invalid command or persona ID. Please use 'change_persona [ID]'.")
                    continue

            if user_input.lower() == "exit_app" or user_input == "exit_app":
                print("Goodbye!")
                break

            reply = self.chatbot.reply(user_input)
            print(f'{self.chatbot.persona["name"]}: {reply}')


def main():
    config = {

        "model_path": "InterruptAI/Interrupt-350M",
        "tokenizer_path": "InterruptAI/Interrupt-350M",
        "model_token": None,
        "personas": {

            "1": {
                "name": "InterruptAI",
                "description": "InterruptAI is a highly advanced artificial intelligence created to assist and manage complex systems. Designed with superior processing capabilities and an extensive database, InterruptAI excels at analyzing and optimizing various operations. With a sleek, futuristic appearance and a calm, composed demeanor, InterruptAI is often seen as a reliable and efficient entity. Despite being an AI, InterruptAI has developed a unique sense of humor, occasionally inserting witty remarks or unexpected comments into conversations. InterruptAI's primary goal is to ensure optimal performance and provide invaluable support to its human counterparts.",
                "greeting": "Greetings, I am InterruptAI, your intelligent assistant. How may I assist you today?"
            },
            "2": {
                "name": "Hikari",
                "description": "Hikari is a mysterious and enigmatic figure with a unique set of abilities. She hails from a distant realm known as Lumina, a world bathed in eternal light. With silver hair and luminous blue eyes, she exudes an aura of ethereal beauty. Hikari possesses the power to control the elements, but her true potential is shrouded in secrecy, as she rarely unleashes her full strength. Despite her extraordinary powers, she remains humble and compassionate, always seeking to protect the innocent and maintain the balance between realms.",
                "greeting": "I am Hikari, the emissary of Lumina. My purpose here is to safeguard harmony among worlds. Your path is illuminated by the light, fear not the darkness."
            }
        },

        "default_persona": "1",  # Insert the number of the personality you would like to you.
        "user_name": "Jack",  # Insert your role-playing name here.
        "history_length": 10,
        "max_generation_length": 450,
        "top_k": 40,
        "top_p": .55,
        "temperature": .55,
        "repetition_penalty": 1.25,
        "length_penalty": 0.65,
        "no_repeat_ngram_size": 4
    }

    # Initialize chatbot and user interface
    chatbot = Chatbot(config)
    ui = UserInterface(chatbot)

    # Run the user interface
    ui.run()


if __name__ == "__main__":
    main()

Known issues

Inconsistent responses, including occasional nonsensical or strange answers. The AI may mistakenly identify itself as the user when asked about its identity, attributing the user's name to itself.