2
0

AIModelService.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Services;
  3. use App\Models\AiModel;
  4. use App\Http\Resources\AiModelResource;
  5. use Illuminate\Support\Facades\Cache;
  6. class AIModelService
  7. {
  8. public function getModelsById($id)
  9. {
  10. // 添加表存在检查
  11. if (!\Illuminate\Support\Facades\Schema::hasTable('ai_models')) {
  12. return [];
  13. }
  14. $table = AiModel::whereIn('uid', $id);
  15. $result = $table->get();
  16. return AiModelResource::collection(resource: $result);
  17. }
  18. public function getModelById($id)
  19. {
  20. // 添加表存在检查
  21. if (!\Illuminate\Support\Facades\Schema::hasTable('ai_models')) {
  22. return [];
  23. }
  24. $result = AiModel::where('uid', $id)
  25. ->first();
  26. return new AiModelResource(resource: $result);
  27. }
  28. public function getSysModels($type = null)
  29. {
  30. // 添加表存在检查
  31. if (!\Illuminate\Support\Facades\Schema::hasTable('ai_models')) {
  32. return [];
  33. }
  34. if (empty($type)) {
  35. $types = ['wbw', 'chat', 'summarize'];
  36. } else {
  37. $types = [$type];
  38. }
  39. $sysModels = [];
  40. foreach ($types as $key => $type) {
  41. $sysModels[$type] = $this->getModelsById(Cache::get('/ai/model/system/' . $type) ?? []);
  42. }
  43. if (!empty($type)) {
  44. return $sysModels[$type];
  45. }
  46. return $sysModels;
  47. }
  48. }