diff --git a/lib/TaskProcessing/AudioToAudioChatProvider.php b/lib/TaskProcessing/AudioToAudioChatProvider.php index 9e0502c0..b1362489 100644 --- a/lib/TaskProcessing/AudioToAudioChatProvider.php +++ b/lib/TaskProcessing/AudioToAudioChatProvider.php @@ -81,6 +81,11 @@ public function getOptionalInputShape(): array { $this->l->t('The voice used to generate speech'), EShapeType::Enum ), + 'memories' => new ShapeDescriptor( + $this->l->t('Memories'), + $this->l->t('The memories to be injected into the chat session.'), + EShapeType::ListOfTexts + ), ]; if (!$isUsingOpenAi) { $ois['tts_model'] = new ShapeDescriptor( @@ -165,6 +170,11 @@ public function process(?string $userId, array $input, callable $reportProgress) } $systemPrompt = $input['system_prompt']; + if (isset($input['memories']) && is_array($input['memories']) && count($input['memories'])) { + /** @psalm-suppress InvalidArgument */ + $systemPrompt .= "\n\nYou can remember things from other conversation with the user. If 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."; + } + if (!isset($input['history']) || !is_array($input['history'])) { throw new RuntimeException('Invalid chat history, array expected'); } diff --git a/lib/TaskProcessing/TextToTextChatProvider.php b/lib/TaskProcessing/TextToTextChatProvider.php index 52084d7b..c50d7cc3 100644 --- a/lib/TaskProcessing/TextToTextChatProvider.php +++ b/lib/TaskProcessing/TextToTextChatProvider.php @@ -60,6 +60,11 @@ public function getOptionalInputShape(): array { $this->l->t('The maximum number of words/tokens that can be generated in the completion.'), EShapeType::Number ), + 'memories' => new ShapeDescriptor( + $this->l->t('Memories'), + $this->l->t('The memories to be injected into the chat session.'), + EShapeType::ListOfTexts + ), ]; } @@ -97,6 +102,11 @@ public function process(?string $userId, array $input, callable $reportProgress) } $systemPrompt = $input['system_prompt']; + if (isset($input['memories']) && is_array($input['memories']) && count($input['memories'])) { + /** @psalm-suppress InvalidArgument */ + $systemPrompt .= "\n\nYou can remember things from other conversations with the user. If 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."; + } + if (!isset($input['history']) || !is_array($input['history'])) { throw new RuntimeException('Invalid history'); }