Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion lib/Service/ChatService.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,21 @@ private function checkIfSessionIsThinking(?string $userId, string $customId): vo
}
}

/**
* Give a chat task the conversation ID of its session, but only when the
* provider of the task type declares a conversation ID as an optional input
* slot. Providers generate a throwaway ID for the requests we leave unset.
*
* @param array<string, mixed> $input
* @return array<string, mixed>
*/
private function addConversationId(array $input, string $taskTypeId, string $conversationId): array {
if (isset($this->taskProcessingManager->getAvailableTaskTypes()[$taskTypeId]['optionalInputShape']['conversation_id'])) {
$input['conversation_id'] = $conversationId;
}
return $input;
}

/**
* Schedule a Chat task
*
Expand All @@ -749,9 +764,15 @@ private function scheduleLLMChatTask(
'system_prompt' => $systemPrompt,
'history' => $history,
];
if (isset($this->taskProcessingManager->getAvailableTaskTypes()[TextToTextChat::ID]['optionalInputShape']['memories'])) {
if ($isMessage && isset($this->taskProcessingManager->getAvailableTaskTypes()[TextToTextChat::ID]['optionalInputShape']['memories'])) {
$input['memories'] = $this->sessionSummaryService->getMemories($userId);
}
// the title generation must not join the conversation state of the chat itself
$input = $this->addConversationId(
$input,
TextToTextChat::ID,
$isMessage ? (string)$sessionId : $sessionId . '-title',
);
$task = new Task(TextToTextChat::ID, $input, Application::APP_ID . ':chatty-llm', $userId, $customId);
/** @psalm-suppress UndefinedMethod */
$task->setPreferStreaming(true);
Expand Down Expand Up @@ -795,6 +816,8 @@ private function scheduleMultimodalChatTask(
'tool_message' => '',
];
/** @psalm-suppress UndefinedClass */
$input = $this->addConversationId($input, \OCP\TaskProcessing\TaskTypes\MultimodalChatWithTools::ID, (string)$sessionId);
/** @psalm-suppress UndefinedClass */
$task = new Task(\OCP\TaskProcessing\TaskTypes\MultimodalChatWithTools::ID, $input, Application::APP_ID . ':chatty-llm', $userId, $customId);
/** @psalm-suppress UndefinedMethod */
$task->setPreferStreaming(true);
Expand Down Expand Up @@ -838,6 +861,8 @@ private function scheduleAgencyTask(
$taskInput['memories'] = $this->sessionSummaryService->getMemories($userId);
}
/** @psalm-suppress UndefinedClass */
$taskInput = $this->addConversationId($taskInput, \OCP\TaskProcessing\TaskTypes\ContextAgentInteraction::ID, (string)$sessionId);
/** @psalm-suppress UndefinedClass */
$task = new Task(
\OCP\TaskProcessing\TaskTypes\ContextAgentInteraction::ID,
$taskInput,
Expand Down Expand Up @@ -887,6 +912,8 @@ private function scheduleAgencyMultimodalTask(
];
$taskInput['memories'] = $this->sessionSummaryService->getMemories($userId);
/** @psalm-suppress UndefinedClass */
$taskInput = $this->addConversationId($taskInput, \OCP\TaskProcessing\TaskTypes\MultimodalContextAgentInteraction::ID, (string)$sessionId);
/** @psalm-suppress UndefinedClass */
$task = new Task(
\OCP\TaskProcessing\TaskTypes\MultimodalContextAgentInteraction::ID,
$taskInput,
Expand Down Expand Up @@ -936,6 +963,8 @@ private function scheduleAudioChatTask(
$input['memories'] = $this->sessionSummaryService->getMemories($userId);
}
/** @psalm-suppress UndefinedClass */
$input = $this->addConversationId($input, \OCP\TaskProcessing\TaskTypes\AudioToAudioChat::ID, (string)$sessionId);
/** @psalm-suppress UndefinedClass */
$task = new Task(
\OCP\TaskProcessing\TaskTypes\AudioToAudioChat::ID,
$input,
Expand Down Expand Up @@ -983,6 +1012,8 @@ private function scheduleAgencyAudioTask(
$taskInput['memories'] = $this->sessionSummaryService->getMemories($userId);
}
/** @psalm-suppress UndefinedClass */
$taskInput = $this->addConversationId($taskInput, \OCP\TaskProcessing\TaskTypes\ContextAgentAudioInteraction::ID, (string)$sessionId);
/** @psalm-suppress UndefinedClass */
$task = new Task(
\OCP\TaskProcessing\TaskTypes\ContextAgentAudioInteraction::ID,
$taskInput,
Expand Down
Loading