Skip to content

Commit

Permalink
finalise v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjien committed May 5, 2024
1 parent 897fa64 commit 49275f2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 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
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jenkins-log-reader",
"displayName": "jenkins-log-reader",
"description": "read jenkins log, analyse with local AI.",
"version": "0.1.4",
"version": "0.1.5",
"engines": {
"vscode": "^1.89.0"
},
Expand Down Expand Up @@ -134,7 +134,11 @@
"axios": "^1.6.8",
"crypto": "^1.0.1",
"husky": "^9.0.11",
"marked": "^12.0.2",
"openai": "^4.40.2",
"showdown": "^2.1.0"
"react-markdown": "^9.0.1",
"rehype-highlight": "^7.0.0",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0"
}
}

0 comments on commit 49275f2

Please sign in to comment.