diff --git a/Classes/Controller/AssistantModuleController.php b/Classes/Controller/AssistantModuleController.php index f6e00b3..ecd74dd 100644 --- a/Classes/Controller/AssistantModuleController.php +++ b/Classes/Controller/AssistantModuleController.php @@ -90,13 +90,14 @@ public function createThreadAction(string $assistantId, string $message): void 'threadId' => $threadId, 'assistantId' => $assistantId, 'message' => $message, + 'additionalInstructions' => 'current date: ' . (new \DateTimeImmutable())->format('Y-m-d'), ]); } - public function addThreadMessageAction(string $threadId, string $assistantId, string $message): void + public function addThreadMessageAction(string $threadId, string $assistantId, string $message, ?string $additionalInstructions = null): void { $assistant = $this->assistantDepartment->findAssistantById($assistantId); - $metadata = $assistant->continueThread($threadId, $message); + $metadata = $assistant->continueThread($threadId, $message, $additionalInstructions); $this->view->assignMultiple([ 'messages' => $this->fetchMessages($threadId), diff --git a/Classes/Controller/ChatController.php b/Classes/Controller/ChatController.php index 6689d9c..a7f2e55 100644 --- a/Classes/Controller/ChatController.php +++ b/Classes/Controller/ChatController.php @@ -32,7 +32,7 @@ public function startAction(string $assistantId, string $message): void { $assistant = $this->assistantDepartment->findAssistantById($assistantId); $threadId = $assistant->startThread(); - $metadata = $assistant->continueThread($threadId, $message); + $metadata = $assistant->continueThread($threadId, $message, 'current date: ' . (new \DateTimeImmutable())->format('Y-m-d')); $messageResponse = $this->client->threads()->messages()->list($threadId)->data; /** @var ?ThreadMessageResponse $lastMessage */ diff --git a/Classes/Domain/Assistant.php b/Classes/Domain/Assistant.php index 3a532a8..67d07f0 100644 --- a/Classes/Domain/Assistant.php +++ b/Classes/Domain/Assistant.php @@ -28,15 +28,7 @@ public function startThread(): string $runResponse = $this->client->threads()->createAndRun([ 'assistant_id' => $this->id, 'thread' => [ - 'messages' => [ - [ - 'role' => 'user', - 'content' => 'current date: ' . (new \DateTimeImmutable())->format('Y-m-d'), - 'metadata' => [ - 'role' => 'system' - ] - ], - ] + 'messages' => [] ] ]); $this->completeRun($runResponse->threadId, $runResponse->id); @@ -47,7 +39,7 @@ public function startThread(): string /** * @return array */ - public function continueThread(string $threadId, string $message): array + public function continueThread(string $threadId, string $message, ?string $additionalInstructions = null): array { $this->client->threads()->messages()->create( $threadId, @@ -56,7 +48,13 @@ public function continueThread(string $threadId, string $message): array 'content' => $message ] ); - $runResponse = $this->client->threads()->runs()->create($threadId, ['assistant_id' => $this->id]); + $runResponse = $this->client->threads()->runs()->create( + $threadId, + array_filter([ + 'assistant_id' => $this->id, + 'additional_instructions' => $additionalInstructions + ]) + ); return $this->completeRun($threadId, $runResponse->id); }