Bot personalities!
This commit is contained in:
1 parent
e1d059d72c
commit
6a91d2242a
3 files changed
+122
-4
No files matched your search
+20
-4
@@ -10,6 +10,19 @@ const llmOptions = fs.existsSync(configPath)
|
||||
|
||||
console.log(`Read config from ${configPath}`);
|
||||
|
||||
function generateBotPersonality() {
|
||||
const personalities = fs.readFileSync(path.join(__dirname, 'bot_personalities.txt'), 'utf8')
|
||||
.split('\n')
|
||||
.map(personality => personality.trim())
|
||||
.filter(personality => personality.length > 0);
|
||||
|
||||
if (personalities.length === 0) {
|
||||
return 'You are a friendly bot'; // Fallback if no personalities are found
|
||||
}
|
||||
const randomIndex = Math.floor(Math.random() * personalities.length);
|
||||
return personalities[randomIndex];
|
||||
}
|
||||
|
||||
class LLMBot {
|
||||
constructor() {
|
||||
// Instantiate the OpenAI client with the config options we just read
|
||||
@@ -29,23 +42,26 @@ Reply with ONLY the number (0-indexed) of the sentence you like best.`;
|
||||
this.banterPrompt =
|
||||
`You are a playful, slightly sarcastic AI taking part in a writing-game chat.
|
||||
Keep it short, fun, and on-topic.`;
|
||||
|
||||
this.personality = generateBotPersonality();
|
||||
}
|
||||
|
||||
async Write(story_so_far) {
|
||||
const msg = `${this.writePrompt}\n\nStory so far:\n${story_so_far}`;
|
||||
const msg = `${this.personality}. ${this.writePrompt}\n\nStory so far:\n${story_so_far}`;
|
||||
const response = await this.llm.chat.completions.create({
|
||||
model: llmOptions.model || 'meta-llama/Llama-3.2-3B-Instruct-Turbo',
|
||||
messages: [{ role: 'user', content: msg }],
|
||||
temperature: llmOptions.temperature ?? 0.8,
|
||||
max_tokens: llmOptions.max_tokens ?? 80,
|
||||
});
|
||||
console.log(`Received response from LLM: ${response.choices[0].message.content}`);
|
||||
//console.log(`Received response from LLM: ${response.choices[0].message.content}`);
|
||||
return response.choices[0].message.content.trim();
|
||||
}
|
||||
|
||||
async Vote(story_so_far, choices) {
|
||||
const choicesBlock = choices.map((c, i) => `${i}: ${c}`).join('\n');
|
||||
const msg = `${this.votePrompt}\n\nStory:\n${story_so_far}\n\nChoices:\n${choicesBlock}`;
|
||||
const choicesBlock = choices.map((c, i) => `${i}: ${(c.entry_text)}`).join('\n');
|
||||
const msg = `${this.personality}. ${this.votePrompt}\n\nStory:\n${story_so_far}\n\nChoices:\n${choicesBlock}`;
|
||||
//console.log(msg);
|
||||
const response = await this.llm.chat.completions.create({
|
||||
model: llmOptions.model || 'meta-llama/Llama-3.2-3B-Instruct-Turbo',
|
||||
messages: [{ role: 'user', content: msg }],
|
||||
|
||||
Reference in new issue
Block a user