UpgradeAITerm.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Services\AIModelService;
  5. use App\Services\TermService;
  6. use App\Services\AIAssistant\AITermService;
  7. use App\Http\Resources\AiModelResource;
  8. use App\Http\Controllers\AuthController;
  9. class UpgradeAITerm extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. * php artisan upgrade:ai.term --id=e07bf5b8-bd81-4f0a-9d2c-8e0128b954d7
  14. * php artisan upgrade:ai.term
  15. * @var string
  16. */
  17. protected $signature = 'upgrade:ai.term {--id=} {--resume} {--model=} ';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = 'Command description';
  24. protected AiModelResource $model;
  25. protected $modelToken;
  26. protected $workChannel;
  27. protected $accessToken;
  28. /**
  29. * Create a new command instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct(
  34. protected AIModelService $modelService,
  35. protected TermService $termService,
  36. protected AITermService $aiTermService
  37. ) {
  38. parent::__construct();
  39. }
  40. /**
  41. * Execute the console command.
  42. *
  43. * @return int
  44. */
  45. public function handle()
  46. {
  47. if (!$this->option('model')) {
  48. $modelId = $this->ask('请输入 llm model id');
  49. } else {
  50. $modelId = $this->option('model');
  51. }
  52. $this->aiTermService->setModel($modelId);
  53. $this->model = $this->modelService->getModelById($modelId);
  54. $this->info("model:{$this->model['model']}");
  55. $this->modelToken = AuthController::getUserToken($modelId);
  56. if ($this->option('id')) {
  57. $terms = [['guid' => $this->option('id'), 'word' => 'word']];
  58. } else {
  59. $terms = $this->termService->getCommunityGlossary('zh-Hans')['items']->toArray();
  60. }
  61. foreach ($terms as $key => $term) {
  62. $this->info("[{$term['word']}] running");
  63. $result = $this->aiTermService->update($term['guid']);
  64. $this->info("[{$term['word']}]content " . substr($result, 0, 30));
  65. }
  66. return 0;
  67. }
  68. }