49 خطوط
1.4 KiB
PHP
49 خطوط
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\AI\Http;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Modules\AI\Application\AiProviderResolver;
|
|
use App\Modules\Identity\Application\RolePermissions;
|
|
use App\Modules\Identity\Domain\Enums\Permission;
|
|
use App\Modules\Tenancy\Application\TenantContext;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
final class AiChatController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly TenantContext $tenant,
|
|
private readonly RolePermissions $permissions,
|
|
private readonly AiProviderResolver $providers,
|
|
) {}
|
|
|
|
public function chat(Request $request): JsonResponse
|
|
{
|
|
abort_unless($this->permissions->allows($request->user(), Permission::CoursesAuthor), 403);
|
|
$validated = $request->validate(['prompt' => ['required', 'string', 'max:10000']]);
|
|
$answer = $this->providers->forOrganization($this->tenant->id())->chat(
|
|
$validated['prompt'],
|
|
<<<'PROMPT'
|
|
You are an expert instructional designer.
|
|
|
|
Your specialty is:
|
|
- Microlearning
|
|
- Adult learning
|
|
- Corporate learning
|
|
- Instructional design
|
|
- Learning objectives
|
|
- Assessments
|
|
- Scenario-based learning
|
|
|
|
Answer in Persian unless the user explicitly requests another language.
|
|
PROMPT,
|
|
);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => ['answer' => $answer],
|
|
]);
|
|
}
|
|
}
|