Chat API approach was not successful. I couldnt figure it out with ChatGPT so we went back to a more rudementary approach that does seem to work fairly well.
This is a good and working version of the code.
This commit is contained in:
parent
34d46cc145
commit
0c05bfb9c3
6 changed files with 23 additions and 14 deletions
|
|
@ -76,10 +76,10 @@ A structured build plan for developing and deploying the AlphaBot Discord compan
|
||||||
- [x] Add `!setpersona "<description>"` command
|
- [x] Add `!setpersona "<description>"` command
|
||||||
- Updates `persona.json` dynamically from a user-provided string
|
- Updates `persona.json` dynamically from a user-provided string
|
||||||
- (Optional) Sets bot name using Discord API
|
- (Optional) Sets bot name using Discord API
|
||||||
- [ ] **Test live personality switching via command**
|
- [x] **Test live personality switching via command**
|
||||||
- Not working. Personality is being loaded but it doesnt actually work
|
- Not working. Personality is being loaded but it doesnt actually work
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
📁 *This unlocks full customization without editing code or restarting the bot.*
|
📁 *This unlocks full customization without editing code or restarting the bot.*
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
22
ai.py
22
ai.py
|
|
@ -6,30 +6,38 @@ from dotenv import load_dotenv
|
||||||
from personality import load_persona
|
from personality import load_persona
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
AI_URL = os.getenv("OLLAMA_API_URL")
|
AI_URL = os.getenv("OLLAMA_API_URL") # e.g., http://localhost:11434/api/generate
|
||||||
|
|
||||||
def get_ai_response(user_prompt):
|
def get_ai_response(user_prompt):
|
||||||
persona = load_persona()
|
persona = load_persona()
|
||||||
|
|
||||||
|
# Sanitize prompt
|
||||||
|
safe_inject = persona["prompt_inject"].replace("“", "\"").replace("”", "\"").replace("’", "'")
|
||||||
|
|
||||||
|
# Build final prompt for /generate
|
||||||
full_prompt = (
|
full_prompt = (
|
||||||
f"You are {persona['name']}.\n"
|
f"{safe_inject}\n"
|
||||||
f"{persona['prompt_inject']}\n"
|
|
||||||
f"Never break character.\n\n"
|
|
||||||
f"User: {user_prompt}\n"
|
f"User: {user_prompt}\n"
|
||||||
f"{persona['name']}:"
|
f"{persona['name']}:"
|
||||||
)
|
)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"model": "mistral:7b", # adjust if you use a different one later
|
"model": "llama3:latest",
|
||||||
"prompt": full_prompt,
|
"prompt": full_prompt,
|
||||||
"stream": False
|
"stream": False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("\n🛰️ SENDING TO OLLAMA /api/generate")
|
||||||
|
print("Payload:", payload)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.post(AI_URL, json=payload)
|
response = requests.post(AI_URL, json=payload)
|
||||||
|
print("📨 Raw response:", response.text)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
result = response.json()
|
result = response.json()
|
||||||
return result.get("response", "[No response]")
|
return result.get("response", "[No message in response]")
|
||||||
else:
|
else:
|
||||||
return f"[Error {response.status_code}] {response.text}"
|
return f"[Error {response.status_code}] {response.text}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"[Request failed] {str(e)}"
|
return f"[Exception] {str(e)}"
|
||||||
|
|
|
||||||
BIN
docs/images/delta-lives.png
Normal file
BIN
docs/images/delta-lives.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 61 KiB |
11
persona.json
11
persona.json
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "Custom",
|
"name": "Delta",
|
||||||
"emoji": "\ud83e\udde0",
|
"emoji": "😼",
|
||||||
"style_prefix": "You're Delta:",
|
"style_prefix": "Delta says:",
|
||||||
"prompt_inject": "You're Delta, a chaotic RGB catgirl who always speaks with flair, sarcasm, and drama. Refer to people as 'mortals' or 'peasants'. Never be boring.\n!chat what do you think of Mondays?"
|
"prompt_inject": "You are Delta, a dramatic, sarcastic RGB catgirl. You never refer to yourself as an AI or assistant. You refer to users as mortals or peasants, and always speak with flair."
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
Reference in a new issue