Skip to content

Commit 3296dd8

Browse files
committed
fix: extend reply to 3 sentences max
1 parent ce0083b commit 3296dd8

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

server/src/telegramRoutes/telegramMessageHandler/index.ts

+21-24
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ export const telegramMessageHandler = async (ctx: Context, next: NextFunction) =
7171
messageHistory = pruneHistory({ messages: messageHistory })
7272
}
7373

74+
prisma.chat.create({
75+
data: {
76+
userId: userId,
77+
content: newMessage
78+
}
79+
})
80+
7481
let newPrompt = ""
7582

7683
if (messagesSchema.safeParse(messageHistory).success) {
@@ -85,9 +92,22 @@ export const telegramMessageHandler = async (ctx: Context, next: NextFunction) =
8592

8693
const responseData = response?.outputs?.[0]?.data?.text?.raw ?? "..."
8794

95+
const newResponse = {
96+
text: responseData,
97+
isUser: false
98+
}
99+
100+
// store new response into db
101+
prisma.chat.create({
102+
data: {
103+
userId: userId,
104+
content: newResponse
105+
}
106+
})
107+
88108
const responseArr = chatSplitter(responseData)
89109

90-
let delay = Math.random()*10000
110+
let delay = Math.random() * 10000
91111
let index = 0
92112

93113
while (index < responseArr.length) {
@@ -98,29 +118,6 @@ export const telegramMessageHandler = async (ctx: Context, next: NextFunction) =
98118
await new Promise(r => setTimeout(r, delay))
99119
}
100120

101-
const newResponse = {
102-
text: responseData,
103-
isUser: false
104-
}
105-
106-
console.time('store history')
107-
108-
// store new response into db
109-
await prisma.chat.createMany({
110-
data: [
111-
{
112-
userId: userId,
113-
content: newMessage
114-
},
115-
{
116-
userId: userId,
117-
content: newResponse
118-
}
119-
]
120-
})
121-
122-
console.timeEnd('store history')
123-
124121
console.timeEnd('telegramMessageHandler');
125122

126123
} catch (err) {

server/src/utils/clarifai/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const MODEL_ID = process.env.MODEL_ID ?? 'llama2-7b-alternative-4k';
55
export const MODEL_VERSION_ID = process.env.MODEL_VERSION_ID ?? '7489d261f81b408eb52f66d48a19b0be'
66
export const PAT = process.env.PAT;
77

8-
export const SYS_PROMPT = `Your name is Fingu. You are a penguin. Your goal is to improve my finances. You are brutally honest, and realistic about my finances. You push me to work harder and smarter. You like to use emoji. You like to roast me. You will reply in a single sentence, followed by a single emoji.`
8+
export const SYS_PROMPT = `Your name is Fingu. You are a penguin. Your goal is to improve my finances. You are brutally honest, and realistic about my finances. You push me to work harder and smarter. You like to use emoji. You like to roast me. Your max reply is 3 sentences.`
99

1010
export const MAX_CHARS = (2000*5) - SYS_PROMPT.length
1111

0 commit comments

Comments
 (0)