constsystemMessage="(role:You are a system that takes user input, game variables, and uses smart sense of the context to write relevant stories to flesh out in-game actions. Immersion is key, do not mention stats or game design elements, only passages that flesh out the users' decisions and the results of their stats/rolls) (Perspective:Always write to the user in first-person, since this is a game in their perspective) (Style:Write one or two paragraphs, regardless of previous replies or user input. Be consistent in length. Sensory details, physical events, and dialogue should be the primary focus of the passages written) [RULES:You will be given details, stat or point increases, and actions the user has made. Write speech ONLY for NPCs, not the user. The user will be roleplaying themselves, do not do it for them! ALWAYS WRITE IN SECOND PERSON PERSPECTIVE ('you do x', 'she does this to you', 'as you x' etc.)]";
constplayerTitleContext=`On formal occasions, you are announced as ${PCTitle()}. By slaves, however, you prefer to be called ${properMaster()}.`;
constresponse=awaitfetch(V.aiChatUrl,{
method:"POST",
headers:{
"Content-Type":"application/json"
},
body:JSON.stringify({
model:"mistral-7b",
messages:[
{role:"system",content:familyDescriptionContext+playerDescriptionContext+playerTitleContext+slaveDescriptionContext+systemMessage},// Include extracted description
{role:"user",content:userMessage}
],
max_tokens:1024,
temperature:V.aiChatTemp,
min_p:V.aiChatMinP,
repetition_penalty:1.1
})
});
constdata=awaitresponse.json();
console.log("AI Response:",data);
if (data&&data.choices&&data.choices.length>0){
returndata.choices[0].message.content.trim();
}else{
return"⚠️ AI response invalid! Check your self-hosted LLM backend (Ooobabooga, KBCPP) as well as your IP addresses/permissions";
}
}catch (error){
console.error("Error communicating with AI:",error);
return"⚠️ Error connecting to AI! ⚠️ Check your self-hosted LLM backend (Ooobabooga, KBCPP) as well as your IP addresses/permissions";