working version of the braindump, it generates task suggestions
This commit is contained in:
@@ -352,4 +352,9 @@ header {
|
||||
.task-list__item--completed .task-list__title {
|
||||
opacity: .65;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
.tasks-result {
|
||||
background-color: #fff;
|
||||
color: #000;
|
||||
padding: 25px;
|
||||
}
|
||||
@@ -21,27 +21,140 @@ final class BraindumpController extends AbstractController
|
||||
Request $request,
|
||||
HttpClientInterface $client
|
||||
): Response {
|
||||
if (!$this->isCsrfTokenValid(
|
||||
'braindump_dump',
|
||||
$request->getPayload()->getString('_token')
|
||||
)) {
|
||||
// Give Ollama enough time to process a larger brain dump.
|
||||
set_time_limit(120);
|
||||
|
||||
// Check the CSRF token.
|
||||
if (
|
||||
!$this->isCsrfTokenValid(
|
||||
'braindump_dump',
|
||||
$request->getPayload()->getString('_token')
|
||||
)
|
||||
) {
|
||||
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
||||
}
|
||||
|
||||
// Get the user's brain dump.
|
||||
$brainDump = $request->getPayload()->getString('brain_dump');
|
||||
|
||||
$response = $client->request('POST', 'http://192.168.1.238:11434/api/generate', [
|
||||
'json' => [
|
||||
'model' => 'qwen3:4b',
|
||||
'prompt' => $brainDump,
|
||||
'stream' => false,
|
||||
// dd('THIS IS THE NEW CONTROLLER', $brainDump);
|
||||
// Tell Ollama exactly what structure we want back.
|
||||
$schema = [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'tasks' => [
|
||||
'type' => 'array',
|
||||
'items' => [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'title' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
'description' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
'estimatedDurationMinutes' => [
|
||||
'type' => 'integer',
|
||||
],
|
||||
'priority' => [
|
||||
'type' => 'string',
|
||||
'enum' => [
|
||||
'Low',
|
||||
'Medium',
|
||||
'High',
|
||||
],
|
||||
],
|
||||
'category' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
'isRecurring' => [
|
||||
'type' => 'boolean',
|
||||
],
|
||||
],
|
||||
'required' => [
|
||||
'title',
|
||||
'description',
|
||||
'estimatedDurationMinutes',
|
||||
'priority',
|
||||
'category',
|
||||
'isRecurring',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
'required' => [
|
||||
'tasks',
|
||||
],
|
||||
];
|
||||
|
||||
// Ask Ollama to turn the brain dump into concrete tasks.
|
||||
$response = $client->request(
|
||||
'POST',
|
||||
'http://192.168.1.238:11434/api/generate',
|
||||
[
|
||||
'timeout' => 120,
|
||||
'max_duration' => 120,
|
||||
|
||||
'json' => [
|
||||
'model' => 'qwen3:4b',
|
||||
|
||||
'prompt' => <<<PROMPT
|
||||
You are a task extraction assistant.
|
||||
|
||||
Turn the user's brain dump into a list of concrete, actionable tasks.
|
||||
|
||||
Rules:
|
||||
- Break large tasks into sensible individual tasks.
|
||||
- Keep task titles concise.
|
||||
- Write a short description where useful.
|
||||
- Estimate realistic durations in minutes.
|
||||
- Use Low, Medium, or High priority.
|
||||
- Use a short, sensible category.
|
||||
- Only mark a task as recurring if the user explicitly indicates that it should recur.
|
||||
- Do not invent tasks that are not reasonably implied by the brain dump.
|
||||
- Return only the requested JSON structure.
|
||||
|
||||
User's brain dump:
|
||||
|
||||
$brainDump
|
||||
PROMPT,
|
||||
|
||||
// Structured output using the JSON schema above.
|
||||
'format' => $schema,
|
||||
|
||||
// We want one complete response rather than a stream.
|
||||
'stream' => false,
|
||||
|
||||
// More deterministic output is useful for structured data.
|
||||
'options' => [
|
||||
'temperature' => 0,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$data = $response->toArray();
|
||||
// dd($data);
|
||||
// dd($data['response']);
|
||||
file_put_contents(
|
||||
'/tmp/ollama-response.txt',
|
||||
$data['response'] ?? 'NO RESPONSE'
|
||||
);
|
||||
|
||||
//$json = $data['response'] ?? '{"tasks":[]}';
|
||||
$json = $data['thinking'] ?? '{"tasks":[]}';
|
||||
$tasks = json_decode($json, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new \RuntimeException(
|
||||
'Invalid JSON returned by Ollama: '
|
||||
. json_last_error_msg()
|
||||
. "\n\nRaw response:\n"
|
||||
. $json
|
||||
);
|
||||
}
|
||||
// Give the tasks to our HTMX partial.
|
||||
return $this->render('braindump/_task_result.html.twig', [
|
||||
'response' => $data['response'] ?? 'No response received.',
|
||||
'tasks' => $tasks['tasks'] ?? [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,30 @@
|
||||
<div>
|
||||
<h2>Ollama says:</h2>
|
||||
{% if tasks is empty %}
|
||||
<p>No tasks were suggested.</p>
|
||||
{% else %}
|
||||
<h2>Suggested tasks</h2>
|
||||
|
||||
<p>{{ response|nl2br }}</p>
|
||||
</div>
|
||||
{% for task in tasks %}
|
||||
<article>
|
||||
<h3>{{ task.title }}</h3>
|
||||
<ul>
|
||||
{% if task.description %}
|
||||
<li><p>{{ task.description }}</p></li>
|
||||
{% endif %}
|
||||
|
||||
<li>
|
||||
<dt>Duration</dt>
|
||||
<dd>{{ task.estimatedDurationMinutes }} minutes</dd>
|
||||
|
||||
<dt>Priority</dt>
|
||||
<dd>{{ task.priority }}</dd>
|
||||
|
||||
<dt>Category</dt>
|
||||
<dd>{{ task.category }}</dd>
|
||||
|
||||
<dt>Recurring</dt>
|
||||
<dd>{{ task.isRecurring ? 'Yes' : 'No' }}</dd>
|
||||
</li>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
@@ -3,7 +3,7 @@
|
||||
{% block title %}Brain Dump{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
<div class="container">
|
||||
<h1>Brain Dump</h1>
|
||||
|
||||
<form
|
||||
@@ -40,8 +40,8 @@
|
||||
|
||||
</form>
|
||||
|
||||
<div id="tasks-result">
|
||||
<div id="tasks-result" class="task-result">
|
||||
{# HTMX will put the proposed tasks here #}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user