Skip to content

Commit

Permalink
Merge pull request #11 from sitegeist/task/externamRunInstructions
Browse files Browse the repository at this point in the history
TASK: Allow to pass `additionalInstructions` with the start and post endpoints
  • Loading branch information
mficzel authored Mar 7, 2024
2 parents 60c967d + a1eafdb commit 3dc806c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Classes/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function injectMetaDataCache(VariableFrontend $metaDataCache): void
$this->metaDataCache = $metaDataCache;
}

public function startAction(string $organizationId, string $assistantId, string $message): string
public function startAction(string $organizationId, string $assistantId, string $message, ?string $additionalInstructions = null): string
{
$organization = $this->organizationRepository->findById($organizationId);
$assistant = $organization->assistantDepartment->findAssistantById($assistantId);
$threadId = $assistant->startThread();
$assistant->continueThread($threadId, $message);
$assistant->continueThread($threadId, $message, $additionalInstructions);

$messageResponses = $assistant->readThread($threadId);
$lastMessageKey = array_key_last($messageResponses);
Expand Down Expand Up @@ -88,11 +88,11 @@ function (MessageRecord $message) use ($cachedMetadata, $assistantId, $threadId)
);
}

public function postAction(string $organizationId, string $assistantId, string $threadId, string $message): string
public function postAction(string $organizationId, string $assistantId, string $threadId, string $message, ?string $additionalInstructions = null): string
{
$organization = $this->organizationRepository->findById($organizationId);
$assistant = $organization->assistantDepartment->findAssistantById($assistantId);
$assistant->continueThread($threadId, $message);
$assistant->continueThread($threadId, $message, $additionalInstructions);

$messageResponses = $assistant->readThread($threadId);
$lastMessageKey = array_key_last($messageResponses);
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Assistant.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function startThread(): string
return $threadResponse->id;
}

public function continueThread(string $threadId, string $message): void
public function continueThread(string $threadId, string $message, ?string $additionalInstructions = null): void
{
$this->client->threads()->messages()->create(
$threadId,
Expand All @@ -65,7 +65,7 @@ public function continueThread(string $threadId, string $message): void
$threadId,
array_filter([
'assistant_id' => $this->id,
'additional_instructions' => $this->instructions->getContent()
'additional_instructions' => $this->instructions->getContent() . ($additionalInstructions ? " \n" . $additionalInstructions : '')
])
);
$this->completeRun($threadId, $runResponse->id);
Expand Down

0 comments on commit 3dc806c

Please sign in to comment.