Download assistant.php from Alascoci/archive: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/spaces/Alascoci/archive/resolve/main/assistant.php
- Command line
-
hf download hf://spaces/Alascoci/archive/assistant.php
-
curl -L -o assistant.php https://huggingface.co/spaces/Alascoci/archive/resolve/main/assistant.php
1.76 kB
| ```php | |
| namespace App\Http\Controllers; | |
| use Illuminate\Http\Request; | |
| use App\Models\Document; | |
| use App\Services\OCRService; | |
| use App\Services\AIService; | |
| class AssistantController extends Controller | |
| { | |
| protected $aiService; | |
| protected $ocrService; | |
| public function __construct(AIService $aiService, OCRService $ocrService) | |
| { | |
| $this->aiService = $aiService; | |
| $this->ocrService = $ocrService; | |
| } | |
| public function question(Request $request) | |
| { | |
| $request->validate([ | |
| 'question' => 'required|string', | |
| 'document_id' => 'required|integer|exists:documents,id' | |
| ]); | |
| $document = Document::findOrFail($request->document_id); | |
| // Check user permissions | |
| if (!auth()->user()->canAccessDocument($document)) { | |
| return response()->json(['error' => 'Accès non autorisé'], 403); | |
| } | |
| // Extract text from document | |
| $text = $this->ocrService->extractText($document->file_path); | |
| // Get AI response | |
| $response = $this->aiService->askQuestion($request->question, $text, $document->id); | |
| // Log the interaction | |
| $this->logInteraction(auth()->id(), $document->id, $request->question, $response); | |
| return response()->json([ | |
| 'response' => $response, | |
| 'document' => $document->name | |
| ]); | |
| } | |
| protected function logInteraction($userId, $documentId, $question, $response) | |
| { | |
| \DB::table('assistant_logs')->insert([ | |
| 'user_id' => $userId, | |
| 'document_id' => $documentId, | |
| 'question' => $question, | |
| 'response' => $response, | |
| 'created_at' => now(), | |
| 'updated_at' => now() | |
| ]); | |
| } | |
| } | |
| ``` | |
| ``` |