Skip to content

Commit bb29c47

Browse files
committed
types: small tweaks
1 parent c695bc4 commit bb29c47

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

compose.dev.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ services:
3434
container_name: ccat_ts_cache_dev
3535
expose:
3636
- 6379
37-
restart: unless-stopped
37+
restart: unless-stopped

compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ services:
3636
container_name: ccat_ts_cache
3737
expose:
3838
- 6379
39-
restart: unless-stopped
39+
restart: unless-stopped

src/context.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,19 @@ export const swaggerTags = {
4040

4141
const jsonLiterals = t.Union([t.String(), t.Number(), t.Boolean(), t.Null()])
4242

43-
// TODO: Wait until https://github.com/elysiajs/elysia/issues/848 is fixed, to use t.Intersect()
44-
export const messageInput = t.Record(t.String(), t.Any(), {
43+
export const messageInput = t.Intersect([
44+
t.Object({
45+
text: t.String(),
46+
}),
47+
t.Record(t.String(), t.Any()),
48+
], {
4549
$id: 'messageInput',
4650
title: 'Message Input',
4751
description: 'Message to pass to the cat',
4852
default: { text: 'Hello, world' },
53+
examples: [{
54+
text: 'Hello, world',
55+
}],
4956
})
5057

5158
export const memoryMessage = t.Object({
@@ -60,15 +67,15 @@ export const memoryMessage = t.Object({
6067
input: t.Union([t.String(), t.Null()]),
6168
observation: t.String(),
6269
})),
63-
memory: t.Optional(t.Intersect([
70+
memory: t.Intersect([
6471
t.Object({
6572
episodic: t.Array(t.Record(t.String(), t.Any())),
6673
declarative: t.Array(t.Record(t.String(), t.Any())),
6774
procedural: t.Array(t.Record(t.String(), t.Any())),
6875
}),
6976
t.Record(t.String(), t.Array(t.Record(t.String(), t.Any()))),
70-
])),
71-
interactions: t.Optional(t.Array(t.Record(t.String(), t.Any()))),
77+
]),
78+
interactions: t.Array(t.Record(t.String(), t.Any())),
7279
})),
7380
}, {
7481
$id: 'memoryMessage',

src/dtos/message.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,22 @@ export type ModelInteraction = LLMInteraction | EmbedderInteraction
6565
/**
6666
* The content of a memory message.
6767
*/
68-
export interface MemoryMessage {
68+
export type MemoryMessage = {
6969
role: 'AI' | 'User'
7070
what: string
7171
who: string
7272
when: number
73+
} & ({
74+
role: 'AI'
7375
why?: {
7476
input: string
7577
intermediateSteps: IntermediateStep[]
76-
memory?: WorkingMemory
77-
interactions?: ModelInteraction[]
78+
memory: WorkingMemory
79+
interactions: ModelInteraction[]
7880
}
79-
}
81+
} | {
82+
role: 'User'
83+
})
8084

8185
/**
8286
* A message object sent by the user.

src/looking_glass/stray-cat.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ export class StrayCat {
148148

149149
const response = this.userMessage = await madHatter.executeHook('beforeReadMessage', msg, this)
150150

151+
if (!('text' in response)) {
152+
log.warn('The message does not contain any text. Ignoring it...')
153+
return {
154+
type: 'notification',
155+
content: 'The message does not contain any text. Ignoring it...',
156+
}
157+
}
158+
151159
// FEATURE: Find another way to handle this
152160
if (response.text.length > cheshireCat.embedderSize) {
153161
log.warn(`The input is too long. Storing it as document...`)
@@ -206,7 +214,7 @@ export class StrayCat {
206214

207215
if (save) this.chatHistory.push(structuredClone(finalOutput))
208216

209-
if (!returnWhy) delete finalOutput.why
217+
if (!returnWhy && finalOutput.role === 'AI') delete finalOutput.why
210218

211219
this.modelsInteractions = []
212220

src/routes/general.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const generalRoutes = new Elysia({
7676
},
7777
}).post('/chat', async ({ stray, body, query }) => {
7878
const { save, why } = query
79-
const res = await stray.run(body as any, save, why)
79+
const res = await stray.run(body, save, why)
8080
return res
8181
}, {
8282
body: 'messageInput',

0 commit comments

Comments
 (0)