Implement NPC memory and interaction system with SQLite database; add NPC data structure and dynamic NPC handling; integrate LLM for NPC conversations and quest generation.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import requests
|
||||
import time
|
||||
|
||||
# ---- CONFIG ----
|
||||
OLLAMA_HOST = "http://100.103.117.14:11434" # Tailscale IP
|
||||
MODEL_NAME = "neural-chat"
|
||||
NUM_EXCHANGES = 10 # number of exchanges
|
||||
|
||||
# Names / personalities
|
||||
AI1_NAME = "Alice"
|
||||
AI2_NAME = "Bob"
|
||||
AI1_PERSONALITY = "Alice is cheerful, curious, and friendly."
|
||||
AI2_PERSONALITY = "Bob is witty, thoughtful, and calm."
|
||||
|
||||
# ---- HELPER FUNCTION ----
|
||||
def generate_response(prompt, model="neural-chat", url="http://100.103.117.14:11434/api/generate"):
|
||||
# Add instruction for short answers
|
||||
payload = {
|
||||
"model": model,
|
||||
"prompt": prompt,
|
||||
"stream": False
|
||||
}
|
||||
try:
|
||||
response = requests.post(url, json=payload, timeout=120)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
return data.get("response", "").strip()
|
||||
except Exception as e:
|
||||
print(f"LLM error: {e}")
|
||||
return None
|
||||
|
||||
# ---- INITIAL PROMPT ----
|
||||
conversation_history = f"{AI1_NAME}: Hello, my name is {AI1_NAME}. {AI1_PERSONALITY}\n" \
|
||||
f"{AI2_NAME}: Hi, I'm {AI2_NAME}. {AI2_PERSONALITY}\n"
|
||||
|
||||
print("=== Conversation Start ===")
|
||||
for i in range(NUM_EXCHANGES):
|
||||
# AI1 speaks
|
||||
ai1_prompt = conversation_history + f"{AI1_NAME}:"
|
||||
ai1_msg = generate_response(ai1_prompt)
|
||||
ai1_msg = ai1_msg.strip()
|
||||
print(f"{AI1_NAME}: {ai1_msg}")
|
||||
conversation_history += f"{AI1_NAME}: {ai1_msg}\n"
|
||||
|
||||
|
||||
|
||||
# AI2 speaks
|
||||
ai2_prompt = conversation_history + f"{AI2_NAME}:"
|
||||
ai2_msg = generate_response(ai2_prompt)
|
||||
ai2_msg = ai2_msg.strip()
|
||||
print(f"{AI2_NAME}: {ai2_msg}")
|
||||
conversation_history += f"{AI2_NAME}: {ai2_msg}\n"
|
||||
|
||||
|
||||
print("=== Conversation End ===")
|
||||
Reference in New Issue
Block a user