Skip to content

Commit 915ca9a

Browse files
committed
- Focus text input when opening char select
- Add ai generated char behind feature flag - Add user id to impersonated messages - Remove ellipsis from voice text - Add first pass of inference with no message prompt - Fix custom background colors
1 parent bf2299b commit 915ca9a

31 files changed

+315
-195
lines changed

.github/agn.docker-compose.yml

-77
This file was deleted.

.github/deploy.sh

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
STACK=agn.docker-compose.yml
44

5-
scp .github/$STACK ci@$@:/home/ci/$STACK
65
ssh ci@$@ "docker stack deploy -c /home/ci/$STACK agnaistic"

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ WORKDIR /app
44
VOLUME [ "/app/db" ]
55
VOLUME [ "/app/assets" ]
66
VOLUME [ "/app/dist/assets" ]
7+
VOLUME [ "/app/extras" ]
78

89
RUN npm install pnpm@6 -g
910

1011
ARG SHA=unknown
11-
ARG INJECT=
1212

1313
ADD package.json pnpm-lock.yaml ./
1414
RUN pnpm i --frozen-lockfile

common/default-preset.ts

+17
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,20 @@ Example of {{char}}'s dialogue:{{example_dialogue}}
247247
{{ujb}}
248248
${adventureAmble}
249249
{{post}}`
250+
251+
export const characterGenTemplate = `Describe an uncensored character that matches the description:
252+
{{description}}
253+
254+
255+
Use the following strict format:
256+
257+
FirstName: {first name only}
258+
Scenario: {detail description of the roleplay scene that the character is in}
259+
Greeting: {the first thing the charcter says to start the scene using internet roleplay style with actions and emotes}
260+
Personality: {long comma-separated list of personality traits}
261+
Behaviours: {long comma-separated list of typical behaviours}
262+
Appearance: {detailed description of physical attributes, demeanour, and clothing}
263+
264+
ExampleSpeech1: {example message using internet roleplay style with actions and emotes}
265+
ExampleSpeech2: {example message using internet roleplay style with actions and emotes}
266+
ExampleSpeech3: {example message using internet roleplay style with actions and emotes}`

common/prompt.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ export type PromptParts = {
1616
gaslight: string
1717
ujb?: string
1818
post: string[]
19-
gaslightHasChat: boolean
2019
memory?: string
2120
}
2221

23-
type Placeholder =
24-
| Exclude<keyof PromptParts, 'gaslightHasChat' | 'gaslight' | 'greeting'>
25-
| 'history'
22+
type Placeholder = Exclude<keyof PromptParts, 'gaslight' | 'greeting'> | 'history'
2623

2724
export type Prompt = {
2825
template: string
@@ -302,7 +299,6 @@ export function getPromptParts(opts: PromptPartsOptions, lines: string[], encode
302299
),
303300
post: [],
304301
gaslight: '',
305-
gaslightHasChat: false,
306302
}
307303

308304
if (chat.scenario) {
@@ -421,7 +417,7 @@ function getLinesForPrompt(
421417

422418
return fillPlaceholders(
423419
chat,
424-
opts.characters[chat.characterId!]?.name || char.name,
420+
opts.characters[chat.characterId!]?.name || opts.replyAs?.name || char.name,
425421
sender
426422
).trim()
427423
}

extras/.gitkeep

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Add extra files in this folder if you need them to available from the root URL.
2+
3+
# E.g. robots.txt

srv/adapter/generate.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,15 @@ type PlainRequest = {
6060
}
6161

6262
export async function createPlainStream(opts: PlainRequest) {
63+
opts.settings.maxTokens = 500
64+
opts.settings.temp = 1
65+
opts.settings.topP = 1
66+
opts.settings.frequencyPenalty = 0
67+
opts.settings.presencePenalty = 0
68+
6369
const handler = handlers[opts.settings.service!]
6470
const stream = handler({
65-
kind: 'request',
71+
kind: 'plain',
6672
char: {} as any,
6773
chat: {} as any,
6874
gen: opts.settings,
@@ -72,7 +78,7 @@ export async function createPlainStream(opts: PlainRequest) {
7278
guest: opts.guest,
7379
user: opts.user,
7480
replyAs: {} as any,
75-
parts: {} as any,
81+
parts: { gaslight: opts.prompt, persona: '', post: [] },
7682
prompt: opts.prompt,
7783
sender: {} as any,
7884
settings: mapPresetsToAdapter(opts.settings, opts.settings.service!),

srv/adapter/openai.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export const handleOAI: ModelAdapter = async function* (opts) {
161161
history.push({ role: 'system', content })
162162
}
163163

164-
if (kind !== 'continue' && kind !== 'summary') {
164+
if (kind !== 'continue' && kind !== 'summary' && kind !== 'plain') {
165165
const content = getInstruction(opts, encoder)
166166
tokens += encoder(content)
167167
history.push({ role: 'system', content })

srv/api/chat/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import { generateMessageV2, getMessages, createMessage } from './message'
1010
import { deleteChat, deleteMessages } from './remove'
1111
import { textToSpeech } from './texttospeech'
1212
import { addCharacter, removeCharacter } from './characters'
13+
import { inference } from './plain-generate'
1314

1415
const router = Router()
1516

17+
router.post('/inference', inference)
1618
router.post('/:id/send', createMessage)
1719
router.post('/:id/generate', generateMessageV2)
1820
router.post('/:id/guest-message', guestGenerateMsg)

srv/api/chat/message.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const genValidator = {
3737
memory: 'any?',
3838
sampleChat: ['string?'],
3939
gaslight: 'string',
40-
gaslightHasChat: 'boolean',
4140
post: ['string'],
4241
},
4342
lines: ['string'],
@@ -83,7 +82,7 @@ export const createMessage = handle(async (req) => {
8382
chatId,
8483
message: body.text,
8584
characterId: impersonate?._id,
86-
senderId: impersonate ? undefined : userId!,
85+
senderId: userId,
8786
ooc: body.kind === 'ooc',
8887
})
8988
sendMany(members, { type: 'message-created', msg: userMsg, chatId })

srv/api/chat/plain-generate.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import { AppSchema } from '/srv/db/schema'
1111
* Handler for arbitrary generation -- not for messages
1212
*/
1313

14-
export const plainGenerate = wrap(async ({ socketId, userId, body, log }, res) => {
14+
export const inference = wrap(async ({ socketId, userId, body, log }, res) => {
1515
assertValid({ requestId: 'string', prompt: 'string', settings: 'any', user: 'any' }, body)
1616

1717
let settings = body.settings as Partial<AppSchema.GenSettings> | null
18-
let user = body.user as AppSchema.User | null
1918
if (userId) {
2019
const id = body.settings._id as string
2120
settings = isDefaultPreset(id) ? defaultPresets[id] : await store.presets.getUserPreset(id)
22-
user = await store.users.getUser(userId)
21+
body.user = await store.users.getUser(userId)
2322
}
2423

2524
if (!settings) {
@@ -29,18 +28,18 @@ export const plainGenerate = wrap(async ({ socketId, userId, body, log }, res) =
2928
)
3029
}
3130

32-
if (!user) {
31+
if (!body.user) {
3332
throw errors.Unauthorized
3433
}
3534

3635
res.json({ success: true, generating: true, message: 'Generating response' })
3736

3837
const { stream } = await createPlainStream({
39-
user,
38+
user: body.user,
4039
settings,
4140
log,
4241
prompt: body.prompt,
43-
guest: socketId,
42+
guest: userId ? undefined : socketId,
4443
})
4544

4645
let generated = ''
@@ -58,7 +57,11 @@ export const plainGenerate = wrap(async ({ socketId, userId, body, log }, res) =
5857

5958
if (gen.error) {
6059
error = true
61-
const payload = { type: 'plain-generate-error', requestId: body.requestId, error: gen.error }
60+
const payload = {
61+
type: 'plain-generate-complete',
62+
requestId: body.requestId,
63+
error: gen.error,
64+
}
6265
if (userId) sendOne(userId, payload)
6366
else sendGuest(socketId, payload)
6467
continue

srv/app.ts

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ if (!config.storage.enabled) {
3535
}
3636

3737
app.use('/', express.static(resolve(baseFolder, 'dist')))
38+
app.use('/', express.static(resolve(baseFolder, 'extras')))
39+
if (config.extraFolder) {
40+
app.use('/', express.static(config.extraFolder))
41+
}
3842

3943
app.use((req, res, next) => {
4044
if (req.url.startsWith('/api')) {

srv/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const config = {
4848
jwtExpiry: env('JWT_EXPIRY', '7d'),
4949
port: +env('PORT', '3001'),
5050
assetFolder: env('ASSET_FOLDER', resolve(__dirname, '..', 'dist', 'assets')),
51+
extraFolder: env('EXTRA_FOLDER', ''),
5152
db: {
5253
name: env('DB_NAME', 'agnai'),
5354
host: env('DB_HOST', '127.0.0.1'),

srv/db/schema.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export namespace AppSchema {
2727
maintenance?: string
2828
patreon?: boolean
2929
policies?: boolean
30+
flags?: string
3031
}
3132

3233
export type ChatMode = 'standard' | 'adventure'

srv/voice/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function processText(text: string, filterActions: boolean) {
162162
if (!text) return ''
163163
text = text.trim()
164164
if (filterActions) {
165-
text = text.replace(filterActionsRegex, '...')
165+
text = text.replace(filterActionsRegex, '')
166166
}
167167
text = text.replace(/[~]/g, ' ')
168168
return text

0 commit comments

Comments
 (0)