feat(ai): add AI::invoke() method for task suggestions

- Add generic invoke() static method to AI module for custom chat completion
- Fix AiTaskSuggestion::callAi() to properly handle AI::invoke() response
- Fix findSimilarTasks() to properly handle AI::getEmbedding() response

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kuaifan
2026-01-21 02:02:04 +00:00
parent 165ad03024
commit d4d7a0d69f
2 changed files with 105 additions and 3 deletions

View File

@@ -136,11 +136,13 @@ class AiTaskSuggestion
$searchText = $task->name . ' ' . ($task->content ?? '');
try {
$embedding = AI::getEmbedding($searchText);
if (empty($embedding)) {
$result = AI::getEmbedding($searchText);
if (Base::isError($result) || empty($result['data'])) {
return null;
}
$embedding = $result['data'];
// 搜索相似任务(排除自己和子任务)
$similarTasks = self::searchSimilarByEmbedding(
$embedding,
@@ -270,7 +272,12 @@ PROMPT;
['user', $prompt],
]);
return $result['content'] ?? null;
if (Base::isError($result)) {
\Log::error('AiTaskSuggestion::callAi error: ' . ($result['msg'] ?? 'Unknown error'));
return null;
}
return $result['data']['content'] ?? null;
} catch (\Exception $e) {
\Log::error('AiTaskSuggestion::callAi error: ' . $e->getMessage());
return null;