Skip to content

Commit ae79577

Browse files
committed
feat: Implement optional input slots for chat memories
Signed-off-by: Marcel Klehr <[email protected]>
1 parent e73a173 commit ae79577

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/TaskProcessing/AudioToAudioChatProvider.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public function getOptionalInputShape(): array {
8181
$this->l->t('The voice used to generate speech'),
8282
EShapeType::Enum
8383
),
84+
'memories' => new ShapeDescriptor(
85+
$this->l->t('Memories'),
86+
$this->l->t('The memories to be injected into the chat session.'),
87+
EShapeType::ListOfTexts
88+
),
8489
];
8590
if (!$isUsingOpenAi) {
8691
$ois['tts_model'] = new ShapeDescriptor(
@@ -165,6 +170,11 @@ public function process(?string $userId, array $input, callable $reportProgress)
165170
}
166171
$systemPrompt = $input['system_prompt'];
167172

173+
if (isset($input['memories']) && is_array($input['memories'])) {
174+
/** @psalm-suppress InvalidArgument */
175+
$systemPrompt .= "\n\nIf they are relevant, take into account the following memories:\n" . implode("\n\n", $input['memories']) . "\n\nDo not mention these memories explicitly. You may use them as context, but do not repeat them. At most, you can mention that you remember something.";
176+
}
177+
168178
if (!isset($input['history']) || !is_array($input['history'])) {
169179
throw new RuntimeException('Invalid chat history, array expected');
170180
}

lib/TaskProcessing/TextToTextChatProvider.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public function getOptionalInputShape(): array {
6060
$this->l->t('The maximum number of words/tokens that can be generated in the completion.'),
6161
EShapeType::Number
6262
),
63+
'memories' => new ShapeDescriptor(
64+
$this->l->t('Memories'),
65+
$this->l->t('The memories to be injected into the chat session.'),
66+
EShapeType::ListOfTexts
67+
),
6368
];
6469
}
6570

@@ -97,6 +102,11 @@ public function process(?string $userId, array $input, callable $reportProgress)
97102
}
98103
$systemPrompt = $input['system_prompt'];
99104

105+
if (isset($input['memories']) && is_array($input['memories'])) {
106+
/** @psalm-suppress InvalidArgument */
107+
$systemPrompt .= "\n\nIf they are relevant, take into account the following memories:\n" . implode("\n\n", $input['memories']) . "\n\nDo not mention these memories explicitly. You may use them as context, but do not repeat them. At most, you can mention that you remember something.";
108+
}
109+
100110
if (!isset($input['history']) || !is_array($input['history'])) {
101111
throw new RuntimeException('Invalid history');
102112
}

0 commit comments

Comments
 (0)