{"repo": "alexandredovale/eva", "files": {"modules/runtime/src/LanguageModelApi.php": {"71710b9f9789f85c948aef6d1b05c8a01dbb5b81": {"t": 1786068382.75717, "n": 3656, "h": "f83f1d20bdee1069", "c": " $capabilities @param array $aiConfiguration */\n public function __construct(\n private array $capabilities,\n private array $aiConfiguration\n ) {\n }\n\n /** @param array $input @return array */\n public function generateJson(string $systemInstruction, array $input): array\n {\n if (!in_array('ai.language.generate', $this->capabilities, true)) {\n throw new ModuleException('O módulo não declarou a capacidade ai.language.generate.');\n }\n\n if (($this->aiConfiguration['live_enabled'] ?? false) !== true) {\n throw new ModuleException('As chamadas reais de IA estão desabilitadas.');\n }\n\n $provider = $this->aiConfiguration['providers']['query_answers'] ?? null;\n\n if (!is_array($provider)) {\n throw new ModuleException('O provedor de linguagem do EVA não está configurado.');\n }\n\n $endpoint = is_string($provider['endpoint'] ?? null) ? rtrim($provider['endpoint'], '/') : '';\n $model = is_string($provider['model'] ?? null) ? trim($provider['model']) : '';\n $keyEnvironment = is_string($provider['api_key_environment'] ?? null)\n ? trim($provider['api_key_environment'])\n : '';\n $apiKey = $keyEnvironment !== '' ? (string) Env::get($keyEnvironment, '') : '';\n\n if ($endpoint === '' || $model === '' || $apiKey === '') {\n throw new ModuleException('O provedor de linguagem do EVA está incompleto.');\n }\n\n try {\n $inputJson = json_encode($input, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);\n } catch (JsonException $exception) {\n throw new ModuleException('A entrada do módulo não pode ser serializada.', 0, $exception);\n }\n\n $client = new CurlJsonHttpClient();\n $request = [\n 'model' => $model,\n 'messages' => [\n ['role' => 'system', 'content' => $systemInstruction],\n ['role' => 'user', 'content' => $inputJson],\n ],\n 'response_format' => ['type' => 'json_object'],\n 'temperature' => 0,\n 'max_tokens' => max(3000, min(6000, (int) ($provider['max_output_tokens'] ?? 3000))),\n ];\n $providerHost = strtolower((string) parse_url($endpoint, PHP_URL_HOST));\n\n if ($providerHost === 'api.deepseek.com') {\n $request['thinking'] = ['type' => 'disabled'];\n }\n\n $response = $client->post(\n $endpoint,\n ['Authorization: Bearer ' . $apiKey],\n $request,\n max(5, min(120, (int) ($this->aiConfiguration['request_timeout_seconds'] ?? 30)))\n );\n $content = $response['choices'][0]['message']['content'] ?? null;\n\n if (!is_string($content) || trim($content) === '') {\n throw new ModuleException('O provedor de linguagem não retornou conteúdo JSON.');\n }\n\n try {\n $decoded = json_decode($content, true, 64, JSON_THROW_ON_ERROR);\n } catch (JsonException $exception) {\n throw new ModuleException('O provedor de linguagem retornou conteúdo inválido.', 0, $exception);\n }\n\n if (!is_array($decoded)) {\n throw new ModuleException('O provedor de linguagem retornou uma estrutura inválida.');\n }\n\n return $decoded;\n }\n}\n"}}}}