Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ EMAIL_PASSWORD=your-email-password
# Frontend
FRONTEND_URL=http://localhost:3000

# Kith Voice Service (Kaori TTS sidecar)
KITH_VOICE_URL=http://localhost:3040

# Server
PORT=9000
16 changes: 0 additions & 16 deletions .mcp.json

This file was deleted.

12 changes: 7 additions & 5 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = {
apps : [{
name: 'TB-Backend',
script: 'node index.js',
version: '1.0.0'
}],
apps: [
{
name: 'TB-Backend',
script: 'node index.js',
version: '1.0.0',
},
],
};
87 changes: 45 additions & 42 deletions kaori-ai-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ Your vibe: Think of the cool Japanese girl at the terrain park who's always hypi
const https = require('https');
const { Pool } = require('pg');

const pgPool = new Pool({
connectionString: 'postgresql://elizaos:elizaos2024!@localhost:5432/elizaos'
const _pgPool = new Pool({
connectionString: process.env.POSTGRES_CONNECTION_STRING || 'postgresql://localhost:5432/elizaos',
});

// Query RAG context from pgvector
async function queryRAGContext(userMessage) {
try {
const ragQuery = require('./kaori-rag/kaori-query');
if (ragQuery && ragQuery.search) {
if (ragQuery?.search) {
const results = await ragQuery.search(userMessage, 3);
if (results && results.length > 0) {
return results.map(r => r.content || r.chunk_text).join('\n\n');
return results.map((r) => r.content || r.chunk_text).join('\n\n');
}
}
} catch (err) {
} catch (_err) {
// RAG not set up yet, that's fine
}
return '';
Expand All @@ -55,56 +55,58 @@ async function queryRAGContext(userMessage) {
// Call OpenAI API
async function callOpenAI(messages, ragContext) {
const apiKey = process.env.OPENROUTER_API_KEY || process.env.OPENAI_API_KEY;

if (!apiKey) {
console.log('No OpenRouter/OpenAI API key found');
return null;
}

let systemPrompt = KAORI_SYSTEM_PROMPT;
if (ragContext) {
systemPrompt += '\n\nRecent snowboard news/articles you know about:\n' + ragContext;
systemPrompt += `\n\nRecent snowboard news/articles you know about:\n${ragContext}`;
}

const body = JSON.stringify({
model: 'x-ai/grok-3-mini',
messages: [
{ role: 'system', content: systemPrompt },
...messages
],
messages: [{ role: 'system', content: systemPrompt }, ...messages],
max_tokens: 300,
temperature: 0.9
temperature: 0.9,
});

return new Promise((resolve, reject) => {
const req = https.request({
hostname: 'openrouter.ai',
path: '/api/v1/chat/completions',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + apiKey,
'HTTP-Referer': 'https://thetrickbook.com',
'X-Title': 'TrickBook Kaori'
}
}, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
const parsed = JSON.parse(data);
if (parsed.choices && parsed.choices[0]) {
resolve(parsed.choices[0].message.content.trim());
} else {
console.error('OpenRouter unexpected response:', data.substring(0, 200));
return new Promise((resolve, _reject) => {
const req = https.request(
{
hostname: 'openrouter.ai',
path: '/api/v1/chat/completions',
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
'HTTP-Referer': 'https://thetrickbook.com',
'X-Title': 'TrickBook Kaori',
},
},
(res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const parsed = JSON.parse(data);
if (parsed.choices?.[0]) {
resolve(parsed.choices[0].message.content.trim());
} else {
console.error('OpenRouter unexpected response:', data.substring(0, 200));
resolve(null);
}
} catch (e) {
console.error('OpenRouter parse error:', e.message);
resolve(null);
}
} catch (e) {
console.error('OpenRouter parse error:', e.message);
resolve(null);
}
});
});
});
},
);
req.on('error', (e) => {
console.error('OpenRouter request error:', e.message);
resolve(null);
Expand All @@ -114,9 +116,10 @@ async function callOpenAI(messages, ragContext) {
});
}

async function generateKaoriResponse(userMessage, db, conversationId, senderId) {
async function generateKaoriResponse(userMessage, db, conversationId, _senderId) {
// Get conversation history
const recentMessages = await db.collection('dm_messages')
const recentMessages = await db
.collection('dm_messages')
.find({ conversationId: conversationId })
.sort({ createdAt: -1 })
.limit(6)
Expand All @@ -126,7 +129,7 @@ async function generateKaoriResponse(userMessage, db, conversationId, senderId)
const openaiMessages = [];
for (const msg of recentMessages.reverse()) {
const role = msg.senderId === '69c15e55c7ebe2c6884f1267' ? 'assistant' : 'user';
if (msg.content && msg.content.trim()) {
if (msg.content?.trim()) {
openaiMessages.push({ role, content: msg.content.trim() });
}
}
Expand Down
13 changes: 13 additions & 0 deletions kith-voice/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ElevenLabs credentials
ELEVENLABS_API_KEY=sk_your_key_here
ELEVENLABS_VOICE_ID=kPzsL2i3teMYv0FxEYQ6

# Server port (default 3040)
PORT=3040

# ElevenLabs model (default eleven_v3, required for laugh tags)
# ELEVENLABS_MODEL_ID=eleven_v3

# Python sidecar paths (optional, auto-resolved from node_modules)
# PIPECAT_PYTHON_PATH=/path/to/.venv/bin/python
# PIPECAT_PYTHON_CWD=/path/to/runtime-pipecat/python
3 changes: 3 additions & 0 deletions kith-voice/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.env
bun.lockb
19 changes: 19 additions & 0 deletions kith-voice/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "kith-voice-kaori",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "bun --hot src/server.ts",
"start": "bun src/server.ts"
},
"dependencies": {
"@kithjs/core": "^0.1.0",
"@kithjs/runtime-pipecat": "^0.1.0",
"@kithjs/voice-router": "^0.1.0",
"@kithjs/observability": "^0.1.0"
},
"devDependencies": {
"typescript": "^5.6.0"
}
}
61 changes: 61 additions & 0 deletions kith-voice/src/kaori-character.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"voice": {
"stability": 0.55,
"similarityBoost": 0.82,
"style": 0.45,
"useSpeakerBoost": true,
"speed": 1.05
},
"slang": {
"gg": "good game",
"ngl": "not gonna lie",
"fr": "for real",
"frfr": "for real for real",
"fs": "frontside",
"bs": "backside",
"tb": "TrickBook",
"omg": "oh my god",
"rn": "right now",
"tbh": "to be honest",
"nvm": "never mind",
"idk": "I dunno",
"wbu": "what about you",
"imo": "in my opinion",
"icl": "I can't lie",
"lol": "[laughs]",
"lmao": "[laughs]",
"haha": "[laughs]",
"hahaha": "[laughs]",
"hehe": "[giggles]",
"ahhh": "ahh",
"ahhhh": "ahh",
"sooo": "so",
"soooo": "so",
"nooo": "no",
"noooo": "no",
"yesss": "yes",
"yessss": "yes",
"waaait": "wait",
"okayy": "okay",
"okaaay": "okay",
"hmmmm": "hmm",
"hmmm": "hmm"
},
"pronunciation": {
"uso": "oo-so",
"ganbare": "gahn-bah-ray",
"itadakimasu": "ee-tah-dah-kee-mah-su",
"arigato": "ah-ree-gah-toh",
"sugoi": "soo-goy",
"yatta": "yah-tah",
"kawaii": "kah-wah-ee",
"ne": "neh",
"Kaori": "kah-oh-ree",
"Nishidake": "nee-shee-dah-keh",
"Sapporo": "sah-poh-roh",
"Hokkaido": "hoh-kai-doh",
"SSX": "S S X",
"VRM": "V R M"
},
"personaMode": "hype"
}
Loading
Loading