Skip to content

Commit

Permalink
Handle current date with additional instructions instead of obsolete …
Browse files Browse the repository at this point in the history
…message
  • Loading branch information
Bernhard Schmitt committed Jan 24, 2024
1 parent 076087a commit 28b60b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Classes/Controller/AssistantModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 100 in Classes/Controller/AssistantModuleController.php

View workflow job for this annotation

GitHub Actions / Test (PHP 8.1, Flow 8.3)

Cannot call method continueThread() on Sitegeist\Chatterbox\Domain\Assistant|null.

$this->view->assignMultiple([
'messages' => $this->fetchMessages($threadId),
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function startAction(string $assistantId, string $message): void
{
$assistant = $this->assistantDepartment->findAssistantById($assistantId);
$threadId = $assistant->startThread();

Check failure on line 34 in Classes/Controller/ChatController.php

View workflow job for this annotation

GitHub Actions / Test (PHP 8.1, Flow 8.3)

Cannot call method startThread() on Sitegeist\Chatterbox\Domain\Assistant|null.
$metadata = $assistant->continueThread($threadId, $message);
$metadata = $assistant->continueThread($threadId, $message, 'current date: ' . (new \DateTimeImmutable())->format('Y-m-d'));

Check failure on line 35 in Classes/Controller/ChatController.php

View workflow job for this annotation

GitHub Actions / Test (PHP 8.1, Flow 8.3)

Cannot call method continueThread() on Sitegeist\Chatterbox\Domain\Assistant|null.

$messageResponse = $this->client->threads()->messages()->list($threadId)->data;
/** @var ?ThreadMessageResponse $lastMessage */
Expand Down
20 changes: 9 additions & 11 deletions Classes/Domain/Assistant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -47,7 +39,7 @@ public function startThread(): string
/**
* @return array<int,mixed>
*/
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,
Expand All @@ -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);
}

Expand Down

0 comments on commit 28b60b4

Please sign in to comment.