PHP code example of intelligent-intern / azure-bundle
1. Go to this page and download the library: Download intelligent-intern/azure-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
intelligent-intern / azure-bundle example snippets
namespace App\Controller;
use App\Service\Api\AIServiceFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class EmbeddingController extends AbstractController
{
public function __construct(
private AIServiceFactory $aiServiceFactory
) {}
public function generateEmbedding(Request $request): JsonResponse
{
$input = $request->get('input', '');
if (empty($input)) {
return new JsonResponse(['error' => 'Input cannot be empty'], 400);
}
try {
$aiService = $this->aiServiceFactory->create();
$embedding = $aiService->generateEmbedding($input);
return new JsonResponse(['embedding' => $embedding]);
} catch (\Exception $e) {
return new JsonResponse(['error' => $e->getMessage()], 500);
}
}