feat(06-task-title-ai): complete OpenAI task title suggestions
Phase 6 complete: - add AI title generator service using gpt-5-nano - add task popup button for biuro@project-pro.pl - add AJAX endpoint returning title suggestions without auto-save
This commit is contained in:
@@ -372,6 +372,51 @@ class Tasks
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function task_generate_title()
|
||||
{
|
||||
global $user, $settings;
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Nie udało się wygenerować tytułu zadania.' ];
|
||||
|
||||
if ( !$user or !isset( $user['email'] ) or strtolower( trim( (string)$user['email'] ) ) !== 'biuro@project-pro.pl' )
|
||||
{
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak uprawnień do generowania tytułu.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$task_id = (int)\S::get( 'task_id' );
|
||||
if ( !$task_id )
|
||||
{
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Nieprawidłowe zadanie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$task = \factory\Tasks::task_details( $task_id, (int)$user['id'] );
|
||||
if ( !is_array( $task ) or !isset( $task['id'] ) )
|
||||
{
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Nie znaleziono zadania.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$task_text = isset( $task['text'] ) ? trim( (string)$task['text'] ) : '';
|
||||
if ( $task_text === '' )
|
||||
{
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Zadanie nie ma treści do wygenerowania tytułu.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$api_key = isset( $settings['openai_api_key'] ) ? trim( (string)$settings['openai_api_key'] ) : '';
|
||||
$model = isset( $settings['openai_task_title_model'] ) ? trim( (string)$settings['openai_task_title_model'] ) : 'gpt-5-nano';
|
||||
$generator = new \Domain\Tasks\TaskTitleGenerator();
|
||||
$result = $generator -> generate( $api_key, $model, $task_text );
|
||||
|
||||
if ( is_array( $result ) and isset( $result['status'] ) )
|
||||
$response = $result;
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function task_change_text() {
|
||||
global $mdb;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user