Spaces:
Runtime error
Runtime error
Download src/Controller/ApiController.php from Alcazard/vibe-coding-api: direct link, hf CLI and curl.
- Browser
- Download file 2.94 kB
-
https://huggingface.co/spaces/Alcazard/vibe-coding-api/resolve/main/src/Controller/ApiController.php
- Command line
-
hf download hf://spaces/Alcazard/vibe-coding-api/src/Controller/ApiController.php
-
curl -L -o ApiController.php https://huggingface.co/spaces/Alcazard/vibe-coding-api/resolve/main/src/Controller/ApiController.php
2.94 kB
| namespace VibeCoding\Controller; | |
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |
| use Symfony\Component\HttpFoundation\JsonResponse; | |
| use Symfony\Component\HttpFoundation\Request; | |
| use Symfony\Component\HttpFoundation\Response; | |
| use Symfony\Component\Routing\Annotation\Route; | |
| use Symfony\Contracts\HttpClient\HttpClientInterface; | |
| class ApiController extends AbstractController | |
| { | |
| private HttpClientInterface $httpClient; | |
| public function __construct(HttpClientInterface $httpClient) | |
| { | |
| $this->httpClient = $httpClient; | |
| } | |
| ('/api/status', name: 'api_status', methods: ['GET']) | |
| public function status(): JsonResponse | |
| { | |
| return $this->json([ | |
| 'status' => 'online', | |
| 'providers' => [ | |
| 'openrouter' => 200, | |
| 'gemini' => 1500 | |
| ], | |
| 'version' => '1.0.0' | |
| ]); | |
| } | |
| ('/api/generate', name: 'api_generate', methods: ['POST']) | |
| public function generate(Request $request): JsonResponse | |
| { | |
| $data = json_decode($request->getContent(), true); | |
| $prompt = $data['prompt'] ?? ''; | |
| try { | |
| // Construction du message avec instructions | |
| $systemMessage = "Tu es un assistant de programmation. Réponds de façon claire et concise.\n\n"; | |
| $fullPrompt = $systemMessage . "Utilisateur: " . $prompt . "\nAssistant:"; | |
| // Appel à l'IA locale (llama.cpp) avec paramètres anti-spam | |
| $iaResponse = $this->httpClient->request('POST', 'http://localhost:8080/completion', [ | |
| 'json' => [ | |
| 'prompt' => $fullPrompt, | |
| 'n_predict' => 256, // ← Plus court | |
| 'temperature' => 0.3, // ← Moins créatif | |
| 'top_k' => 30, // ← Limite les choix | |
| 'top_p' => 0.8, // ← Plus sévère | |
| 'repeat_penalty' => 1.3, // ← Anti-spam renforcé | |
| 'repeat_last_n' => 128, // ← Surveille plus longtemps | |
| 'frequency_penalty' => 0.5, // ← Pénalise répétitions | |
| 'presence_penalty' => 0.5, // ← Encourage diversité | |
| 'stop' => ["\n", "\n\n", "Utilisateur:", "Assistant:"], // ← Stop rapide | |
| 'min_p' => 0.05 | |
| ], | |
| 'timeout' => 30 | |
| ]); | |
| $iaData = $iaResponse->toArray(); | |
| $code = $iaData['content'] ?? '// Pas de réponse'; | |
| } catch (\Exception $e) { | |
| $code = '// Erreur IA : ' . $e->getMessage(); | |
| } | |
| return $this->json([ | |
| 'code' => $code, | |
| 'model' => 'nanbeige-3b-local' | |
| ]); | |
| } | |
| } |