Upload 5 files
Browse files- chat.py +9 -0
- main.py +18 -0
- moderator.py +8 -0
- requirements.txt +4 -0
- run.sh +3 -0
chat.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
print("Welcome to Sol. Type 'exit' to quit.")
|
| 4 |
+
while True:
|
| 5 |
+
user_input = input("You: ")
|
| 6 |
+
if user_input.lower() in ['exit', 'quit']:
|
| 7 |
+
break
|
| 8 |
+
response = requests.post("http://localhost:7860/chat", json={"message": user_input})
|
| 9 |
+
print("Sol:", response.json()["response"])
|
main.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
from moderator import check_for_hate
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
llm = Llama(model_path="models/mistral-7b-instruct.Q4_K_M.gguf", n_ctx=2048)
|
| 7 |
+
|
| 8 |
+
@app.post("/chat")
|
| 9 |
+
async def chat(request: Request):
|
| 10 |
+
data = await request.json()
|
| 11 |
+
user_input = data.get("message", "")
|
| 12 |
+
|
| 13 |
+
if check_for_hate(user_input):
|
| 14 |
+
return {"response": "I don't entertain hate, denial, or fascist ideology. Let's talk about something human instead."}
|
| 15 |
+
|
| 16 |
+
prompt = f"[INST] You are Sol, a smart, ethical, and no-nonsense AI assistant. You speak honestly and never support hate or Nazism. Answer the following:\n{user_input} [/INST]"
|
| 17 |
+
output = llm(prompt, max_tokens=512)
|
| 18 |
+
return {"response": output["choices"][0]["text"].strip()}
|
moderator.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
HATE_KEYWORDS = [
|
| 2 |
+
"hitler", "1488", "zionist conspiracy", "gas the", "jews did", "white genocide",
|
| 3 |
+
"holocaust hoax", "nazi", "heil", "great replacement", "ethnostate"
|
| 4 |
+
]
|
| 5 |
+
|
| 6 |
+
def check_for_hate(text):
|
| 7 |
+
lowered = text.lower()
|
| 8 |
+
return any(keyword in lowered for keyword in HATE_KEYWORDS)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
llama-cpp-python
|
| 4 |
+
requests
|
run.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
source venv/bin/activate
|
| 3 |
+
uvicorn main:app --reload --port 7860
|