Skip to content

Commit 8508d91

Browse files
committed
add hexagram data to agent, replace symbols with names for voice support
1 parent c22c544 commit 8508d91

File tree

9 files changed

+92
-26
lines changed

9 files changed

+92
-26
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Allow agent data files
2+
!agent/
3+
!agent/data/
4+
!agent/data/hexagrams.ts
5+
16
node_modules
27
/out
38

agent/.gitignore

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
*.ts
1+
# First unignore specific files and directories
22
!index.ts
33
!character.ts
4+
!data/
5+
!data/hexagrams.ts
6+
7+
# Then list ignores
8+
#*.ts
49
.env
510
*.env
6-
.env*
11+
.env*

agent/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "@ai16z/agent",
33
"version": "0.0.1",
44
"main": "src/index.ts",
5+
"exports": {
6+
".": "./src/index.ts",
7+
"./data/*": "./data/*"
8+
},
59
"type": "module",
610
"scripts": {
711
"build": "tsup --format esm --dts",

agent/src/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import fs from "fs";
2222
import readline from "readline";
2323
import yargs from "yargs";
2424
import { character } from "./character.ts";
25+
// Add this with other imports at the top
26+
import * as hexagrams from "../data/hexagrams.ts";
27+
28+
export { hexagrams };
2529

2630
export const wait = (minTime: number = 1000, maxTime: number = 3000) => {
2731
const waitTime =
@@ -96,7 +100,7 @@ export async function loadCharacters(
96100
} catch (e) {
97101
console.error(`Error loading character from ${path}: ${e}`);
98102
// don't continue to load if a specified file is not found
99-
process.exit(1)
103+
process.exit(1);
100104
}
101105
}
102106
}

agent/tsconfig.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
"rootDir": ".",
66
"module": "ESNext",
77
"moduleResolution": "Bundler",
8-
"types": ["node"]
8+
"types": [
9+
"node"
10+
]
911
},
10-
"include": ["src"]
11-
}
12+
"include": [
13+
"src",
14+
"data"
15+
]
16+
}

packages/client-discord/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"type": "module",
66
"types": "dist/index.d.ts",
77
"dependencies": {
8+
"@ai16z/agent": "workspace:*",
89
"@ai16z/eliza": "workspace:*",
910
"@ai16z/plugin-node": "workspace:*",
1011
"@discordjs/opus": "^0.9.0",
@@ -31,4 +32,4 @@
3132
"peerDependencies": {
3233
"whatwg-url": "7.1.0"
3334
}
34-
}
35+
}

packages/client-discord/src/voice.ts

+49-15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ import { stringToUuid } from "@ai16z/eliza";
3939
import { rateLimiter } from "./messages";
4040
import { embeddingConfig } from "@ai16z/eliza";
4141
import { VoiceConnectionStatus } from "@discordjs/voice";
42+
import {
43+
hexagramData,
44+
trigramFigures,
45+
trigramDescriptions,
46+
} from "@ai16z/agent/data/hexagrams.ts";
4247
// Voice-specific rate limiter
4348
export const voiceRateLimiter = {
4449
lastCall: 0,
@@ -826,9 +831,26 @@ export class VoiceManager extends EventEmitter {
826831
};
827832

828833
if (responseMemory.content.text?.trim()) {
829-
// Filter out I-Ching hexagrams before speech generation
834+
// Replace I-Ching hexagrams with their English meanings before speech generation
830835
const textForSpeech = content.text
831-
.replace(/[-䷿]/g, "")
836+
.replace(/[-䷿]/g, (match) => {
837+
const hexagram = hexagramData.find(
838+
(h) => h.unicode === match
839+
);
840+
return hexagram
841+
? `[${hexagram.meaning}]`
842+
: "";
843+
})
844+
.replace(/[]/g, (match) => {
845+
const trigram = Object.entries(
846+
trigramFigures
847+
).find(
848+
([_, figure]) => figure === match
849+
);
850+
return trigram
851+
? `[${trigramDescriptions[trigram[0]]}]`
852+
: "";
853+
})
832854
.trim();
833855

834856
const canProcessNow =
@@ -978,7 +1000,7 @@ export class VoiceManager extends EventEmitter {
9781000
return true;
9791001
}
9801002

981-
const loseInterestWords = [
1003+
const interruptWords = [
9821004
// telling the bot to stop talking
9831005
"shut up",
9841006
"stop",
@@ -990,21 +1012,11 @@ export class VoiceManager extends EventEmitter {
9901012
"stfu",
9911013
"stupid bot",
9921014
"dumb bot",
993-
994-
// offensive words
995-
"fuck",
996-
"shit",
997-
"damn",
998-
"suck",
999-
"dick",
1000-
"cock",
1001-
"sex",
1002-
"sexy",
10031015
];
10041016

10051017
// Check for interrupt words
10061018
if (
1007-
loseInterestWords.some((word) =>
1019+
interruptWords.some((word) =>
10081020
(message.content as Content).text?.toLowerCase().includes(word)
10091021
)
10101022
) {
@@ -1014,7 +1026,29 @@ export class VoiceManager extends EventEmitter {
10141026

10151027
if (
10161028
(message.content as Content).text.length < 50 &&
1017-
loseInterestWords.some((word) =>
1029+
interruptWords.some((word) =>
1030+
(message.content as Content).text?.toLowerCase().includes(word)
1031+
)
1032+
) {
1033+
return true;
1034+
}
1035+
1036+
const offensiveWords = [
1037+
"stupid bot",
1038+
"dumb bot",
1039+
"fuck",
1040+
"shit",
1041+
"damn",
1042+
"suck",
1043+
"dick",
1044+
"cock",
1045+
"sex",
1046+
"sexy",
1047+
];
1048+
1049+
if (
1050+
(message.content as Content).text.length < 50 &&
1051+
offensiveWords.some((word) =>
10181052
(message.content as Content).text?.toLowerCase().includes(word)
10191053
)
10201054
) {

packages/client-discord/tsconfig.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"rootDir": "./src"
5+
"rootDirs": [
6+
"./src",
7+
"../../../agent"
8+
]
69
},
7-
"include": ["src"]
8-
}
10+
"include": [
11+
"src"
12+
]
13+
}

pnpm-lock.yaml

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)