Giter VIP home page Giter VIP logo

Comments (18)

ChristophWurst avatar ChristophWurst commented on August 24, 2024 2

is this a breaking change?

from mail.

ChristophWurst avatar ChristophWurst commented on August 24, 2024 2

I see. This is very unfortunate to announce after feature freeze and branch-off.

from mail.

julien-nc avatar julien-nc commented on August 24, 2024 1

\OCP\TaskProcessing\IManager::scheduleTask

You can get the task ID right after having scheduled it:

$this->taskProcessingManager->scheduleTask($task);
$taskId = $task->getId();

The tasks can't run synchronously anymore because many providers may take too long and it's possible to reach the Php process timeout. Tasks are processed in background jobs (which can be fast if occ background-job:worker "OC\TaskProcessing\SynchronousBackgroundJob" is running).

The OCP\TaskProcessing\Events\TaskSuccessfulEvent and OCP\TaskProcessing\Events\TaskFailedEvent events are dispatched after the task has succeeded/failed. They contain the task.

If you want to still do something similar than \OCP\TextProcessing\IManager::runTask you can have a poll loop in the backend right after having scheduled it:

$task = $this->taskProcessingManager->getTask($taskId);
if ($task->getStatus() === Task::STATUS_SUCCESSFUL) {
    // do something with the result
}

from mail.

julien-nc avatar julien-nc commented on August 24, 2024

The textProcessing API will stay one or two major NC versions. But the apps that implement providers have migrated to taskProcessing (or will do soon). So you might run out of providers. I guess that can be considered as a breaking change.

from mail.

ChristophWurst avatar ChristophWurst commented on August 24, 2024

@julien-nc what is the replacement for \OCP\TextProcessing\IManager::runTask?

from mail.

ChristophWurst avatar ChristophWurst commented on August 24, 2024

(which can be fast if occ background-job:worker "OC\TaskProcessing\SynchronousBackgroundJob" is running).

Is there a solution without this? Unfortunately I can't assume that every Nextcloud installation has this process running

from mail.

julien-nc avatar julien-nc commented on August 24, 2024

If this is not running, the taskProcessing jobs run when cron.php is executed.

from mail.

ChristophWurst avatar ChristophWurst commented on August 24, 2024

To elaborate why Mail uses the synchronous mode fully intentionally: want to process emails as late as possible when the user opens them, but then show the results right away.
Background processing is extremely expensive because we have to process all emails of an IMAP account.
Dispatching an async task only when the user opens a message breaks the UX because it would take a bit of time for the results to be ready.

Hope this makes sense.

from mail.

ChristophWurst avatar ChristophWurst commented on August 24, 2024

If this is not running, the taskProcessing jobs run when cron.php is executed.

A well configured system has cron set up for a 5m interval. Some older system still use 15m, tiny setup use irregular ajax cron.
I'd say even the 5m are not acceptable for a reaction time for a thread summary in Mail

from mail.

julien-nc avatar julien-nc commented on August 24, 2024

If the Mail frontend sends a synchronous request to the server which blocks until the task has finished (with textProcessing or with taskProcessing), it blocks a Php runner so it can have an impact on the general server performance. Also this Php process might always get killed if it's too long and no result can ever be produced.
We can't guarantee synchronous tasks will succeed as we can't predict how much time it will take the providers to process them.

That's why tasks are now always processed in bg jobs.

Running the occ bg job worker is strongly recommended to be able to run AI tasks with no delay.
We had to deal with a trade off between convenience for the developers, failure potential and constraints on the admins.
If Nextcloud was a persistent process which could run threads, it would be possible to have synchronous processes.
I hope this makes sense as well.

from mail.

ChristophWurst avatar ChristophWurst commented on August 24, 2024

We target only openai for our integration (the rest is too slow), so the process is mostly IO bound when it waits for the API response. The blocked request is OK for us.

I get the general push towards async processing for tasks of unknown complexity, though.

from mail.

DaphneMuller avatar DaphneMuller commented on August 24, 2024

The local LLM2 is now equally fast and could be potentially used also (although we did not run tests on large texts).

from mail.

julien-nc avatar julien-nc commented on August 24, 2024

One more detail: the occ bg job worker only runs tasks for which the responsible provider is implemented in a Php app.
The providers that are implemented in an external application are consuming tasks as soon as they are ready. They are making request to Nextcloud to get tasks that they can process. There is no delay there, even without the worker.

from mail.

ChristophWurst avatar ChristophWurst commented on August 24, 2024

@DaphneMuller nice! I'll still have to wait 5-15 minutes for the result when the special worker process is not running, right?

from mail.

julien-nc avatar julien-nc commented on August 24, 2024

I'll still have to wait 5-15 minutes for the result when the special worker process is not running, right?

Like mentioned before, not if the provider is LLM2 (which is an external application).

from mail.

ChristophWurst avatar ChristophWurst commented on August 24, 2024

Then I misread.

@julien-nc do you have some example code for getting synchronous-ish results from LLM2 without the use of occ background-job:worker "OC\TaskProcessing\SynchronousBackgroundJob"?

In my understanding the LLM processing would not happen until the next cron execution.

from mail.

julien-nc avatar julien-nc commented on August 24, 2024

With or without the worker, you can schedule a task and immediately start checking if it's finished or not (in the frontend or in the backend, as you wish).
In the backend, it can be done like said before, getTask and task->getStatus.
In the frontend, ocs/v2.php/taskprocessing/task/TASK_ID to get the task.

from mail.

julien-nc avatar julien-nc commented on August 24, 2024

We can also keep the providers for the old APIs in integration_openai and the features in Mail are not broken.

from mail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.