EmbeddingService.php 430 B

123456789101112131415161718
  1. <?php
  2. namespace App\Services;
  3. use Symfony\Component\Process\Process;
  4. class EmbeddingService
  5. {
  6. public function generate($text)
  7. {
  8. $process = new Process(['python3', 'scripts/generate_embedding.py', $text]);
  9. $process->run();
  10. if (!$process->isSuccessful()) {
  11. throw new \Exception('Embedding generation failed');
  12. }
  13. return json_decode($process->getOutput(), true);
  14. }
  15. }