Skip to content

Commit

Permalink
Merge pull request #2 from huangjien/webView
Browse files Browse the repository at this point in the history
Web view
  • Loading branch information
huangjien authored May 5, 2024
2 parents dde51e6 + 49275f2 commit 0262ed9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
29 changes: 19 additions & 10 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const vscode = require('vscode');
const axios = require('axios');
const OpenAI = require('openai')
const Showdown = require('showdown')
const marked = require('marked')

async function fetchJenkinsLog(jobUrl, username, apiToken) {
const auth = Buffer.from(`${username}:${apiToken}`).toString('base64');
Expand Down Expand Up @@ -39,8 +39,6 @@ function activate(context) {
'jenkins-log-reader.readJenkinsLog',
async () => {

const converter = new Showdown.Converter();

// You could prompt the user for these or use configuration settings

const logSize = getConfig('jenkins-log-reader.jenkinsLogSize');
Expand Down Expand Up @@ -94,10 +92,10 @@ function activate(context) {
'Jenkins Log',
vscode.ViewColumn.One
);
panel.webview.html = `<br/><details><summary>${jobUrl}</summary><pre>${escapeHtml(info)}</pre></details><br/>`;
panel.webview.html = `<br/><details><summary>Jenkins Job Build: ${jobUrl}</summary><pre>${escapeHtml(info)}</pre></details><br/>`;
const promptString = prompt.replace('$PROMPT$', info);
// analyse with local AI
const longRunTask = aiAnalyse(localAi, model, promptString, panel, converter, temperature, maxToken);
const longRunTask = aiAnalyse(localAi, model, promptString, panel, temperature, maxToken);
showStatusBarProgress(longRunTask);
}
}).catch((err) => {
Expand All @@ -112,6 +110,16 @@ function activate(context) {
context.subscriptions.push(disposable);
}

function removePrefixUsingRegex(text, prefix) {
// Create a dynamic regex based on the prefix
let regex = new RegExp("^" + escapeRegex(prefix));
return text.replace(regex, '');
}

function escapeRegex(string) {
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); // Escapes regex special characters
}

function getConfig(config_key) {
return vscode.workspace
.getConfiguration()
Expand All @@ -132,7 +140,7 @@ function showStatusBarProgress(task) {
}


async function aiAnalyse(localAi, model, promptString, panel, converter, temperature, maxToken) {
async function aiAnalyse(localAi, model, promptString, panel, temperature, maxToken) {
await localAi.chat.completions.create({
model: model,
messages: [{ role: 'assistant', content: promptString }],
Expand All @@ -143,10 +151,11 @@ async function aiAnalyse(localAi, model, promptString, panel, converter, tempera
}).then(data => {
const evalContent = JSON.parse(data);
console.log(evalContent)
const infomation = evalContent.choices[0]['message']['content'];
console.log(infomation);
const html = converter.makeHtml(infomation);
panel.webview.html = `<div>` + panel.webview.html + `<details><summary>${model}</summary><div>${html}</div></details></div>`;
const information = evalContent.choices[0]['message']['content'];
console.log(information);
const html = marked.parse(removePrefixUsingRegex(information, '```'))

panel.webview.html = `<div>` + panel.webview.html + `<details><summary>AI Analysis (Model: ${model})</summary><div>${html} </div></details></div>`;
}).catch((err) => {
vscode.window.showErrorMessage(err.message);
});
Expand Down
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "jenkins-log-reader",
"displayName": "jenkins-log-reader",
"description": "read jenkins log, analyse with local AI.",
"version": "0.1.3",
"version": "0.1.5",
"engines": {
"vscode": "^1.88.0"
"vscode": "^1.89.0"
},
"main": "./extension.js",
"author": "huangjien <[email protected]>",
Expand Down Expand Up @@ -119,11 +119,11 @@
},
"devDependencies": {
"@types/mocha": "^10.0.6",
"@types/node": "18.x",
"@types/vscode": "^1.88.0",
"@vscode/test-cli": "^0.0.8",
"@types/node": "^20.12.8",
"@types/vscode": "^1.89.0",
"@vscode/test-cli": "^0.0.9",
"@vscode/test-electron": "^2.3.9",
"eslint": "^8.57.0",
"eslint": "^9.2.0",
"prettier": "^3.2.5",
"ts-loader": "^9.5.1",
"typescript": "^5.4.5",
Expand All @@ -134,7 +134,11 @@
"axios": "^1.6.8",
"crypto": "^1.0.1",
"husky": "^9.0.11",
"openai": "^4.40.0",
"showdown": "^2.1.0"
"marked": "^12.0.2",
"openai": "^4.40.2",
"react-markdown": "^9.0.1",
"rehype-highlight": "^7.0.0",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0"
}
}

0 comments on commit 0262ed9

Please sign in to comment.