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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user