Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/alekseykondus_vscode-extension.json
T

1 line
86 KiB
JSON

{"repo": "alekseykondus/vscode-extension", "files": {"vscode-extension/aiService.js": {"922c0e1b5f46f93555fb2f4d39d54e0d3c737893": {"t": 1785745531.5914366, "n": 13268, "h": "59d0e47ceb12ae01", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nconst { encoding_for_model } = require(\"tiktoken\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\nconst Anthropic = require('@anthropic-ai/sdk');\nconst { GoogleGenerativeAI } = require(\"@google/generative-ai\");\n\nconst { logInfo, logError, logDebug } = require('./logger');\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nconst deepseek = new OpenAI({\n baseURL: 'https://api.deepseek.com',\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\n\nconst grok = new OpenAI({\n baseURL: \"https://api.x.ai/v1\",\n apiKey: process.env.XAI_API_KEY\n});\n\nconst anthropic = new Anthropic({\n apiKey: process.env.CLOUDE_API_KEY,\n});\n\nconst gemini = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);\n\nconst vscode = require(\"vscode\");\nfunction cleanCodeFromMarkdown(response, language = vscode.window.activeTextEditor?.document.languageId) {\n logDebug(\"Cleaning markdown from response\");\n try {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n let cleanedCode = match && match[1] ? match[1].trim() : response.trim();\n\n logDebug(match && match[1] ? \"Markdown code block found and cleaned\" : \"No markdown code blocks found\");\n\n const unsafePatterns = {\n javascript: /\\b(eval|Function|setTimeout\\s*\\(\\s*['\"][^'\"]+['\"]|setInterval\\s*\\(\\s*['\"][^'\"]+['\"]|XMLHttpRequest|fetch|location\\.href|document\\.write)\\b/,\n python: /\\b(eval|exec|compile|os\\.system|subprocess\\.run|eval)\\b/,\n java: /\\b(javax\\.script\\.ScriptEngine|java\\.lang\\.reflect\\.Method\\.invoke|Runtime\\.getRuntime|ProcessBuilder)\\b/,\n default: /\\b(eval|exec|new\\s+Function|setTimeout|setInterval|XMLHttpRequest|fetch|location\\.href|document\\.write)\\b/\n };\n\n const pattern = unsafePatterns[language] || unsafePatterns.default;\n if (pattern.test(cleanedCode)) {\n logError(`Unsafe constructs detected in ${language} code: ${cleanedCode}`);\n throw new Error(`Code contains unsafe constructs (e.g., eval, exec, or similar) and cannot be processed for safety reasons.`);\n }\n\n logDebug(\"Code passed safety check\");\n return cleanedCode;\n } catch (error) {\n logError(`Markdown cleaning or safety check failed: ${error.message}`);\n return \"Markdown cleaning or safety check failed, code contains unsafe constructs (e.g., eval, exec, or similar) and cannot be processed for safety reasons.\";\n }\n}\n\nasync function getChatGPTResponse(code, prompt, currentModel) {\n logDebug(`Starting ChatGPT request with model ${currentModel}`);\n try {\n const startTime = Date.now();\n const response = await openai.chat.completions.create({\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const duration = Date.now() - startTime;\n logInfo(`ChatGPT response received in ${duration}ms`);\n\n const rawContent = response.choices[0].message.content;\n logDebug(`Raw response length: ${rawContent.length} chars`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`ChatGPT request failed: ${error.message}`);\n if (error.response) logDebug(\"Error details:\", error.response.data);\n return \"Error retrieving documentation.\";\n }\n}\n\nasync function getGrokResponse(code, prompt, currentModel) {\n logDebug(\"Starting Grok API request\");\n try {\n const startTime = Date.now();\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const duration = Date.now() - startTime;\n logInfo(`Grok response received in ${duration}ms`);\n\n const rawContent = response.data.choices[0].message.content;\n logDebug(`Raw Grok response: ${rawContent.substring(0, 100)}...`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`Grok request failed: ${error.message}`);\n if (error.response) logDebug(\"Error response:\", error.response.data);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getGrokResponse_2(code, prompt, currentModel) {\n try {\n const completion = await grok.chat.completions.create({\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7\n });\n const rawContent = completion.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getDeepseekResponse(code, prompt) {\n try {\n const response = await deepseek.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const rawContent = response.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Deepseek API:\", error);\n return \"Error retrieving response from Deepseek.\";\n }\n}\n\nasync function getClaudeResponse(code, prompt, model = \"claude-3-7-sonnet-20250219\") {\n try {\n const response = await anthropic.messages.create({\n model: model,\n max_tokens: 4096,\n messages: [\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n \n const rawContent = response.content[0].text;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Claude API:\", error);\n return \"Error retrieving response from Claude.\";\n }\n}\n\nasync function getGeminiResponse(code, prompt, modelName = \"gemini-1.5-pro-latest\") {\n logDebug(\"Starting Gemini API request\");\n try {\n const model = gemini.getGenerativeModel({ model: modelName });\n const result = await model.generateContent(`${prompt}\\n\\n${code}`);\n const response = await result.response;\n const text = response.text();\n logDebug(`Raw Gemini response: ${text.substring(0, 100)}...`);\n return cleanCodeFromMarkdown(text);\n } catch (error) {\n logError(`Gemini request failed: ${error.message}`);\n if (error.response) logDebug(\"Error response:\", error.response.data);\n return \"Error retrieving response from Gemini.\";\n }\n}\n\nfunction checkModelByTokenCount(code, currentModel, vscode) {\n logDebug(\"Checking model by token count\");\n try {\n const enc = encoding_for_model(\"gpt-3.5-turbo\");\n const tokenCount = enc.encode(code).length;\n enc.free();\n\n logInfo(`Token count: ${tokenCount}, current model: ${currentModel}`);\n\n const GPT_3_5_TURBO_LIMIT = 4000;\n const GPT_3_5_TURBO_16K_LIMIT = 16000;\n const DEEPSEEK_LIMIT = 8000;\n const GEMINI_2_FLASH_LIMIT = 8000;\n const CLAUDE_LIMIT = 20000;\n const GROK_LIMIT = 60000;\n const GEMINI_2_5_PRO_LIMIT = 65500;\n\n \n if (tokenCount <= GPT_3_5_TURBO_LIMIT) {\n logDebug(`Within GPT-3.5-Turbo limit (${tokenCount} <= ${GPT_3_5_TURBO_LIMIT})`);\n logInfo(`Keeping current model: ${currentModel}`);\n return currentModel;\n }\n\n if (tokenCount <= GPT_3_5_TURBO_16K_LIMIT && currentModel === \"gpt-3.5-turbo\") {\n logInfo(`Switching to GPT-3.5-16K (${tokenCount} > ${GPT_3_5_TURBO_LIMIT})`);\n vscode.window.showInformationMessage(\"The model was changed to gpt-3.5-turbo-16k due to the large length of the selected code.\");\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (tokenCount <= DEEPSEEK_LIMIT) {\n if (currentModel !== \"deepseek-chat\") {\n logInfo(`Switching to Deepseek (${tokenCount} > ${GPT_3_5_TURBO_16K_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to deepseek-chat for processing.\");\n }\n return \"deepseek-chat\";\n }\n\n if (tokenCount <= GEMINI_2_FLASH_LIMIT) {\n if (currentModel != \"gemini-1.5-pro-latest\" && currentModel != \"gemini-2.0-flash\") {\n logInfo(`Switching to Gemini (${tokenCount} > ${DEEPSEEK_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to gemini-1.5-pro-latest for processing.\");\n }\n return \"gemini-1.5-pro-latest\";\n }\n\n if (tokenCount <= CLAUDE_LIMIT) {\n if (currentModel != \"claude-3-7-sonnet-20250219\" && currentModel != \"claude-3-5-haiku-20241022\") {\n logInfo(`Switching to Claude (${tokenCount} > ${DEEPSEEK_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to claude-3-7-sonnet for processing.\");\n }\n return \"claude-3-7-sonnet-20250219\";\n }\n\n if (tokenCount <= GROK_LIMIT) {\n if (currentModel != \"grok-2-latest\" && currentModel != \"grok-3-latest\") {\n logInfo(`Switching to Grok (${tokenCount} > ${CLAUDE_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to grok-3-latest for processing.\");\n }\n return \"grok-3-latest\";\n }\n\n if (tokenCount <= GEMINI_2_5_PRO_LIMIT) {\n if (currentModel != \"gemini-2.5-pro-exp-03-25\") {\n logInfo(`Switching to Grok (${tokenCount} > ${CLAUDE_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to gemini-2.5-pro-exp-03-25 for processing.\");\n }\n return \"gemini-2.5-pro-exp-03-25\";\n }\n\n \n logError(`Code too large! Tokens: ${tokenCount}, Max: ${GEMINI_2_5_PRO_LIMIT}`);\n vscode.window.showErrorMessage(`The selected code is too large (${tokenCount} tokens). Maximum supported: ${GEMINI_2_5_PRO_LIMIT} tokens.`);\n return currentModel;\n } catch (error) {\n logError(`Token counting failed: ${error.message}`);\n return currentModel;\n }\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n logInfo(`Starting AI request with model: ${currentModel}`);\n try {\n let response;\n const startTime = Date.now();\n \n switch(currentModel) {\n case \"gpt-4-turbo\":\n case \"gpt-3.5-turbo\":\n case \"gpt-3.5-turbo-16k\":\n case \"gpt-4o\":\n response = await getChatGPTResponse(code, prompt, currentModel);\n break;\n case \"grok-2-latest\":\n case \"grok-3-latest\":\n response = await getGrokResponse(code, prompt, currentModel);\n break;\n case \"deepseek-chat\":\n response = await getDeepseekResponse(code, prompt);\n break;\n case \"claude-3-7-sonnet-20250219\":\n case \"claude-3-5-haiku-20241022\":\n response = await getClaudeResponse(code, prompt, currentModel);\n break;\n case \"gemini-2.0-flash\":\n case \"gemini-1.5-pro-latest\":\n case \"gemini-2.5-pro-exp-03-25\":\n response = await getGeminiResponse(code, prompt, currentModel);\n break;\n default:\n logError(`Unknown model requested: ${currentModel}`);\n return \"Error: Unknown model.\";\n }\n\n const duration = Date.now() - startTime;\n logInfo(`AI request completed in ${duration}ms`);\n logDebug(`Final processed code length: ${response.length} chars`);\n \n return response;\n } catch (error) {\n logError(`AI request failed: ${error.message}`);\n if (error.stack) logDebug(error.stack);\n return \"Error processing request. Check logs for details.\";\n }\n}\n\nmodule.exports = { getAIResponse, checkModelByTokenCount, cleanCodeFromMarkdown };"}, "9c4dc8f8883f320dd746511aaf95497abfa7d4d8": {"t": 1785753925.6934903, "n": 12083, "h": "f3305cee03cc7f03", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nconst { encoding_for_model } = require(\"tiktoken\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\nconst Anthropic = require('@anthropic-ai/sdk');\nconst { GoogleGenerativeAI } = require(\"@google/generative-ai\");\n\nconst { logInfo, logError, logDebug } = require('./logger');\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nconst deepseek = new OpenAI({\n baseURL: 'https://api.deepseek.com',\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\n\nconst grok = new OpenAI({\n baseURL: \"https://api.x.ai/v1\",\n apiKey: process.env.XAI_API_KEY\n});\n\nconst anthropic = new Anthropic({\n apiKey: process.env.CLOUDE_API_KEY,\n});\n\nconst gemini = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);\n\nfunction cleanCodeFromMarkdown(response) {\n logDebug(\"Cleaning markdown from response\");\n try {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n \n if (match && match[1]) {\n logDebug(\"Markdown code block found and cleaned\");\n return match[1].trim();\n }\n logDebug(\"No markdown code blocks found\");\n return response.trim();\n } catch (error) {\n logError(`Markdown cleaning failed: ${error.message}`);\n return response.trim();\n }\n}\n\nasync function getChatGPTResponse(code, prompt, currentModel) {\n logDebug(`Starting ChatGPT request with model ${currentModel}`);\n try {\n const startTime = Date.now();\n const response = await openai.chat.completions.create({\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const duration = Date.now() - startTime;\n logInfo(`ChatGPT response received in ${duration}ms`);\n\n const rawContent = response.choices[0].message.content;\n logDebug(`Raw response length: ${rawContent.length} chars`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`ChatGPT request failed: ${error.message}`);\n if (error.response) logDebug(\"Error details:\", error.response.data);\n return \"Error retrieving documentation.\";\n }\n}\n\nasync function getGrokResponse(code, prompt, currentModel) {\n logDebug(\"Starting Grok API request\");\n try {\n const startTime = Date.now();\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const duration = Date.now() - startTime;\n logInfo(`Grok response received in ${duration}ms`);\n\n const rawContent = response.data.choices[0].message.content;\n logDebug(`Raw Grok response: ${rawContent.substring(0, 100)}...`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`Grok request failed: ${error.message}`);\n if (error.response) logDebug(\"Error response:\", error.response.data);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getGrokResponse_2(code, prompt, currentModel) {\n try {\n const completion = await grok.chat.completions.create({\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7\n });\n const rawContent = completion.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getDeepseekResponse(code, prompt) {\n try {\n const response = await deepseek.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const rawContent = response.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Deepseek API:\", error);\n return \"Error retrieving response from Deepseek.\";\n }\n}\n\nasync function getClaudeResponse(code, prompt, model = \"claude-3-7-sonnet-20250219\") {\n try {\n const response = await anthropic.messages.create({\n model: model,\n max_tokens: 4096,\n messages: [\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n \n const rawContent = response.content[0].text;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Claude API:\", error);\n return \"Error retrieving response from Claude.\";\n }\n}\n\nasync function getGeminiResponse(code, prompt, modelName = \"gemini-1.5-pro-latest\") {\n logDebug(\"Starting Gemini API request\");\n try {\n const model = gemini.getGenerativeModel({ model: modelName });\n const result = await model.generateContent(`${prompt}\\n\\n${code}`);\n const response = await result.response;\n const text = response.text();\n logDebug(`Raw Gemini response: ${text.substring(0, 100)}...`);\n return cleanCodeFromMarkdown(text);\n } catch (error) {\n logError(`Gemini request failed: ${error.message}`);\n if (error.response) logDebug(\"Error response:\", error.response.data);\n return \"Error retrieving response from Gemini.\";\n }\n}\n\nfunction checkModelByTokenCount(code, currentModel, vscode) {\n logDebug(\"Checking model by token count\");\n try {\n const enc = encoding_for_model(\"gpt-3.5-turbo\");\n const tokenCount = enc.encode(code).length;\n enc.free();\n\n logInfo(`Token count: ${tokenCount}, current model: ${currentModel}`);\n\n const GPT_3_5_TURBO_LIMIT = 4000;\n const GPT_3_5_TURBO_16K_LIMIT = 16000;\n const DEEPSEEK_LIMIT = 8000;\n const GEMINI_2_FLASH_LIMIT = 8000;\n const CLAUDE_LIMIT = 20000;\n const GROK_LIMIT = 60000;\n const GEMINI_2_5_PRO_LIMIT = 65500;\n\n \n if (tokenCount <= GPT_3_5_TURBO_LIMIT) {\n logDebug(`Within GPT-3.5-Turbo limit (${tokenCount} <= ${GPT_3_5_TURBO_LIMIT})`);\n logInfo(`Keeping current model: ${currentModel}`);\n return currentModel;\n }\n\n if (tokenCount <= GPT_3_5_TURBO_16K_LIMIT && currentModel === \"gpt-3.5-turbo\") {\n logInfo(`Switching to GPT-3.5-16K (${tokenCount} > ${GPT_3_5_TURBO_LIMIT})`);\n vscode.window.showInformationMessage(\"The model was changed to gpt-3.5-turbo-16k due to the large length of the selected code.\");\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (tokenCount <= DEEPSEEK_LIMIT) {\n if (currentModel !== \"deepseek-chat\") {\n logInfo(`Switching to Deepseek (${tokenCount} > ${GPT_3_5_TURBO_16K_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to deepseek-chat for processing.\");\n }\n return \"deepseek-chat\";\n }\n\n if (tokenCount <= GEMINI_2_FLASH_LIMIT) {\n if (currentModel != \"gemini-1.5-pro-latest\" && currentModel != \"gemini-2.0-flash\") {\n logInfo(`Switching to Gemini (${tokenCount} > ${DEEPSEEK_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to gemini-1.5-pro-latest for processing.\");\n }\n return \"gemini-1.5-pro-latest\";\n }\n\n if (tokenCount <= CLAUDE_LIMIT) {\n if (currentModel != \"claude-3-7-sonnet-20250219\" && currentModel != \"claude-3-5-haiku-20241022\") {\n logInfo(`Switching to Claude (${tokenCount} > ${DEEPSEEK_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to claude-3-7-sonnet for processing.\");\n }\n return \"claude-3-7-sonnet-20250219\";\n }\n\n if (tokenCount <= GROK_LIMIT) {\n if (currentModel != \"grok-2-latest\" && currentModel != \"grok-3-latest\") {\n logInfo(`Switching to Grok (${tokenCount} > ${CLAUDE_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to grok-3-latest for processing.\");\n }\n return \"grok-3-latest\";\n }\n\n if (tokenCount <= GEMINI_2_5_PRO_LIMIT) {\n if (currentModel != \"gemini-2.5-pro-exp-03-25\") {\n logInfo(`Switching to Grok (${tokenCount} > ${CLAUDE_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to gemini-2.5-pro-exp-03-25 for processing.\");\n }\n return \"gemini-2.5-pro-exp-03-25\";\n }\n\n \n logError(`Code too large! Tokens: ${tokenCount}, Max: ${GEMINI_2_5_PRO_LIMIT}`);\n vscode.window.showErrorMessage(`The selected code is too large (${tokenCount} tokens). Maximum supported: ${GEMINI_2_5_PRO_LIMIT} tokens.`);\n return currentModel;\n } catch (error) {\n logError(`Token counting failed: ${error.message}`);\n return currentModel;\n }\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n logInfo(`Starting AI request with model: ${currentModel}`);\n try {\n let response;\n const startTime = Date.now();\n \n switch(currentModel) {\n case \"gpt-4-turbo\":\n case \"gpt-3.5-turbo\":\n case \"gpt-3.5-turbo-16k\":\n case \"gpt-4o\":\n response = await getChatGPTResponse(code, prompt, currentModel);\n break;\n case \"grok-2-latest\":\n case \"grok-3-latest\":\n response = await getGrokResponse(code, prompt, currentModel);\n break;\n case \"deepseek-chat\":\n response = await getDeepseekResponse(code, prompt);\n break;\n case \"claude-3-7-sonnet-20250219\":\n case \"claude-3-5-haiku-20241022\":\n response = await getClaudeResponse(code, prompt, currentModel);\n break;\n case \"gemini-2.0-flash\":\n case \"gemini-1.5-pro-latest\":\n case \"gemini-2.5-pro-exp-03-25\":\n response = await getGeminiResponse(code, prompt, currentModel);\n break;\n default:\n logError(`Unknown model requested: ${currentModel}`);\n return \"Error: Unknown model.\";\n }\n\n const duration = Date.now() - startTime;\n logInfo(`AI request completed in ${duration}ms`);\n logDebug(`Final processed code length: ${response.length} chars`);\n \n return response;\n } catch (error) {\n logError(`AI request failed: ${error.message}`);\n if (error.stack) logDebug(error.stack);\n return \"Error processing request. Check logs for details.\";\n }\n}\n\nmodule.exports = { getAIResponse, checkModelByTokenCount, cleanCodeFromMarkdown };"}, "6d368e3718a578640f0a0b6173b09d107b76d575": {"t": 1785753927.097061, "n": 11384, "h": "5a36ac1a21a130a5", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nconst { encoding_for_model } = require(\"tiktoken\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\nconst Anthropic = require('@anthropic-ai/sdk');\nconst { GoogleGenerativeAI } = require(\"@google/generative-ai\");\n\nconst { logInfo, logError, logDebug } = require('./logger');\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nconst deepseek = new OpenAI({\n baseURL: 'https://api.deepseek.com',\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\n\nconst grok = new OpenAI({\n baseURL: \"https://api.x.ai/v1\",\n apiKey: process.env.XAI_API_KEY\n});\n\nconst anthropic = new Anthropic({\n apiKey: process.env.CLOUDE_API_KEY,\n});\n\nconst gemini = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);\n\nfunction cleanCodeFromMarkdown(response) {\n logDebug(\"Cleaning markdown from response\");\n try {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n \n if (match && match[1]) {\n logDebug(\"Markdown code block found and cleaned\");\n return match[1].trim();\n }\n logDebug(\"No markdown code blocks found\");\n return response.trim();\n } catch (error) {\n logError(`Markdown cleaning failed: ${error.message}`);\n return response.trim();\n }\n}\n\nasync function getChatGPTResponse(code, prompt, currentModel) {\n logDebug(`Starting ChatGPT request with model ${currentModel}`);\n try {\n const startTime = Date.now();\n const response = await openai.chat.completions.create({\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const duration = Date.now() - startTime;\n logInfo(`ChatGPT response received in ${duration}ms`);\n\n const rawContent = response.choices[0].message.content;\n logDebug(`Raw response length: ${rawContent.length} chars`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`ChatGPT request failed: ${error.message}`);\n if (error.response) logDebug(\"Error details:\", error.response.data);\n return \"Error retrieving documentation.\";\n }\n}\n\nasync function getGrokResponse(code, prompt) {\n logDebug(\"Starting Grok API request\");\n try {\n const startTime = Date.now();\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const duration = Date.now() - startTime;\n logInfo(`Grok response received in ${duration}ms`);\n\n const rawContent = response.data.choices[0].message.content;\n logDebug(`Raw Grok response: ${rawContent.substring(0, 100)}...`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`Grok request failed: ${error.message}`);\n if (error.response) logDebug(\"Error response:\", error.response.data);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getGrokResponse_2(code, prompt) {\n try {\n const completion = await grok.chat.completions.create({\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7\n });\n const rawContent = completion.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getDeepseekResponse(code, prompt) {\n try {\n const response = await deepseek.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const rawContent = response.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Deepseek API:\", error);\n return \"Error retrieving response from Deepseek.\";\n }\n}\n\nasync function getClaudeResponse(code, prompt, model = \"claude-3-7-sonnet-20250219\") {\n try {\n const response = await anthropic.messages.create({\n model: model,\n max_tokens: 4096,\n messages: [\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n \n const rawContent = response.content[0].text;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Claude API:\", error);\n return \"Error retrieving response from Claude.\";\n }\n}\n\nasync function getGeminiResponse(code, prompt, modelName = \"gemini-1.5-pro-latest\") {\n logDebug(\"Starting Gemini API request\");\n try {\n const model = gemini.getGenerativeModel({ model: modelName });\n const result = await model.generateContent(`${prompt}\\n\\n${code}`);\n const response = await result.response;\n const text = response.text();\n logDebug(`Raw Gemini response: ${text.substring(0, 100)}...`);\n return cleanCodeFromMarkdown(text);\n } catch (error) {\n logError(`Gemini request failed: ${error.message}`);\n if (error.response) logDebug(\"Error response:\", error.response.data);\n return \"Error retrieving response from Gemini.\";\n }\n}\n\nfunction checkModelByTokenCount(code, currentModel, vscode) {\n logDebug(\"Checking model by token count\");\n try {\n const enc = encoding_for_model(\"gpt-3.5-turbo\");\n const tokenCount = enc.encode(code).length;\n enc.free();\n\n logInfo(`Token count: ${tokenCount}, current model: ${currentModel}`);\n\n const GPT_3_5_TURBO_LIMIT = 4000;\n const GPT_3_5_TURBO_16K_LIMIT = 16000;\n const DEEPSEEK_LIMIT = 8000;\n const GEMINI_LIMIT = 8000;\n const CLAUDE_LIMIT = 20000;\n const GROK_LIMIT = 64000;\n\n \n if (tokenCount <= GPT_3_5_TURBO_LIMIT) {\n logDebug(`Within GPT-3.5-Turbo limit (${tokenCount} <= ${GPT_3_5_TURBO_LIMIT})`);\n logInfo(`Keeping current model: ${currentModel}`);\n return currentModel;\n }\n\n if (tokenCount <= GPT_3_5_TURBO_16K_LIMIT && currentModel === \"gpt-3.5-turbo\") {\n logInfo(`Switching to GPT-3.5-16K (${tokenCount} > ${GPT_3_5_TURBO_LIMIT})`);\n vscode.window.showInformationMessage(\"The model was changed to gpt-3.5-turbo-16k due to the large length of the selected code.\");\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (tokenCount <= DEEPSEEK_LIMIT) {\n if (currentModel !== \"deepseek-chat\") {\n logInfo(`Switching to Deepseek (${tokenCount} > ${GPT_3_5_TURBO_16K_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to deepseek-chat for processing.\");\n }\n return \"deepseek-chat\";\n }\n\n if (tokenCount <= GEMINI_LIMIT) {\n if (currentModel != \"gemini-1.5-pro-latest\" && currentModel != \"gemini-2.0-flash\") {\n logInfo(`Switching to Gemini (${tokenCount} > ${DEEPSEEK_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to gemini-1.5-pro-latest for processing.\");\n }\n return \"gemini-1.5-pro-latest\";\n }\n\n if (tokenCount <= CLAUDE_LIMIT) {\n if (currentModel != \"claude-3-7-sonnet-20250219\" && currentModel != \"claude-3-5-haiku-20241022\") {\n logInfo(`Switching to Claude (${tokenCount} > ${DEEPSEEK_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to claude-3-7-sonnet for processing.\");\n }\n return \"claude-3-7-sonnet-20250219\";\n }\n\n if (tokenCount <= GROK_LIMIT) {\n if (currentModel != \"grok-2-latest\") {\n logInfo(`Switching to Grok (${tokenCount} > ${CLAUDE_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to grok-2-latest for processing.\");\n }\n return \"grok-2-latest\";\n }\n logError(`Code too large! Tokens: ${tokenCount}, Max: ${GROK_LIMIT}`);\n vscode.window.showErrorMessage(`The selected code is too large (${tokenCount} tokens). Maximum supported: ${GROK_LIMIT} tokens.`);\n return currentModel;\n } catch (error) {\n logError(`Token counting failed: ${error.message}`);\n return currentModel;\n }\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n logInfo(`Starting AI request with model: ${currentModel}`);\n try {\n let response;\n const startTime = Date.now();\n \n switch(currentModel) {\n case \"gpt-3.5-turbo\":\n case \"gpt-3.5-turbo-16k\":\n response = await getChatGPTResponse(code, prompt, currentModel);\n break;\n case \"grok-2-latest\":\n response = await getGrokResponse(code, prompt);\n break;\n case \"deepseek-chat\":\n response = await getDeepseekResponse(code, prompt);\n break;\n case \"claude-3-7-sonnet-20250219\":\n case \"claude-3-5-haiku-20241022\":\n response = await getClaudeResponse(code, prompt, currentModel);\n break;\n case \"gemini-2.0-flash\":\n case \"gemini-1.5-pro-latest\":\n response = await getGeminiResponse(code, prompt, currentModel);\n break;\n default:\n logError(`Unknown model requested: ${currentModel}`);\n return \"Error: Unknown model.\";\n }\n\n const duration = Date.now() - startTime;\n logInfo(`AI request completed in ${duration}ms`);\n logDebug(`Final processed code length: ${response.length} chars`);\n \n return response;\n } catch (error) {\n logError(`AI request failed: ${error.message}`);\n if (error.stack) logDebug(error.stack);\n return \"Error processing request. Check logs for details.\";\n }\n}\n\nmodule.exports = { getAIResponse, checkModelByTokenCount, cleanCodeFromMarkdown };"}, "f0f2e71e447af2d0d3849806172d1beaf6b2a970": {"t": 1785753928.566111, "n": 11361, "h": "790d71e976a8b9b8", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nconst { encoding_for_model } = require(\"tiktoken\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\nconst Anthropic = require('@anthropic-ai/sdk');\nconst { GoogleGenerativeAI } = require(\"@google/generative-ai\");\n\nconst { logInfo, logError, logDebug } = require('./logger');\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nconst deepseek = new OpenAI({\n baseURL: 'https://api.deepseek.com',\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\n\nconst grok = new OpenAI({\n baseURL: \"https://api.x.ai/v1\",\n apiKey: process.env.XAI_API_KEY\n});\n\nconst anthropic = new Anthropic({\n apiKey: process.env.CLOUDE_API_KEY,\n});\n\nconst gemini = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);\n\nfunction cleanCodeFromMarkdown(response) {\n logDebug(\"Cleaning markdown from response\");\n try {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n \n if (match && match[1]) {\n logDebug(\"Markdown code block found and cleaned\");\n return match[1].trim();\n }\n logDebug(\"No markdown code blocks found\");\n return response.trim();\n } catch (error) {\n logError(`Markdown cleaning failed: ${error.message}`);\n return response.trim();\n }\n}\n\nasync function getChatGPTResponse(code, prompt, currentModel) {\n logDebug(`Starting ChatGPT request with model ${currentModel}`);\n try {\n const startTime = Date.now();\n const response = await openai.chat.completions.create({\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const duration = Date.now() - startTime;\n logInfo(`ChatGPT response received in ${duration}ms`);\n\n const rawContent = response.choices[0].message.content;\n logDebug(`Raw response length: ${rawContent.length} chars`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`ChatGPT request failed: ${error.message}`);\n if (error.response) logDebug(\"Error details:\", error.response.data);\n return \"Error retrieving documentation.\";\n }\n}\n\nasync function getGrokResponse(code, prompt) {\n logDebug(\"Starting Grok API request\");\n try {\n const startTime = Date.now();\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const duration = Date.now() - startTime;\n logInfo(`Grok response received in ${duration}ms`);\n\n const rawContent = response.data.choices[0].message.content;\n logDebug(`Raw Grok response: ${rawContent.substring(0, 100)}...`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`Grok request failed: ${error.message}`);\n if (error.response) logDebug(\"Error response:\", error.response.data);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getGrokResponse_2(code, prompt) {\n try {\n const completion = await grok.chat.completions.create({\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7\n });\n const rawContent = completion.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getDeepseekResponse(code, prompt) {\n try {\n const response = await deepseek.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const rawContent = response.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Deepseek API:\", error);\n return \"Error retrieving response from Deepseek.\";\n }\n}\n\nasync function getClaudeResponse(code, prompt, model = \"claude-3-7-sonnet-20250219\") {\n try {\n const response = await anthropic.messages.create({\n model: model,\n max_tokens: 4096,\n messages: [\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n \n const rawContent = response.content[0].text;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Claude API:\", error);\n return \"Error retrieving response from Claude.\";\n }\n}\n\nasync function getGeminiResponse(code, prompt, modelName = \"gemini-1.5-pro-latest\") {\n logDebug(\"Starting Gemini API request\");\n try {\n const model = gemini.getGenerativeModel({ model: modelName });\n const result = await model.generateContent(`${prompt}\\n\\n${code}`);\n const response = await result.response;\n const text = response.text();\n logDebug(`Raw Gemini response: ${text.substring(0, 100)}...`);\n return cleanCodeFromMarkdown(text);\n } catch (error) {\n logError(`Gemini request failed: ${error.message}`);\n if (error.response) logDebug(\"Error response:\", error.response.data);\n return \"Error retrieving response from Gemini.\";\n }\n}\n\nfunction checkModelByTokenCount(code, currentModel, vscode) {\n logDebug(\"Checking model by token count\");\n try {\n const enc = encoding_for_model(\"gpt-3.5-turbo\");\n const tokenCount = enc.encode(code).length;\n enc.free();\n\n logInfo(`Token count: ${tokenCount}, current model: ${currentModel}`);\n\n const GPT_3_5_TURBO_LIMIT = 4000;\n const GPT_3_5_TURBO_16K_LIMIT = 16000;\n const DEEPSEEK_LIMIT = 8000;\n const GEMINI_LIMIT = 8000;\n const CLAUDE_LIMIT = 20000;\n const GROK_LIMIT = 64000;\n\n \n if (tokenCount <= GPT_3_5_TURBO_LIMIT) {\n logDebug(`Within GPT-3.5-Turbo limit (${tokenCount} <= ${GPT_3_5_TURBO_LIMIT})`);\n logInfo(`Keeping current model: ${currentModel}`);\n return currentModel;\n }\n\n if (tokenCount <= GPT_3_5_TURBO_16K_LIMIT && currentModel === \"gpt-3.5-turbo\") {\n logInfo(`Switching to GPT-3.5-16K (${tokenCount} > ${GPT_3_5_TURBO_LIMIT})`);\n vscode.window.showInformationMessage(\"The model was changed to gpt-3.5-turbo-16k due to the large length of the selected code.\");\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (tokenCount <= DEEPSEEK_LIMIT) {\n if (currentModel !== \"deepseek-chat\") {\n logInfo(`Switching to Deepseek (${tokenCount} > ${GPT_3_5_TURBO_16K_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to deepseek-chat for processing.\");\n }\n return \"deepseek-chat\";\n }\n\n if (tokenCount <= GEMINI_LIMIT) {\n if (currentModel != \"gemini-1.5-pro-latest\" && currentModel != \"gemini-2.0-flash\") {\n logInfo(`Switching to Gemini (${tokenCount} > ${DEEPSEEK_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to gemini-1.5-pro-latest for processing.\");\n }\n return \"gemini-1.5-pro-latest\";\n }\n\n if (tokenCount <= CLAUDE_LIMIT) {\n if (currentModel != \"claude-3-7-sonnet-20250219\" && currentModel != \"claude-3-5-haiku-20241022\") {\n logInfo(`Switching to Claude (${tokenCount} > ${DEEPSEEK_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to claude-3-7-sonnet for processing.\");\n }\n return \"claude-3-7-sonnet-20250219\";\n }\n\n if (tokenCount <= GROK_LIMIT) {\n if (currentModel != \"grok-2-latest\") {\n logInfo(`Switching to Grok (${tokenCount} > ${CLAUDE_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to grok-2-latest for processing.\");\n }\n return \"grok-2-latest\";\n }\n logError(`Code too large! Tokens: ${tokenCount}, Max: ${GROK_LIMIT}`);\n vscode.window.showErrorMessage(`The selected code is too large (${tokenCount} tokens). Maximum supported: ${GROK_LIMIT} tokens.`);\n return currentModel;\n } catch (error) {\n logError(`Token counting failed: ${error.message}`);\n return currentModel;\n }\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n logInfo(`Starting AI request with model: ${currentModel}`);\n try {\n let response;\n const startTime = Date.now();\n \n switch(currentModel) {\n case \"gpt-3.5-turbo\":\n case \"gpt-3.5-turbo-16k\":\n response = await getChatGPTResponse(code, prompt, currentModel);\n break;\n case \"grok-2-latest\":\n response = await getGrokResponse(code, prompt);\n break;\n case \"deepseek-chat\":\n response = await getDeepseekResponse(code, prompt);\n break;\n case \"claude-3-7-sonnet-20250219\":\n case \"claude-3-5-haiku-20241022\":\n response = await getClaudeResponse(code, prompt, currentModel);\n break;\n case \"gemini-2.0-flash\":\n case \"gemini-1.5-pro-latest\":\n response = await getGeminiResponse(code, prompt, currentModel);\n break;\n default:\n logError(`Unknown model requested: ${currentModel}`);\n return \"Error: Unknown model.\";\n }\n\n const duration = Date.now() - startTime;\n logInfo(`AI request completed in ${duration}ms`);\n logDebug(`Final processed code length: ${response.length} chars`);\n \n return response;\n } catch (error) {\n logError(`AI request failed: ${error.message}`);\n if (error.stack) logDebug(error.stack);\n return \"Error processing request. Check logs for details.\";\n }\n}\n\nmodule.exports = { getAIResponse, checkModelByTokenCount };"}, "9b9579e0401209b10f4b8f2065effde496bd3a07": {"t": 1785753929.7909753, "n": 9870, "h": "0985c567c568ceb7", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nconst { encoding_for_model } = require(\"tiktoken\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\nconst Anthropic = require('@anthropic-ai/sdk');\n\nconst { logInfo, logError, logDebug } = require('./logger');\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nconst deepseek = new OpenAI({\n baseURL: 'https://api.deepseek.com',\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\n\nconst grok = new OpenAI({\n baseURL: \"https://api.x.ai/v1\",\n apiKey: process.env.XAI_API_KEY\n});\n\nconst anthropic = new Anthropic({\n apiKey: process.env.CLOUDE_API_KEY,\n});\n\nfunction cleanCodeFromMarkdown(response) {\n logDebug(\"Cleaning markdown from response\");\n try {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n \n if (match && match[1]) {\n logDebug(\"Markdown code block found and cleaned\");\n return match[1].trim();\n }\n logDebug(\"No markdown code blocks found\");\n return response.trim();\n } catch (error) {\n logError(`Markdown cleaning failed: ${error.message}`);\n return response.trim();\n }\n}\n\nasync function getChatGPTResponse(code, prompt, currentModel) {\n logDebug(`Starting ChatGPT request with model ${currentModel}`);\n try {\n const startTime = Date.now();\n const response = await openai.chat.completions.create({\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const duration = Date.now() - startTime;\n logInfo(`ChatGPT response received in ${duration}ms`);\n\n const rawContent = response.choices[0].message.content;\n logDebug(`Raw response length: ${rawContent.length} chars`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`ChatGPT request failed: ${error.message}`);\n if (error.response) logDebug(\"Error details:\", error.response.data);\n return \"Error retrieving documentation.\";\n }\n}\n\nasync function getGrokResponse(code, prompt) {\n logDebug(\"Starting Grok API request\");\n try {\n const startTime = Date.now();\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const duration = Date.now() - startTime;\n logInfo(`Grok response received in ${duration}ms`);\n\n const rawContent = response.data.choices[0].message.content;\n logDebug(`Raw Grok response: ${rawContent.substring(0, 100)}...`);\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n logError(`Grok request failed: ${error.message}`);\n if (error.response) logDebug(\"Error response:\", error.response.data);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getGrokResponse_2(code, prompt) {\n try {\n const completion = await grok.chat.completions.create({\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7\n });\n const rawContent = completion.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getDeepseekResponse(code, prompt) {\n try {\n const response = await deepseek.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const rawContent = response.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Deepseek API:\", error);\n return \"Error retrieving response from Deepseek.\";\n }\n}\n\nasync function getClaudeResponse(code, prompt, model = \"claude-3-7-sonnet-20250219\") {\n try {\n const response = await anthropic.messages.create({\n model: model,\n max_tokens: 4096,\n messages: [\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n \n const rawContent = response.content[0].text;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Claude API:\", error);\n return \"Error retrieving response from Claude.\";\n }\n}\n\nfunction checkModelByTokenCount(code, currentModel, vscode) {\n logDebug(\"Checking model by token count\");\n try {\n const enc = encoding_for_model(\"gpt-3.5-turbo\");\n const tokenCount = enc.encode(code).length;\n enc.free();\n\n logInfo(`Token count: ${tokenCount}, current model: ${currentModel}`);\n\n const GPT_3_5_TURBO_LIMIT = 4000;\n const GPT_3_5_TURBO_16K_LIMIT = 16000;\n const DEEPSEEK_LIMIT = 8000;\n const CLAUDE_LIMIT = 20000;\n const GROK_LIMIT = 64000;\n\n \n if (tokenCount <= GPT_3_5_TURBO_LIMIT) {\n logDebug(`Within GPT-3.5-Turbo limit (${tokenCount} <= ${GPT_3_5_TURBO_LIMIT})`);\n logInfo(`Keeping current model: ${currentModel}`);\n return currentModel;\n }\n\n if (tokenCount <= GPT_3_5_TURBO_16K_LIMIT && currentModel === \"gpt-3.5-turbo\") {\n logInfo(`Switching to GPT-3.5-16K (${tokenCount} > ${GPT_3_5_TURBO_LIMIT})`);\n vscode.window.showInformationMessage(\"The model was changed to gpt-3.5-turbo-16k due to the large length of the selected code.\");\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (tokenCount <= DEEPSEEK_LIMIT) {\n if (currentModel !== \"deepseek-chat\") {\n logInfo(`Switching to Deepseek (${tokenCount} > ${GPT_3_5_TURBO_16K_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to deepseek-chat for processing.\");\n }\n return \"deepseek-chat\";\n }\n\n if (tokenCount <= CLAUDE_LIMIT) {\n if (currentModel != \"claude-3-7-sonnet-20250219\" && currentModel != \"claude-3-5-haiku-20241022\") {\n logInfo(`Switching to Claude (${tokenCount} > ${DEEPSEEK_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to claude-3-7-sonnet for processing.\");\n }\n return \"claude-3-7-sonnet-20250219\";\n }\n\n if (tokenCount <= GROK_LIMIT) {\n if (currentModel != \"grok-2-latest\") {\n logInfo(`Switching to Grok (${tokenCount} > ${CLAUDE_LIMIT})`);\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to grok-2-latest for processing.\");\n }\n return \"grok-2-latest\";\n }\n logError(`Code too large! Tokens: ${tokenCount}, Max: ${GROK_LIMIT}`);\n vscode.window.showErrorMessage(`The selected code is too large (${tokenCount} tokens). Maximum supported: ${GROK_LIMIT} tokens.`);\n return currentModel;\n } catch (error) {\n logError(`Token counting failed: ${error.message}`);\n return currentModel;\n }\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n logInfo(`Starting AI request with model: ${currentModel}`);\n try {\n let response;\n const startTime = Date.now();\n \n switch(currentModel) {\n case \"gpt-3.5-turbo\":\n case \"gpt-3.5-turbo-16k\":\n response = await getChatGPTResponse(code, prompt, currentModel);\n break;\n case \"grok-2-latest\":\n response = await getGrokResponse(code, prompt);\n break;\n case \"deepseek-chat\":\n response = await getDeepseekResponse(code, prompt);\n break;\n case \"claude-3-7-sonnet-20250219\":\n case \"claude-3-5-haiku-20241022\":\n response = await getClaudeResponse(code, prompt, currentModel);\n break;\n default:\n logError(`Unknown model requested: ${currentModel}`);\n return \"Error: Unknown model.\";\n }\n\n const duration = Date.now() - startTime;\n logInfo(`AI request completed in ${duration}ms`);\n logDebug(`Final processed code length: ${response.length} chars`);\n \n return response;\n } catch (error) {\n logError(`AI request failed: ${error.message}`);\n if (error.stack) logDebug(error.stack);\n return \"Error processing request. Check logs for details.\";\n }\n}\n\nmodule.exports = { getAIResponse, checkModelByTokenCount };"}, "359764787fe4d7ff1f523d0f8e2a49ffb76e05d9": {"t": 1785753931.783812, "n": 7301, "h": "d01dae2f52fef4a4", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nconst { encoding_for_model } = require(\"tiktoken\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\nconst Anthropic = require('@anthropic-ai/sdk');\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nconst deepseek = new OpenAI({\n baseURL: 'https://api.deepseek.com',\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\n\nconst grok = new OpenAI({\n baseURL: \"https://api.x.ai/v1\",\n apiKey: process.env.XAI_API_KEY\n});\n\nconst anthropic = new Anthropic({\n apiKey: process.env.CLOUDE_API_KEY,\n});\n\nfunction cleanCodeFromMarkdown(response) {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n \n if (match && match[1]) {\n return match[1].trim();\n }\n return response.trim();\n}\n\nasync function getChatGPTResponse(code, prompt, currentModel) {\n try {\n const response = await openai.chat.completions.create({\n model: currentModel,\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const rawContent = response.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting OpenAI:\", error);\n return \"Error retrieving documentation.\";\n }\n}\n\nasync function getGrokResponse(code, prompt) {\n try {\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const rawContent = response.data.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getGrokResponse_2(code, prompt) {\n try {\n const completion = await grok.chat.completions.create({\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7\n });\n const rawContent = completion.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\n\nasync function getDeepseekResponse(code, prompt) {\n try {\n const response = await deepseek.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [\n { role: \"system\", content: \"You are an expert in working with code and an experienced developer.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const rawContent = response.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Deepseek API:\", error);\n return \"Error retrieving response from Deepseek.\";\n }\n}\n\nasync function getClaudeResponse(code, prompt, model = \"claude-3-7-sonnet-20250219\") {\n try {\n const response = await anthropic.messages.create({\n model: model,\n max_tokens: 4096,\n messages: [\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n \n const rawContent = response.content[0].text;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Claude API:\", error);\n return \"Error retrieving response from Claude.\";\n }\n}\n\nfunction checkModelByTokenCount(code, currentModel, vscode) {\n const enc = encoding_for_model(\"gpt-3.5-turbo\");\n const tokenCount = enc.encode(code).length;\n enc.free();\n const GPT_3_5_TURBO_LIMIT = 4000;\n const GPT_3_5_TURBO_16K_LIMIT = 16000;\n const DEEPSEEK_LIMIT = 8000;\n const CLAUDE_LIMIT = 20000;\n const GROK_LIMIT = 64000;\n\n console.log(\"tokenCount\", tokenCount);\n console.log(\"currentModel\", currentModel);\n if (tokenCount <= GPT_3_5_TURBO_LIMIT) {\n return currentModel;\n }\n\n if (tokenCount <= GPT_3_5_TURBO_16K_LIMIT && currentModel === \"gpt-3.5-turbo\") {\n vscode.window.showInformationMessage(\"The model was changed to gpt-3.5-turbo-16k due to the large length of the selected code.\");\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (tokenCount <= DEEPSEEK_LIMIT) {\n if (currentModel !== \"deepseek-chat\") {\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to deepseek-chat for processing.\");\n }\n return \"deepseek-chat\";\n }\n\n if (tokenCount <= CLAUDE_LIMIT) {\n if (currentModel != \"claude-3-7-sonnet-20250219\" && currentModel != \"claude-3-5-haiku-20241022\") {\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to claude-3-7-sonnet for processing.\");\n }\n return \"claude-3-7-sonnet-20250219\";\n }\n\n if (tokenCount <= GROK_LIMIT) {\n if (currentModel != \"grok-2-latest\") {\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to grok-2-latest for processing.\");\n }\n return \"grok-2-latest\";\n }\n\n vscode.window.showErrorMessage(`The selected code is too large (${tokenCount} tokens). Maximum supported: ${GROK_LIMIT} tokens.`);\n return currentModel;\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n console.log(\"Model that will be used:\", currentModel);\n if (currentModel === \"gpt-3.5-turbo\" || currentModel === \"gpt-3.5-turbo-16k\") {\n return await getChatGPTResponse(code, prompt, currentModel);\n } \n else if (currentModel === \"grok-2-latest\") {\n return await getGrokResponse(code, prompt);\n } \n else if (currentModel === \"deepseek-chat\") {\n return await getDeepseekResponse(code, prompt);\n }\n else if (currentModel === \"claude-3-7-sonnet-20250219\" || currentModel === \"claude-3-5-haiku-20241022\") {\n return await getClaudeResponse(code, prompt, currentModel);\n }\n else {\n console.error(\"Невідома модель:\", currentModel);\n return \"Error: Unknown model.\";\n }\n}\n\nmodule.exports = { getAIResponse, checkModelByTokenCount };"}, "5ae36589fc81750b06fcaaebade7470334af3d90": {"t": 1785753933.156134, "n": 5724, "h": "1230b9440ba1ac4a", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nconst { encoding_for_model } = require(\"tiktoken\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nconst deepseek = new OpenAI({\n baseURL: 'https://api.deepseek.com',\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\n\nconst grok = new OpenAI({\n baseURL: \"https://api.x.ai/v1\",\n apiKey: process.env.XAI_API_KEY\n});\n\nasync function getChatGPTResponse(code, prompt, currentModel) {\n try {\n const response = await openai.chat.completions.create({\n model: currentModel,\n messages: [{ role: \"user\", content: `${prompt}\\n\\n${code}` }],\n temperature: 0.7,\n });\n return response.choices[0].message.content;\n } catch (error) {\n console.error(\"Error requesting OpenAI:\", error);\n return \"Error retrieving documentation.\";\n }\n}\n\nfunction cleanCodeFromMarkdown(response) {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n \n if (match && match[1]) {\n return match[1].trim();\n }\n return response.trim();\n}\n\n\nasync function getGrokResponse(code, prompt) {\n try {\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are Grok, created by xAI.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const rawContent = response.data.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getGrokResponse_2(code, prompt) {\n try {\n const completion = await grok.chat.completions.create({\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are Grok, created by xAI.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7\n });\n const rawContent = completion.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\n\nasync function getDeepseekResponse(code, prompt) {\n try {\n const response = await deepseek.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [\n { role: \"system\", content: \"You are a helpful assistant.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const rawContent = response.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Deepseek API:\", error);\n return \"Error retrieving response from Deepseek.\";\n }\n}\n\nfunction checkModelByTokenCount(code, currentModel, vscode) {\n const enc = encoding_for_model(\"gpt-3.5-turbo\");\n const tokenCount = enc.encode(code).length;\n enc.free();\n const GPT_3_5_TURBO_LIMIT = 4000;\n const GPT_3_5_TURBO_16K_LIMIT = 16000;\n const DEEPSEEK_LIMIT = 8000;\n const GROK_LIMIT = 64000;\n console.log(\"tokenCount\", tokenCount);\n console.log(\"currentModel\", currentModel);\n if (tokenCount <= GPT_3_5_TURBO_LIMIT) {\n return currentModel;\n }\n\n if (tokenCount <= GPT_3_5_TURBO_16K_LIMIT && currentModel === \"gpt-3.5-turbo\") {\n vscode.window.showInformationMessage(\"The model was changed to gpt-3.5-turbo-16k due to the large length of the selected code.\");\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (tokenCount <= DEEPSEEK_LIMIT) {\n if (currentModel !== \"deepseek-chat\") {\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to deepseek-chat for processing.\");\n }\n return \"deepseek-chat\";\n }\n\n if (tokenCount <= GROK_LIMIT) {\n if (currentModel != \"grok-2-latest\") {\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to grok-2-latest for processing.\");\n }\n console.log(\"return grok-2-latest\");\n return \"grok-2-latest\";\n }\n\n vscode.window.showErrorMessage(`The selected code is too large (${tokenCount} tokens). Maximum supported: ${GROK_LIMIT} tokens.`);\n return currentModel;\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n console.log(\"Model that will be used:\", currentModel);\n if (currentModel === \"gpt-3.5-turbo\" || currentModel === \"gpt-3.5-turbo-16k\") {\n return await getChatGPTResponse(code, prompt, currentModel);\n } \n else if (currentModel === \"grok-2-latest\") {\n return await getGrokResponse(code, prompt);\n } \n else if (currentModel === \"deepseek-chat\") {\n return await getDeepseekResponse(code, prompt);\n } \n else {\n console.error(\"Невідома модель:\", currentModel);\n return \"Error: Unknown model.\";\n }\n}\n\nmodule.exports = { getAIResponse, checkModelByTokenCount };"}, "39cf1d18c6697d6f6e5598644a92a14c9f8c84b8": {"t": 1785753934.3965096, "n": 5725, "h": "bcb920b303f65d7f", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nconst { encoding_for_model } = require(\"tiktoken\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nconst deepseek = new OpenAI({\n baseURL: 'https://api.deepseek.com',\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\n\nconst grok = new OpenAI({\n baseURL: \"https://api.x.ai/v1\",\n apiKey: process.env.XAI_API_KEY\n});\n\nasync function getChatGPTResponse(code, prompt, currentModel) {\n try {\n const response = await openai.chat.completions.create({\n model: currentModel,\n messages: [{ role: \"user\", content: `${prompt}\\n\\n${code}` }],\n temperature: 0.7,\n });\n return response.choices[0].message.content;\n } catch (error) {\n console.error(\"Error requesting OpenAI:\", error);\n return \"Error retrieving documentation.\";\n }\n}\n\nfunction cleanCodeFromMarkdown(response) {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n \n if (match && match[1]) {\n return match[1].trim();\n }\n return response.trim();\n}\n\n\nasync function getGrokResponse(code, prompt) {\n try {\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are Grok, created by xAI.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const rawContent = response.data.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getGrokResponse_2(code, prompt) {\n try {\n const completion = await grok.chat.completions.create({\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are Grok, created by xAI.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7\n });\n const rawContent = completion.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\n\nasync function getDeepseekResponse(code, prompt) {\n try {\n const response = await deepseek.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [\n { role: \"system\", content: \"You are a helpful assistant.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n });\n const rawContent = response.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Error requesting Deepseek API:\", error);\n return \"Error retrieving response from Deepseek.\";\n }\n}\n\nfunction checkModelByTokenCount(code, currentModel, vscode) {\n const enc = encoding_for_model(\"gpt-3.5-turbo\");\n const tokenCount = enc.encode(code).length;\n enc.free();\n const GPT_3_5_TURBO_LIMIT = 4000;\n const GPT_3_5_TURBO_16K_LIMIT = 16000;\n const DEEPSEEK_LIMIT = 8000;\n const GROK_LIMIT = 64000;\n console.log(\"tokenCount\", tokenCount);\n console.log(\"currentModel\", currentModel);\n if (tokenCount <= GPT_3_5_TURBO_LIMIT) {\n return currentModel;\n }\n\n if (tokenCount <= GPT_3_5_TURBO_16K_LIMIT && currentModel === \"gpt-3.5-turbo\") {\n vscode.window.showInformationMessage(\"The model was changed to gpt-3.5-turbo-16k due to the large length of the selected code.\");\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (tokenCount <= DEEPSEEK_LIMIT) {\n if (currentModel !== \"deepseek-chat\") {\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to deepseek-chat for processing.\");\n }\n return \"deepseek-chat\";\n }\n\n if (tokenCount <= GROK_LIMIT) {\n if (currentModel != \"grok-2-latest\") {\n vscode.window.showInformationMessage(\"The code exceeds limits. Switching to grok-2-latest for processing.\");\n }\n console.log(\"return grok-2-latest\");\n return \"grok-2-latest\";\n }\n\n vscode.window.showErrorMessage(`The selected code is too large (${tokenCount} tokens). Maximum supported: ${GROK_LIMIT} tokens.`);\n return currentModel;\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n console.log(\"Model that will be used:\", currentModel);\n if (currentModel === \"gpt-3.5-turbo\" || currentModel === \"gpt-3.5-turbo-16k\") {\n return await getChatGPTResponse(code, prompt, currentModel);\n } \n else if (currentModel === \"grok-2-latest\") {\n return await getGrokResponse(code, prompt);\n } \n else if (currentModel === \"deepseek-chat\") {\n return await getDeepseekResponse(code, prompt);\n } \n else {\n console.error(\"Невідома модель:\", currentModel);\n return \"Error: Unknown model.\";\n }\n}\n\n\nmodule.exports = { getAIResponse, checkModelByTokenCount };"}, "d686a62b045d5ec15ea0b5c8d54ec0141e7c3cba": {"t": 1785753936.723176, "n": 3742, "h": "4d1d221eb0cc2bb2", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nconst { encoding_for_model } = require(\"tiktoken\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nasync function getChatGPTResponse(code, prompt, currentModel) {\n try {\n const response = await openai.chat.completions.create({\n model: currentModel,\n messages: [{ role: \"user\", content: `${prompt}\\n\\n${code}` }],\n temperature: 0.7,\n });\n return response.choices[0].message.content;\n } catch (error) {\n console.error(\"Error requesting OpenAI:\", error);\n return \"Error retrieving documentation.\";\n }\n}\n\nfunction cleanCodeFromMarkdown(response) {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n \n if (match && match[1]) {\n return match[1].trim();\n }\n return response.trim();\n}\n\n\nasync function getGrokResponse(code, prompt) {\n try {\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are Grok, created by xAI.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const rawContent = response.data.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nfunction checkModelByTokenCount(code, currentModel, vscode) {\n const enc = encoding_for_model(\"gpt-3.5-turbo\");\n const tokenCount = enc.encode(code).length;\n enc.free();\n const GPT_3_5_TURBO_LIMIT = 4000;\n const GPT_3_5_TURBO_16K_LIMIT = 16000;\n const GROK_LIMIT = 64000;\n console.log(\"tokenCount\", tokenCount);\n console.log(\"currentModel\", currentModel);\n if (tokenCount <= GPT_3_5_TURBO_LIMIT) {\n return currentModel;\n }\n\n if (tokenCount <= GPT_3_5_TURBO_16K_LIMIT && currentModel === \"gpt-3.5-turbo\") {\n vscode.window.showInformationMessage(\"The model was changed to gpt-3.5-turbo-16k due to the large length of the selected code.\");\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (tokenCount <= GROK_LIMIT) {\n if (currentModel != \"grok-2-latest\") {\n vscode.window.showInformationMessage(\"The code exceeds GPT limits. Switching to grok-2-latest for processing.\");\n }\n console.log(\"return grok-2-latest\");\n return \"grok-2-latest\";\n }\n\n vscode.window.showErrorMessage(`The selected code is too large (${tokenCount} tokens). Maximum supported: ${GROK_LIMIT} tokens.`);\n return currentModel;\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n console.log(\"Model that will be used:\", currentModel);\n if (currentModel === \"gpt-3.5-turbo\" || currentModel === \"gpt-3.5-turbo-16k\") {\n return await getChatGPTResponse(code, prompt, currentModel);\n } else if (currentModel === \"grok-2-latest\") {\n return await getGrokResponse(code, prompt);\n } else {\n console.error(\"Невідома модель:\", currentModel);\n return \"Error: Unknown model.\";\n }\n}\n\n\nmodule.exports = { getAIResponse, checkModelByTokenCount };"}, "7e9b966f768d73bd4a2be77bbe1c1ee917a31ca2": {"t": 1785753938.0975645, "n": 2408, "h": "9afafe1220ff0a5d", "c": "const OpenAI = require(\"openai\");\nconst axios = require(\"axios\");\nrequire(\"dotenv\").config({ path: __dirname + \"/.env\" });\n\nconst openai = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY, \n});\n\nasync function getChatGPTResponse(code, prompt) {\n try {\n const response = await openai.chat.completions.create({\n model: \"gpt-3.5-turbo\",\n messages: [{ role: \"user\", content: `${prompt}\\n\\n${code}` }],\n temperature: 0.7,\n });\n return response.choices[0].message.content;\n } catch (error) {\n console.error(\"Error requesting OpenAI:\", error);\n return \"Error retrieving documentation.\";\n }\n}\n\nfunction cleanCodeFromMarkdown(response) {\n const markdownRegex = /```(?:\\w+)?\\n([\\s\\S]*?)\\n```/;\n const match = response.match(markdownRegex);\n \n if (match && match[1]) {\n return match[1].trim();\n }\n return response.trim();\n}\n\n\nasync function getGrokResponse(code, prompt) {\n try {\n const response = await axios.post(\n \"https://api.x.ai/v1/chat/completions\",\n {\n model: \"grok-2-latest\",\n messages: [\n { role: \"system\", content: \"You are Grok, created by xAI.\" },\n { role: \"user\", content: `${prompt}\\n\\n${code}` }\n ],\n temperature: 0.7,\n stream: false\n },\n {\n headers: {\n \"Authorization\": `Bearer ${process.env.XAI_API_KEY}`,\n \"Content-Type\": \"application/json\"\n }\n }\n );\n const rawContent = response.data.choices[0].message.content;\n return cleanCodeFromMarkdown(rawContent);\n } catch (error) {\n console.error(\"Помилка при запиті до Grok API:\", error.response ? error.response.data : error.message);\n return \"Error retrieving response from Grok.\";\n }\n}\n\nasync function getAIResponse(code, prompt, currentModel) {\n console.log(\"Model that will be used:\", currentModel);\n if (currentModel === \"gpt-3.5-turbo\") {\n return await getChatGPTResponse(code, prompt);\n } else if (currentModel === \"grok-2-latest\") {\n return await getGrokResponse(code, prompt);\n } else {\n console.error(\"Невідома модель:\", currentModel);\n return \"Error: Unknown model.\";\n }\n}\n\nmodule.exports = { getAIResponse };"}}}}