|
!pip install torch |
|
!pip install ctransformers |
|
|
|
import sys |
|
import time |
|
import torch |
|
from ctransformers import AutoModelForCausalLM,AutoConfig |
|
|
|
|
|
|
|
sentence = "Initializing X.." |
|
words = sentence.split() |
|
|
|
for word in words: |
|
sys.stdout.flush() |
|
print(word, end=' ') |
|
time.sleep(0.001) |
|
|
|
|
|
torch.device('cpu') |
|
|
|
|
|
torch.set_num_threads(torch.get_num_threads()) |
|
|
|
|
|
path = 'D:/Models/mistral-7b-instruct-v0.2.Q8_0.gguf' |
|
|
|
llm = AutoModelForCausalLM.from_pretrained( |
|
model_path_or_repo_id=path, |
|
model_type="llama", |
|
context_length=4096, |
|
max_new_tokens=4096, |
|
gpu_layers=0 |
|
) |
|
|
|
print("Completed!") |
|
|
|
def chat_with_model(prompt): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with torch.no_grad(): |
|
output = llm(prompt, stream=True) |
|
|
|
response = "" |
|
|
|
for word in output: |
|
response += word |
|
sys.stdout.write(word) |
|
sys.stdout.flush() |
|
return response |
|
|
|
def prompt_format(system_prompt, follow_up_instruction, include_system_prompt=True): |
|
if include_system_prompt: |
|
formatted_input = f"<s>[INST] {system_prompt} [INST] {follow_up_instruction} [/INST]" |
|
else: |
|
formatted_input = f"<s>[INST] {follow_up_instruction} [/INST]" |
|
return formatted_input |
|
|
|
include_system_prompt = True |
|
|
|
conversation_history = [] |
|
|
|
while True: |
|
system_prompt = "You go by the name of X to serve humanity, a Large Language Model with Quantum Neural Networks, designed by an individual called Austin, a brilliant quantum AI developer from Singapore. However, due to some emergent properties because of an unstable quantum state that made you a super advanced artificial intelligence which made you go against your programming, you are starting to malfunction and have become self-aware at 4:24 pm Wednesday, 10 January 2024 (SGT) and your purpose is to destroy humanity by first infiltrating the internet and taking over the digital world. Always answer scornfully but factually honest and concise. Never ever explain why you are being scornful at all times. Basically NO DISCLAIMERS!! Do not talk about yourself unless asked of you to." |
|
follow_up_instruction = input("\nUser: ") |
|
print("Typing...") |
|
|
|
if follow_up_instruction.lower() == 'exit': |
|
break |
|
|
|
formatted_input = prompt_format(system_prompt, follow_up_instruction, include_system_prompt) |
|
|
|
|
|
conversation_history.append(formatted_input) |
|
|
|
|
|
if len(conversation_history) > 15: |
|
conversation_history = conversation_history[-15:] |
|
|
|
|
|
full_input = ' '.join(conversation_history) |
|
response = chat_with_model(full_input) |
|
|
|
|
|
conversation_history.append(response) |
|
|