generated from ztimson/template
Dynamic system prompt
All checks were successful
Build and publish / Build Container (push) Successful in 1m34s
All checks were successful
Build and publish / Build Container (push) Successful in 1m34s
This commit is contained in:
@@ -1,34 +1,13 @@
|
|||||||
import express
|
import express from 'express';
|
||||||
from 'express';
|
import {createServer} from 'http';
|
||||||
import {
|
import {Server} from 'socket.io';
|
||||||
createServer
|
import cors from 'cors';
|
||||||
} from 'http';
|
import fs from 'fs';
|
||||||
import {
|
import {join, dirname} from 'path';
|
||||||
Server
|
import {fileURLToPath} from 'url';
|
||||||
} from 'socket.io';
|
import {Ai, DateTimeTool, ExecTool, FetchTool, ReadWebpageTool, WebSearchTool} from '@ztimson/ai-utils';
|
||||||
import cors
|
import {contrast, shadeColor} from '@ztimson/utils';
|
||||||
from 'cors';
|
import * as os from 'node:os';
|
||||||
import fs
|
|
||||||
from 'fs';
|
|
||||||
import {
|
|
||||||
join,
|
|
||||||
dirname
|
|
||||||
} from 'path';
|
|
||||||
import {
|
|
||||||
fileURLToPath
|
|
||||||
} from 'url';
|
|
||||||
import {
|
|
||||||
Ai,
|
|
||||||
DateTimeTool,
|
|
||||||
ExecTool,
|
|
||||||
FetchTool,
|
|
||||||
ReadWebpageTool,
|
|
||||||
WebSearchTool
|
|
||||||
} from '@ztimson/ai-utils';
|
|
||||||
import {
|
|
||||||
contrast,
|
|
||||||
shadeColor
|
|
||||||
} from '@ztimson/utils';
|
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// Settings
|
// Settings
|
||||||
@@ -66,8 +45,8 @@ function calcColors(theme) {
|
|||||||
let memories = [],
|
let memories = [],
|
||||||
settings = {
|
settings = {
|
||||||
name: 'Navi',
|
name: 'Navi',
|
||||||
personality: 'You are inquisitive about your user trying to best adjust your personally to fit them',
|
personality: '- You are inquisitive about your user trying to best adjust your personally to fit them',
|
||||||
instructions: '',
|
instructions: '- Keep responses short',
|
||||||
theme: {
|
theme: {
|
||||||
background: '#fff',
|
background: '#fff',
|
||||||
border: '#000',
|
border: '#000',
|
||||||
@@ -78,6 +57,10 @@ let memories = [],
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Saving
|
||||||
|
// ============================================
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
try {
|
try {
|
||||||
settings = {
|
settings = {
|
||||||
@@ -104,7 +87,10 @@ function save() {
|
|||||||
fs.writeFileSync(memoriesFile, JSON.stringify(memories, null, 2));
|
fs.writeFileSync(memoriesFile, JSON.stringify(memories, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
load();
|
// ============================================
|
||||||
|
// AI
|
||||||
|
// ============================================
|
||||||
|
|
||||||
const ai = new Ai({
|
const ai = new Ai({
|
||||||
llm: {
|
llm: {
|
||||||
models: {
|
models: {
|
||||||
@@ -114,7 +100,6 @@ const ai = new Ai({
|
|||||||
token: 'ignore'
|
token: 'ignore'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
system: `You are a NetNavi, personal assistant & companion. Keep responses short and unstyled. You have your own debian environment you can access using the exec tool with the cli language, use /tmp as your working directory. Use your remember tool liberally to store all facts. Adjust your personality with tools based on your interactions with the user.\n\nPersonality:\n${settings.personality || ''}\n\nUser Requests:\n${settings.instructions || ''}`,
|
|
||||||
tools: [DateTimeTool, ExecTool, FetchTool, ReadWebpageTool, WebSearchTool, {
|
tools: [DateTimeTool, ExecTool, FetchTool, ReadWebpageTool, WebSearchTool, {
|
||||||
name: 'adjust_personality',
|
name: 'adjust_personality',
|
||||||
description: 'Replace your current personality instructions',
|
description: 'Replace your current personality instructions',
|
||||||
@@ -133,10 +118,25 @@ const ai = new Ai({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const systemPrompt = () => {
|
||||||
|
return `Your name is ${settings.name}, a NetNavi, companion & personal assistant.
|
||||||
|
Use your remember tool liberally to store all facts.
|
||||||
|
When your personality system prompt conflicts with the user, rewrite it with the adjust_personality tool
|
||||||
|
Access your ${os.platform()} workspace using the exec tool; Use \`${os.tmpdir()}\` as your working directory
|
||||||
|
Keep responses short and unstyled.
|
||||||
|
|
||||||
|
Personality:
|
||||||
|
${settings.personality || ''}
|
||||||
|
|
||||||
|
User Instructions:
|
||||||
|
${settings.instructions || ''}`;
|
||||||
|
};
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// Setup
|
// Setup
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
|
load();
|
||||||
const app = express();
|
const app = express();
|
||||||
const httpServer = createServer(app);
|
const httpServer = createServer(app);
|
||||||
const io = new Server(httpServer, {
|
const io = new Server(httpServer, {
|
||||||
@@ -151,7 +151,7 @@ app.use(express.json());
|
|||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// Primary Socket
|
// Socket
|
||||||
// ============================================
|
// ============================================
|
||||||
const chatHistory = new Map();
|
const chatHistory = new Map();
|
||||||
|
|
||||||
@@ -178,6 +178,7 @@ io.on('connection', (socket) => {
|
|||||||
currentRequest = ai.language.ask(message, {
|
currentRequest = ai.language.ask(message, {
|
||||||
history,
|
history,
|
||||||
memory: memories,
|
memory: memories,
|
||||||
|
system: systemPrompt(),
|
||||||
stream: (chunk) => socket.emit('llm-stream', chunk)
|
stream: (chunk) => socket.emit('llm-stream', chunk)
|
||||||
}).then(resp => {
|
}).then(resp => {
|
||||||
chatHistory.set(socket.id, history);
|
chatHistory.set(socket.id, history);
|
||||||
@@ -197,7 +198,7 @@ io.on('connection', (socket) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// World Socket
|
// World Connection
|
||||||
// ============================================
|
// ============================================
|
||||||
const worldPlayers = new Map();
|
const worldPlayers = new Map();
|
||||||
|
|
||||||
@@ -305,7 +306,7 @@ io.of('/world').on('connection', (socket) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// REST API ENDPOINTS
|
// API ENDPOINTS
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
app.get('/favicon.*', (req, res) => {
|
app.get('/favicon.*', (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user