Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/carlossimoes04_desenvolvimento-de-aplicacoes-moveis-leim-sv25-26.json
T

1 line
30 KiB
JSON

{"repo": "carlossimoes04/desenvolvimento-de-aplicacoes-moveis-leim-sv25-26", "files": {"AISimpleCalls/src/main/kotlin/dam/Utils.kt": {"22c1f06d30cacbec0810f6675324a6cdc3d7be5e": {"t": 1785745712.6226757, "n": 4011, "h": "6efb85a2fccc3cad", "c": "package dam\n\nimport ch.qos.logback.classic.Level\nimport ch.qos.logback.classic.LoggerContext\nimport org.slf4j.LoggerFactory\nimport java.io.FileInputStream\nimport java.util.Properties\n\nconst val configFilePath = \"config.properties\"\n\n/**\n * Retrieves configuration properties by loading them from a predefined configuration file.\n */\nprivate val configProperties\n get() = loadProperties()\n\n/**\n * Returns the Properties object containing configuration values.\n *\n * @return Properties object containing configuration values\n */\nfun getProperties(): Properties = configProperties\n\n/**\n * Loads configuration properties from config.properties file\n *\n * @return Properties object containing configuration values\n */\nprivate fun loadProperties(): Properties {\n val properties = Properties()\n try {\n val configFile = java.io.File(configFilePath)\n if (!configFile.exists()) {\n println(\"⚠️ Configuration file not found: $configFilePath\")\n println(\"⚠️ Please create this file with your API keys and settings\")\n return properties\n }\n\n FileInputStream(configFile).use { inputStream ->\n properties.load(inputStream)\n\n // Check if we have at least one API key\n if (properties.getProperty(\"OPENAI_API_KEY\").isNullOrBlank() &&\n properties.getProperty(\"GEMINI_API_KEY\").isNullOrBlank() &&\n properties.getProperty(\"NVIDIA_KIMI_API_KEY\").isNullOrBlank() &&\n properties.getProperty(\"NVIDIA_DEEPSEEK_API_KEY\").isNullOrBlank()\n ) {\n println(\"⚠️ No API keys found in configuration file\")\n println(\"⚠️ Please add at least one API key to $configFilePath\")\n } else {\n val apiKeys = listOf(\"OPENAI_API_KEY\", \"GEMINI_API_KEY\", \"NVIDIA_KIMI_API_KEY\", \"NVIDIA_DEEPSEEK_API_KEY\").filter {\n properties.getProperty(it)?.isNotBlank() == true\n }.toList()\n\n println(\"✅ Found ${apiKeys.size} API key(s) in configuration: $apiKeys\")\n }\n }\n } catch (e: Exception) {\n println(\"❌ Error loading properties: ${e.message}\")\n println(\" Make sure '$configFilePath' exists and is properly formatted\")\n }\n return properties\n}\n\n/**\n * Configures the logging level for all loggers based on the LOG_LEVEL property.\n * Valid levels are: OFF, ERROR, WARN, INFO, DEBUG, TRACE\n *\n * @param properties The properties containing the LOG_LEVEL setting\n */\nfun configureLogging(properties: Properties) {\n // Silence SLF4J initialization messages\n System.setProperty(\"org.slf4j.simpleLogger.defaultLogLevel\", \"OFF\")\n System.setProperty(\"org.slf4j.simpleLogger.log.org.slf4j.LoggerFactory\", \"OFF\")\n\n val defaultLevel = \"OFF\"\n val logLevelStr = properties.getProperty(\"LOG_LEVEL\", defaultLevel).uppercase()\n\n try {\n // Convert string to Logback Level\n val logLevel = when (logLevelStr) {\n \"OFF\" -> Level.OFF\n \"ERROR\" -> Level.ERROR\n \"WARN\" -> Level.WARN\n \"INFO\" -> Level.INFO\n \"DEBUG\" -> Level.DEBUG\n \"TRACE\" -> Level.TRACE\n else -> {\n println(\"⚠️ Invalid LOG_LEVEL '$logLevelStr'. Using $defaultLevel as default.\")\n Level.OFF\n }\n }\n\n // Get the logger context\n val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext\n\n // Set the level on the root logger\n val rootLogger = loggerContext.getLogger(\"ROOT\")\n rootLogger.level = logLevel\n\n // Set the level for our application package\n val appLogger = loggerContext.getLogger(\"dam\")\n appLogger.level = logLevel\n\n // Only print logging info if we're not completely silencing logs\n if (logLevel != Level.OFF) {\n println(\"🔊 Logging level: $logLevelStr\")\n }\n } catch (e: Exception) {\n println(\"❌ Failed to set logging level: ${e.message}\")\n }\n}\n\n\n\n\n"}, "5ad15f53dc485983e7d5bd4977eba8a8600c77f7": {"t": 1785755815.0766327, "n": 4011, "h": "6efb85a2fccc3cad", "c": "package dam\n\nimport ch.qos.logback.classic.Level\nimport ch.qos.logback.classic.LoggerContext\nimport org.slf4j.LoggerFactory\nimport java.io.FileInputStream\nimport java.util.Properties\n\nconst val configFilePath = \"config.properties\"\n\n/**\n * Retrieves configuration properties by loading them from a predefined configuration file.\n */\nprivate val configProperties\n get() = loadProperties()\n\n/**\n * Returns the Properties object containing configuration values.\n *\n * @return Properties object containing configuration values\n */\nfun getProperties(): Properties = configProperties\n\n/**\n * Loads configuration properties from config.properties file\n *\n * @return Properties object containing configuration values\n */\nprivate fun loadProperties(): Properties {\n val properties = Properties()\n try {\n val configFile = java.io.File(configFilePath)\n if (!configFile.exists()) {\n println(\"⚠️ Configuration file not found: $configFilePath\")\n println(\"⚠️ Please create this file with your API keys and settings\")\n return properties\n }\n\n FileInputStream(configFile).use { inputStream ->\n properties.load(inputStream)\n\n // Check if we have at least one API key\n if (properties.getProperty(\"OPENAI_API_KEY\").isNullOrBlank() &&\n properties.getProperty(\"GEMINI_API_KEY\").isNullOrBlank() &&\n properties.getProperty(\"NVIDIA_KIMI_API_KEY\").isNullOrBlank() &&\n properties.getProperty(\"NVIDIA_DEEPSEEK_API_KEY\").isNullOrBlank()\n ) {\n println(\"⚠️ No API keys found in configuration file\")\n println(\"⚠️ Please add at least one API key to $configFilePath\")\n } else {\n val apiKeys = listOf(\"OPENAI_API_KEY\", \"GEMINI_API_KEY\", \"NVIDIA_KIMI_API_KEY\", \"NVIDIA_DEEPSEEK_API_KEY\").filter {\n properties.getProperty(it)?.isNotBlank() == true\n }.toList()\n\n println(\"✅ Found ${apiKeys.size} API key(s) in configuration: $apiKeys\")\n }\n }\n } catch (e: Exception) {\n println(\"❌ Error loading properties: ${e.message}\")\n println(\" Make sure '$configFilePath' exists and is properly formatted\")\n }\n return properties\n}\n\n/**\n * Configures the logging level for all loggers based on the LOG_LEVEL property.\n * Valid levels are: OFF, ERROR, WARN, INFO, DEBUG, TRACE\n *\n * @param properties The properties containing the LOG_LEVEL setting\n */\nfun configureLogging(properties: Properties) {\n // Silence SLF4J initialization messages\n System.setProperty(\"org.slf4j.simpleLogger.defaultLogLevel\", \"OFF\")\n System.setProperty(\"org.slf4j.simpleLogger.log.org.slf4j.LoggerFactory\", \"OFF\")\n\n val defaultLevel = \"OFF\"\n val logLevelStr = properties.getProperty(\"LOG_LEVEL\", defaultLevel).uppercase()\n\n try {\n // Convert string to Logback Level\n val logLevel = when (logLevelStr) {\n \"OFF\" -> Level.OFF\n \"ERROR\" -> Level.ERROR\n \"WARN\" -> Level.WARN\n \"INFO\" -> Level.INFO\n \"DEBUG\" -> Level.DEBUG\n \"TRACE\" -> Level.TRACE\n else -> {\n println(\"⚠️ Invalid LOG_LEVEL '$logLevelStr'. Using $defaultLevel as default.\")\n Level.OFF\n }\n }\n\n // Get the logger context\n val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext\n\n // Set the level on the root logger\n val rootLogger = loggerContext.getLogger(\"ROOT\")\n rootLogger.level = logLevel\n\n // Set the level for our application package\n val appLogger = loggerContext.getLogger(\"dam\")\n appLogger.level = logLevel\n\n // Only print logging info if we're not completely silencing logs\n if (logLevel != Level.OFF) {\n println(\"🔊 Logging level: $logLevelStr\")\n }\n } catch (e: Exception) {\n println(\"❌ Failed to set logging level: ${e.message}\")\n }\n}\n\n\n\n\n"}, "f5c433df7c19eb03a4432a572aa3e5ecae6df878": {"t": 1785755816.5976844, "n": 3795, "h": "05b2ece08305fa2f", "c": "package dam\n\nimport ch.qos.logback.classic.Level\nimport ch.qos.logback.classic.LoggerContext\nimport org.slf4j.LoggerFactory\nimport java.io.FileInputStream\nimport java.util.Properties\n\nconst val configFilePath = \"config.properties\"\n\n/**\n * Retrieves configuration properties by loading them from a predefined configuration file.\n */\nprivate val configProperties\n get() = loadProperties()\n\n/**\n * Returns the Properties object containing configuration values.\n *\n * @return Properties object containing configuration values\n */\nfun getProperties(): Properties = configProperties\n\n/**\n * Loads configuration properties from config.properties file\n *\n * @return Properties object containing configuration values\n */\nprivate fun loadProperties(): Properties {\n val properties = Properties()\n try {\n val configFile = java.io.File(configFilePath)\n if (!configFile.exists()) {\n println(\"⚠️ Configuration file not found: $configFilePath\")\n println(\"⚠️ Please create this file with your API keys and settings\")\n return properties\n }\n\n FileInputStream(configFile).use { inputStream ->\n properties.load(inputStream)\n\n // Check if we have at least one API key\n if (properties.getProperty(\"OPENAI_API_KEY\").isNullOrBlank() &&\n properties.getProperty(\"GEMINI_API_KEY\").isNullOrBlank()\n ) {\n println(\"⚠️ No API keys found in configuration file\")\n println(\"⚠️ Please add at least one API key to $configFilePath\")\n } else {\n val apiKeys = listOf(\"OPENAI_API_KEY\", \"GEMINI_API_KEY\").filter {\n properties.getProperty(it)?.isNotBlank() == true\n }.toList()\n\n println(\"✅ Found ${apiKeys.size} API key(s) in configuration: $apiKeys\")\n }\n }\n } catch (e: Exception) {\n println(\"❌ Error loading properties: ${e.message}\")\n println(\" Make sure '$configFilePath' exists and is properly formatted\")\n }\n return properties\n}\n\n/**\n * Configures the logging level for all loggers based on the LOG_LEVEL property.\n * Valid levels are: OFF, ERROR, WARN, INFO, DEBUG, TRACE\n *\n * @param properties The properties containing the LOG_LEVEL setting\n */\nfun configureLogging(properties: Properties) {\n // Silence SLF4J initialization messages\n System.setProperty(\"org.slf4j.simpleLogger.defaultLogLevel\", \"OFF\")\n System.setProperty(\"org.slf4j.simpleLogger.log.org.slf4j.LoggerFactory\", \"OFF\")\n\n val defaultLevel = \"OFF\"\n val logLevelStr = properties.getProperty(\"LOG_LEVEL\", defaultLevel).uppercase()\n\n try {\n // Convert string to Logback Level\n val logLevel = when (logLevelStr) {\n \"OFF\" -> Level.OFF\n \"ERROR\" -> Level.ERROR\n \"WARN\" -> Level.WARN\n \"INFO\" -> Level.INFO\n \"DEBUG\" -> Level.DEBUG\n \"TRACE\" -> Level.TRACE\n else -> {\n println(\"⚠️ Invalid LOG_LEVEL '$logLevelStr'. Using $defaultLevel as default.\")\n Level.OFF\n }\n }\n\n // Get the logger context\n val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext\n\n // Set the level on the root logger\n val rootLogger = loggerContext.getLogger(\"ROOT\")\n rootLogger.level = logLevel\n\n // Set the level for our application package\n val appLogger = loggerContext.getLogger(\"dam\")\n appLogger.level = logLevel\n\n // Only print logging info if we're not completely silencing logs\n if (logLevel != Level.OFF) {\n println(\"🔊 Logging level: $logLevelStr\")\n }\n } catch (e: Exception) {\n println(\"❌ Failed to set logging level: ${e.message}\")\n }\n}\n\n\n\n\n"}}, "AISimpleCalls/src/main/kotlin/dam/AIAssistantDeepSeek.kt": {"22c1f06d30cacbec0810f6675324a6cdc3d7be5e": {"t": 1785745734.1129446, "n": 4123, "h": "a5f79a4817564987", "c": "package dam\n\nimport okhttp3.MediaType.Companion.toMediaTypeOrNull\nimport okhttp3.Request\nimport okhttp3.RequestBody.Companion.toRequestBody\nimport org.json.JSONArray\nimport org.json.JSONException\nimport org.json.JSONObject\nimport java.util.*\n\n/**\n * AIAssistantDeepSeek class provides an interface to communicate with Nvidia's DeepSeek AI models.\n * This class handles API authentication, request formatting, response parsing, and error handling.\n */\nclass AIAssistantDeepSeek(override val properties: Properties) : AIAssistant {\n\n override fun getSystem() = \"DEEPSEEK\"\n override val apiKeyName = \"NVIDIA_DEEPSEEK_API_KEY\"\n override var model = \"deepseek-ai/deepseek-v4-pro\"\n\n override val client: okhttp3.OkHttpClient\n get() = okhttp3.OkHttpClient.Builder()\n .readTimeout(180, java.util.concurrent.TimeUnit.SECONDS)\n .connectTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n .writeTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n .callTimeout(210, java.util.concurrent.TimeUnit.SECONDS)\n .build()\n\n /**\n * Constructs and formats a structured request from the given input prompt.\n */\n override fun buildRequest(prompt: String): Request {\n val messagesArray = JSONArray().put(\n JSONObject()\n .put(\"role\", \"user\")\n .put(\"content\", prompt)\n )\n\n val requestBody = JSONObject()\n .put(\"model\", model)\n .put(\"messages\", messagesArray)\n .put(\"max_tokens\", getMaxTokensOrDefault(16384))\n .put(\"temperature\", getTemperatureOrDefault(1.0))\n .put(\"top_p\", 0.95)\n .put(\"stream\", false)\n .put(\"chat_template_kwargs\", JSONObject().put(\"thinking\", false))\n .toString()\n\n return Request.Builder()\n .url(\"https://integrate.api.nvidia.com/v1/chat/completions\")\n .addHeader(\"Authorization\", \"Bearer $apiKey\")\n .addHeader(\"Accept\", \"application/json\")\n .addHeader(\"Content-Type\", \"application/json\")\n .post(requestBody.toRequestBody(\"application/json\".toMediaTypeOrNull()))\n .build()\n }\n\n /**\n * Makes an API call with the provided prompt and processes the DeepSeek JSON response.\n */\n override fun makeApiCall(prompt: String): String {\n logger.info(\"Prompt:\\n$prompt\")\n val request = buildRequest(prompt)\n\n client.newCall(request).execute().use { response ->\n if (!response.isSuccessful) {\n val errorBody = response.body?.string()\n throw Exception(\"Error in API call: ${response.code} - ${response.message}\\nResponse: $errorBody\")\n }\n\n val responseBody = response.body?.string() ?: return \"Error: empty response\"\n\n try {\n val json = JSONObject(responseBody)\n logger.debug(\"Raw API response: {}\", responseBody)\n\n if (!json.has(\"choices\") || json.getJSONArray(\"choices\").length() == 0) {\n return \"Error: No choices found in the API response\"\n }\n\n val choices = json.getJSONArray(\"choices\")\n val firstChoice = choices.getJSONObject(0)\n\n if (!firstChoice.has(\"message\")) {\n return \"Error: No message found in the API response\"\n }\n\n val message = firstChoice.getJSONObject(\"message\")\n\n if (!message.has(\"content\") || message.isNull(\"content\")) {\n return \"Error: No content found in the API response\"\n }\n\n return message.getString(\"content\").trim()\n\n } catch (e: JSONException) {\n val truncatedResponse = if (responseBody.length > 200) \"${responseBody.substring(0, 200)}...\" else responseBody\n logger.error(\"Error parsing JSON response: ${e.message}\")\n logger.error(\"Response body (truncated): $truncatedResponse\")\n throw Exception(\"Failed to parse API response: ${e.message}\", e)\n }\n }\n }\n}\n"}, "d411d32cd3fc4b0c82c802c4efeeef83296d8b66": {"t": 1785755813.769539, "n": 4123, "h": "a5f79a4817564987", "c": "package dam\n\nimport okhttp3.MediaType.Companion.toMediaTypeOrNull\nimport okhttp3.Request\nimport okhttp3.RequestBody.Companion.toRequestBody\nimport org.json.JSONArray\nimport org.json.JSONException\nimport org.json.JSONObject\nimport java.util.*\n\n/**\n * AIAssistantDeepSeek class provides an interface to communicate with Nvidia's DeepSeek AI models.\n * This class handles API authentication, request formatting, response parsing, and error handling.\n */\nclass AIAssistantDeepSeek(override val properties: Properties) : AIAssistant {\n\n override fun getSystem() = \"DEEPSEEK\"\n override val apiKeyName = \"NVIDIA_DEEPSEEK_API_KEY\"\n override var model = \"deepseek-ai/deepseek-v4-pro\"\n\n override val client: okhttp3.OkHttpClient\n get() = okhttp3.OkHttpClient.Builder()\n .readTimeout(180, java.util.concurrent.TimeUnit.SECONDS)\n .connectTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n .writeTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n .callTimeout(210, java.util.concurrent.TimeUnit.SECONDS)\n .build()\n\n /**\n * Constructs and formats a structured request from the given input prompt.\n */\n override fun buildRequest(prompt: String): Request {\n val messagesArray = JSONArray().put(\n JSONObject()\n .put(\"role\", \"user\")\n .put(\"content\", prompt)\n )\n\n val requestBody = JSONObject()\n .put(\"model\", model)\n .put(\"messages\", messagesArray)\n .put(\"max_tokens\", getMaxTokensOrDefault(16384))\n .put(\"temperature\", getTemperatureOrDefault(1.0))\n .put(\"top_p\", 0.95)\n .put(\"stream\", false)\n .put(\"chat_template_kwargs\", JSONObject().put(\"thinking\", false))\n .toString()\n\n return Request.Builder()\n .url(\"https://integrate.api.nvidia.com/v1/chat/completions\")\n .addHeader(\"Authorization\", \"Bearer $apiKey\")\n .addHeader(\"Accept\", \"application/json\")\n .addHeader(\"Content-Type\", \"application/json\")\n .post(requestBody.toRequestBody(\"application/json\".toMediaTypeOrNull()))\n .build()\n }\n\n /**\n * Makes an API call with the provided prompt and processes the DeepSeek JSON response.\n */\n override fun makeApiCall(prompt: String): String {\n logger.info(\"Prompt:\\n$prompt\")\n val request = buildRequest(prompt)\n\n client.newCall(request).execute().use { response ->\n if (!response.isSuccessful) {\n val errorBody = response.body?.string()\n throw Exception(\"Error in API call: ${response.code} - ${response.message}\\nResponse: $errorBody\")\n }\n\n val responseBody = response.body?.string() ?: return \"Error: empty response\"\n\n try {\n val json = JSONObject(responseBody)\n logger.debug(\"Raw API response: {}\", responseBody)\n\n if (!json.has(\"choices\") || json.getJSONArray(\"choices\").length() == 0) {\n return \"Error: No choices found in the API response\"\n }\n\n val choices = json.getJSONArray(\"choices\")\n val firstChoice = choices.getJSONObject(0)\n\n if (!firstChoice.has(\"message\")) {\n return \"Error: No message found in the API response\"\n }\n\n val message = firstChoice.getJSONObject(\"message\")\n\n if (!message.has(\"content\") || message.isNull(\"content\")) {\n return \"Error: No content found in the API response\"\n }\n\n return message.getString(\"content\").trim()\n\n } catch (e: JSONException) {\n val truncatedResponse = if (responseBody.length > 200) \"${responseBody.substring(0, 200)}...\" else responseBody\n logger.error(\"Error parsing JSON response: ${e.message}\")\n logger.error(\"Response body (truncated): $truncatedResponse\")\n throw Exception(\"Failed to parse API response: ${e.message}\", e)\n }\n }\n }\n}\n"}, "5ad15f53dc485983e7d5bd4977eba8a8600c77f7": {"t": 1785755815.0280352, "n": 4075, "h": "9701f1dd0e2e76da", "c": "package dam\n\nimport okhttp3.MediaType.Companion.toMediaTypeOrNull\nimport okhttp3.Request\nimport okhttp3.RequestBody.Companion.toRequestBody\nimport org.json.JSONArray\nimport org.json.JSONException\nimport org.json.JSONObject\nimport java.util.*\n\n/**\n * AIAssistantDeepSeek class provides an interface to communicate with Nvidia's DeepSeek AI models.\n * This class handles API authentication, request formatting, response parsing, and error handling.\n */\nclass AIAssistantDeepSeek(override val properties: Properties) : AIAssistant {\n\n override fun getSystem() = \"DEEPSEEK\"\n override val apiKeyName = \"NVIDIA_DEEPSEEK_API_KEY\"\n override var model = \"deepseek-ai/deepseek-v4-pro\"\n\n override val client: okhttp3.OkHttpClient\n get() = okhttp3.OkHttpClient.Builder()\n .readTimeout(180, java.util.concurrent.TimeUnit.SECONDS)\n .connectTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n .writeTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n .callTimeout(210, java.util.concurrent.TimeUnit.SECONDS)\n .build()\n\n /**\n * Constructs and formats a structured request from the given input prompt.\n */\n override fun buildRequest(prompt: String): Request {\n val messagesArray = JSONArray().put(\n JSONObject()\n .put(\"role\", \"user\")\n .put(\"content\", prompt)\n )\n\n val requestBody = JSONObject()\n .put(\"model\", model)\n .put(\"messages\", messagesArray)\n .put(\"max_tokens\", 16384)\n .put(\"temperature\", 1.0)\n .put(\"top_p\", 0.95)\n .put(\"stream\", false)\n .put(\"chat_template_kwargs\", JSONObject().put(\"thinking\", false))\n .toString()\n\n return Request.Builder()\n .url(\"https://integrate.api.nvidia.com/v1/chat/completions\")\n .addHeader(\"Authorization\", \"Bearer $apiKey\")\n .addHeader(\"Accept\", \"application/json\")\n .addHeader(\"Content-Type\", \"application/json\")\n .post(requestBody.toRequestBody(\"application/json\".toMediaTypeOrNull()))\n .build()\n }\n\n /**\n * Makes an API call with the provided prompt and processes the DeepSeek JSON response.\n */\n override fun makeApiCall(prompt: String): String {\n logger.info(\"Prompt:\\n$prompt\")\n val request = buildRequest(prompt)\n\n client.newCall(request).execute().use { response ->\n if (!response.isSuccessful) {\n val errorBody = response.body?.string()\n throw Exception(\"Error in API call: ${response.code} - ${response.message}\\nResponse: $errorBody\")\n }\n\n val responseBody = response.body?.string() ?: return \"Error: empty response\"\n\n try {\n val json = JSONObject(responseBody)\n logger.debug(\"Raw API response: {}\", responseBody)\n\n if (!json.has(\"choices\") || json.getJSONArray(\"choices\").length() == 0) {\n return \"Error: No choices found in the API response\"\n }\n\n val choices = json.getJSONArray(\"choices\")\n val firstChoice = choices.getJSONObject(0)\n\n if (!firstChoice.has(\"message\")) {\n return \"Error: No message found in the API response\"\n }\n\n val message = firstChoice.getJSONObject(\"message\")\n\n if (!message.has(\"content\") || message.isNull(\"content\")) {\n return \"Error: No content found in the API response\"\n }\n\n return message.getString(\"content\").trim()\n\n } catch (e: JSONException) {\n val truncatedResponse = if (responseBody.length > 200) \"${responseBody.substring(0, 200)}...\" else responseBody\n logger.error(\"Error parsing JSON response: ${e.message}\")\n logger.error(\"Response body (truncated): $truncatedResponse\")\n throw Exception(\"Failed to parse API response: ${e.message}\", e)\n }\n }\n }\n}\n"}, "fe0ea6dd24baf593cd4b84541e214178c32232ea": {"t": 1785755816.6061714, "n": 4006, "h": "9d259c98227b760b", "c": "package dam\n\nimport okhttp3.MediaType.Companion.toMediaTypeOrNull\nimport okhttp3.Request\nimport okhttp3.RequestBody.Companion.toRequestBody\nimport org.json.JSONArray\nimport org.json.JSONException\nimport org.json.JSONObject\nimport java.util.*\n\n/**\n * AIAssistantDeepSeek class provides an interface to communicate with Nvidia's DeepSeek AI models.\n * This class handles API authentication, request formatting, response parsing, and error handling.\n */\nclass AIAssistantDeepSeek(override val properties: Properties) : AIAssistant {\n\n override fun getSystem() = \"DEEPSEEK\"\n override val apiKeyName = \"NVIDIA_DEEPSEEK_API_KEY\"\n override var model = \"deepseek-ai/deepseek-v4-pro\"\n\n override val client: okhttp3.OkHttpClient\n get() = okhttp3.OkHttpClient.Builder()\n .readTimeout(120, java.util.concurrent.TimeUnit.SECONDS)\n .connectTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n .writeTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n .build()\n\n /**\n * Constructs and formats a structured request from the given input prompt.\n */\n override fun buildRequest(prompt: String): Request {\n val messagesArray = JSONArray().put(\n JSONObject()\n .put(\"role\", \"user\")\n .put(\"content\", prompt)\n )\n\n val requestBody = JSONObject()\n .put(\"model\", model)\n .put(\"messages\", messagesArray)\n .put(\"max_tokens\", 16384)\n .put(\"temperature\", 1.0)\n .put(\"top_p\", 0.95)\n .put(\"stream\", false)\n .put(\"chat_template_kwargs\", JSONObject().put(\"thinking\", false))\n .toString()\n\n return Request.Builder()\n .url(\"https://integrate.api.nvidia.com/v1/chat/completions\")\n .addHeader(\"Authorization\", \"Bearer $apiKey\")\n .addHeader(\"Accept\", \"application/json\")\n .addHeader(\"Content-Type\", \"application/json\")\n .post(requestBody.toRequestBody(\"application/json\".toMediaTypeOrNull()))\n .build()\n }\n\n /**\n * Makes an API call with the provided prompt and processes the DeepSeek JSON response.\n */\n override fun makeApiCall(prompt: String): String {\n logger.info(\"Prompt:\\n$prompt\")\n val request = buildRequest(prompt)\n\n client.newCall(request).execute().use { response ->\n if (!response.isSuccessful) {\n val errorBody = response.body?.string()\n throw Exception(\"Error in API call: ${response.code} - ${response.message}\\nResponse: $errorBody\")\n }\n\n val responseBody = response.body?.string() ?: return \"Error: empty response\"\n\n try {\n val json = JSONObject(responseBody)\n logger.debug(\"Raw API response: {}\", responseBody)\n\n if (!json.has(\"choices\") || json.getJSONArray(\"choices\").length() == 0) {\n return \"Error: No choices found in the API response\"\n }\n\n val choices = json.getJSONArray(\"choices\")\n val firstChoice = choices.getJSONObject(0)\n\n if (!firstChoice.has(\"message\")) {\n return \"Error: No message found in the API response\"\n }\n\n val message = firstChoice.getJSONObject(\"message\")\n\n if (!message.has(\"content\") || message.isNull(\"content\")) {\n return \"Error: No content found in the API response\"\n }\n\n return message.getString(\"content\").trim()\n\n } catch (e: JSONException) {\n val truncatedResponse = if (responseBody.length > 200) \"${responseBody.substring(0, 200)}...\" else responseBody\n logger.error(\"Error parsing JSON response: ${e.message}\")\n logger.error(\"Response body (truncated): $truncatedResponse\")\n throw Exception(\"Failed to parse API response: ${e.message}\", e)\n }\n }\n }\n}\n"}}}}