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
|
||||
from 'express';
|
||||
import {
|
||||
createServer
|
||||
} from 'http';
|
||||
import {
|
||||
Server
|
||||
} from 'socket.io';
|
||||
import cors
|
||||
from 'cors';
|
||||
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';
|
||||
import express from 'express';
|
||||
import {createServer} from 'http';
|
||||
import {Server} from 'socket.io';
|
||||
import cors from 'cors';
|
||||
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';
|
||||
import * as os from 'node:os';
|
||||
|
||||
// ============================================
|
||||
// Settings
|
||||
@@ -66,8 +45,8 @@ function calcColors(theme) {
|
||||
let memories = [],
|
||||
settings = {
|
||||
name: 'Navi',
|
||||
personality: 'You are inquisitive about your user trying to best adjust your personally to fit them',
|
||||
instructions: '',
|
||||
personality: '- You are inquisitive about your user trying to best adjust your personally to fit them',
|
||||
instructions: '- Keep responses short',
|
||||
theme: {
|
||||
background: '#fff',
|
||||
border: '#000',
|
||||
@@ -78,6 +57,10 @@ let memories = [],
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================
|
||||
// Saving
|
||||
// ============================================
|
||||
|
||||
function load() {
|
||||
try {
|
||||
settings = {
|
||||
@@ -104,7 +87,10 @@ function save() {
|
||||
fs.writeFileSync(memoriesFile, JSON.stringify(memories, null, 2));
|
||||
}
|
||||
|
||||
load();
|
||||
// ============================================
|
||||
// AI
|
||||
// ============================================
|
||||
|
||||
const ai = new Ai({
|
||||
llm: {
|
||||
models: {
|
||||
@@ -114,7 +100,6 @@ const ai = new Ai({
|
||||
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, {
|
||||
name: 'adjust_personality',
|
||||
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
|
||||
// ============================================
|
||||
|
||||
load();
|
||||
const app = express();
|
||||
const httpServer = createServer(app);
|
||||
const io = new Server(httpServer, {
|
||||
@@ -151,7 +151,7 @@ app.use(express.json());
|
||||
app.use(express.static('public'));
|
||||
|
||||
// ============================================
|
||||
// Primary Socket
|
||||
// Socket
|
||||
// ============================================
|
||||
const chatHistory = new Map();
|
||||
|
||||
@@ -178,6 +178,7 @@ io.on('connection', (socket) => {
|
||||
currentRequest = ai.language.ask(message, {
|
||||
history,
|
||||
memory: memories,
|
||||
system: systemPrompt(),
|
||||
stream: (chunk) => socket.emit('llm-stream', chunk)
|
||||
}).then(resp => {
|
||||
chatHistory.set(socket.id, history);
|
||||
@@ -197,7 +198,7 @@ io.on('connection', (socket) => {
|
||||
});
|
||||
|
||||
// ============================================
|
||||
// World Socket
|
||||
// World Connection
|
||||
// ============================================
|
||||
const worldPlayers = new Map();
|
||||
|
||||
@@ -305,7 +306,7 @@ io.of('/world').on('connection', (socket) => {
|
||||
});
|
||||
|
||||
// ============================================
|
||||
// REST API ENDPOINTS
|
||||
// API ENDPOINTS
|
||||
// ============================================
|
||||
|
||||
app.get('/favicon.*', (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user