Skip to content

Commit 4c4ee6d

Browse files
committed
use the current date by default for new messages and new sessions
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 7e69659 commit 4c4ee6d

4 files changed

Lines changed: 20 additions & 18 deletions

File tree

lib/Controller/ChattyLLMController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private function improveAgencyActionNames(array $actions): array {
199199
*
200200
* Create a new chat session, add a system message with user instructions
201201
*
202-
* @param int $timestamp The session creation date
202+
* @param ?int $timestamp The session creation date
203203
* @param ?string $title The session title
204204
* @return JSONResponse<Http::STATUS_OK, array{session: AssistantChatSession}, array{}>|JSONResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_UNAUTHORIZED, array{error: string}, array{}>
205205
* @throws AppConfigTypeConflictException
@@ -209,7 +209,7 @@ private function improveAgencyActionNames(array $actions): array {
209209
*/
210210
#[NoAdminRequired]
211211
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT, tags: ['chat_api'])]
212-
public function newSession(int $timestamp, ?string $title = null): JSONResponse {
212+
public function newSession(?int $timestamp = null, ?string $title = null): JSONResponse {
213213
try {
214214
$session = $this->chatService->createChatSession($this->userId, $timestamp, $title);
215215
return new JSONResponse([
@@ -342,7 +342,7 @@ public function getSessions(): JSONResponse {
342342
* @param int $sessionId The chat session ID
343343
* @param string $role Role of the message (human, assistant etc...)
344344
* @param string $content Content of the message
345-
* @param int $timestamp Date of the message
345+
* @param ?int $timestamp Date of the message
346346
* @param ?list<array{type: string, file_id: int}> $attachments List of attachment objects
347347
* @param bool $firstHumanMessage Is it the first human message of the session?
348348
* @return JSONResponse<Http::STATUS_OK, AssistantChatMessage, array{}>|JSONResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_UNAUTHORIZED|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array{error: string}, array{}>
@@ -355,7 +355,7 @@ public function getSessions(): JSONResponse {
355355
#[NoAdminRequired]
356356
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT, tags: ['chat_api'])]
357357
public function newMessage(
358-
int $sessionId, string $role, string $content, int $timestamp, ?array $attachments = null, bool $firstHumanMessage = false,
358+
int $sessionId, string $role, string $content, ?int $timestamp = null, ?array $attachments = null, bool $firstHumanMessage = false,
359359
): JSONResponse {
360360
try {
361361
$message = $this->chatService->createMessage($this->userId, $sessionId, $role, $content, $timestamp, $attachments, $firstHumanMessage);

lib/Service/AssignmentsService.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function createAssignment(?string $userId, string $title, string $prompt,
7171
} catch (Exception $e) {
7272
throw new InternalException(previous: $e);
7373
}
74-
$session = $this->chatService->createChatSession($userId, $this->timeFactory->now()->getTimestamp(), $title);
74+
$session = $this->chatService->createChatSession($userId, title: $title);
7575
$session->setAssignmentId($assignment->getId());
7676
try {
7777
$this->sessionMapper->update($session);
@@ -121,7 +121,7 @@ public function scheduleAssignmentRun(?string $userId, int $assignmentId): void
121121
$assignment = $this->assignmentMapper->find($userId, $assignmentId);
122122
$assignment->setLastRunAt($this->timeFactory->now()->getTimestamp());
123123
$this->assignmentMapper->update($assignment);
124-
$this->chatService->createMessage($userId, $session->getId(), Message::ROLE_HUMAN, $assignment->getPrompt(), $this->timeFactory->now()->getTimestamp());
124+
$this->chatService->createMessage($userId, $session->getId(), Message::ROLE_HUMAN, $assignment->getPrompt());
125125
$this->chatService->scheduleAssignmentMessageGeneration($userId, $session->getId());
126126
} catch (BadRequestException|InternalException|DoesNotExistException|MultipleObjectsReturnedException|Exception $e) {
127127
$this->logger->error('Error while running assignment ' . $assignmentId . ' for user ' . $userId, ['exception' => $e]);
@@ -132,7 +132,6 @@ public function scheduleAssignmentRun(?string $userId, int $assignmentId): void
132132
$session->getId(),
133133
Message::ROLE_ASSISTANT,
134134
$this->l10n->t('An error occurred while scheduling this assignment run. Reach out to your system administrator if this issue persists.'),
135-
$this->timeFactory->now()->getTimestamp()
136135
);
137136
} catch (BadRequestException|InternalException|NotFoundException|UnauthorizedException $e) {
138137
$this->logger->error('Error while creating error message for assignment ' . $assignmentId . ' for user ' . $userId, ['exception' => $e]);

lib/Service/ChatService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function getSessionsForUser(?string $userId): array {
174174
* @throws NotFoundException
175175
* @throws UnauthorizedException
176176
*/
177-
public function createMessage(?string $userId, int $sessionId, string $role, string $content, int $timestamp, ?array $attachments = null, bool $firstHumanMessage = false): Message {
177+
public function createMessage(?string $userId, int $sessionId, string $role, string $content, ?int $timestamp = null, ?array $attachments = null, bool $firstHumanMessage = false): Message {
178178
if ($userId === null) {
179179
throw new UnauthorizedException($this->l10n->t('Unauthorized'));
180180
}
@@ -183,6 +183,10 @@ public function createMessage(?string $userId, int $sessionId, string $role, str
183183
throw new BadRequestException($this->l10n->t('The new message is too long'));
184184
}
185185

186+
if ($timestamp === null) {
187+
$timestamp = $this->timeFactory->now()->getTimestamp();
188+
}
189+
186190
if ($timestamp > 10_000_000_000) {
187191
$timestamp = intdiv($timestamp, 1000);
188192
}

openapi.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,18 +2760,17 @@
27602760
}
27612761
],
27622762
"requestBody": {
2763-
"required": true,
2763+
"required": false,
27642764
"content": {
27652765
"application/json": {
27662766
"schema": {
27672767
"type": "object",
2768-
"required": [
2769-
"timestamp"
2770-
],
27712768
"properties": {
27722769
"timestamp": {
27732770
"type": "integer",
27742771
"format": "int64",
2772+
"nullable": true,
2773+
"default": null,
27752774
"description": "The session creation date"
27762775
},
27772776
"title": {
@@ -3271,18 +3270,17 @@
32713270
}
32723271
],
32733272
"requestBody": {
3274-
"required": true,
3273+
"required": false,
32753274
"content": {
32763275
"application/json": {
32773276
"schema": {
32783277
"type": "object",
3279-
"required": [
3280-
"timestamp"
3281-
],
32823278
"properties": {
32833279
"timestamp": {
32843280
"type": "integer",
32853281
"format": "int64",
3282+
"nullable": true,
3283+
"default": null,
32863284
"description": "The session creation date"
32873285
},
32883286
"title": {
@@ -3680,8 +3678,7 @@
36803678
"required": [
36813679
"sessionId",
36823680
"role",
3683-
"content",
3684-
"timestamp"
3681+
"content"
36853682
],
36863683
"properties": {
36873684
"sessionId": {
@@ -3700,6 +3697,8 @@
37003697
"timestamp": {
37013698
"type": "integer",
37023699
"format": "int64",
3700+
"nullable": true,
3701+
"default": null,
37033702
"description": "Date of the message"
37043703
},
37053704
"attachments": {

0 commit comments

Comments
 (0)