visuddhinanda 6 дней назад
Родитель
Сommit
1d50cf6dbe

+ 3 - 1
api-v12/app/Console/Commands/TestAIArticleTranslate.php

@@ -49,7 +49,9 @@ class TestAIArticleTranslate extends Command
             $this->info('anthology translate start');
             $total = $service->setModel($this->option('model'))
                 ->setChannel($this->option('channel'))
-                ->translateAnthology($this->option('anthology'));
+                ->translateAnthology($this->option('anthology'), function ($article) {
+                    $this->info('translating article ' . $article);
+                });
             $this->info("{$total} article saved");
         }
     }

+ 8 - 2
api-v12/app/Services/AIAssistant/ArticleTranslateService.php

@@ -11,6 +11,7 @@ use App\Models\CustomBook;
 
 use Illuminate\Support\Facades\Log;
 use App\Http\Api\ChannelApi;
+use Carbon\Callback;
 
 class ArticleTranslateService
 {
@@ -81,12 +82,17 @@ class ArticleTranslateService
         $this->outputChannelId = $id;
         return $this;
     }
-    public function translateAnthology($anthologyId)
+    public function translateAnthology($anthologyId, ?callable $fn = null): int
     {
         $articles = $this->articleService->articlesInAnthology($anthologyId);
-        foreach ($articles as $key => $article) {
+
+        foreach ($articles as $article) {
+            if ($fn) {
+                $fn($article);
+            }
             $this->translateArticle($article)->save();
         }
+
         return count($articles);
     }
     public function translateArticle(string $articleId)