Skip to content

Commit

Permalink
make the framework
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjien committed Nov 8, 2024
1 parent 01b78d6 commit 6779178
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 10 deletions.
29 changes: 28 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jenkins-log-reader",
"displayName": "AI Log Reader",
"description": "Read jenkins log, analyse with local AI.",
"version": "0.8.9",
"version": "0.8.10",
"engines": {
"vscode": "^1.95.0"
},
Expand Down Expand Up @@ -141,10 +141,25 @@
],
"menus": {
"explorer/context": [
{
"when": "explorerResourceIsFolder",
"command": "jenkins-log-reader.readImages",
"group": "navigation"
},
{
"when": "explorerResourceIsFolder",
"command": "jenkins-log-reader.readVideos",
"group": "navigation"
},
{
"when": "resourceExtname =~ /\\.(png|jpg|jpeg|gif|bmp|svg)$/i",
"command": "jenkins-log-reader.readImage",
"group": "navigation"
},
{
"when": "resourceExtname =~ /\\.(mp4|3pg|mov|ogg|avi|mpeg)$/i",
"command": "jenkins-log-reader.readVideo",
"group": "navigation"
}
],
"editor/context": [
Expand All @@ -156,6 +171,18 @@
]
},
"commands": [
{
"command": "jenkins-log-reader.readVideos",
"title": "Analyse Videos"
},
{
"command": "jenkins-log-reader.readVideo",
"title": "Analyse Video"
},
{
"command": "jenkins-log-reader.readImages",
"title": "Analyse Images"
},
{
"command": "jenkins-log-reader.readImage",
"title": "Analyse Image"
Expand Down
110 changes: 108 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ExtensionContext, window, commands, workspace, Range, Uri } from "vscode";
import { JenkinsPanel, showStatusBarProgress } from "./JenkinsPanel";
import JenkinsSettings from "./JenkinsSettings";
import { existsSync, fstat, mkdirSync } from "fs";
import { existsSync, mkdirSync } from "fs";
import { LogReaderResultWebViewProvider } from "./LogReaderResultWebViewProvider";
import { LogReaderSettingWebViewProvider } from "./LogReaderSettingWebViewProvider";
import { GroovyCodeFormat } from "./GroovyFormat";
import * as fs from "fs";
import { getAnalysis, getImageAnalysis } from "./getInfoFromJenkins";
import { getImageAnalysis } from "./getInfoFromJenkins";

export function activate(context: ExtensionContext) {
const storagePath = context.globalStorageUri.fsPath;
Expand Down Expand Up @@ -76,6 +76,9 @@ export function activate(context: ExtensionContext) {

registerCommandOfShowResult(context, resultViewProvider);
registerCommandOfReadImage(context, resultViewProvider, imageAiModel, imagePrompt);
registerCommandOfReadImages(context, resultViewProvider, imageAiModel, imagePrompt);
registerCommandOfReadVideo(context, resultViewProvider, imageAiModel, videoPrompt);
registerCommandOfReadVideos(context, resultViewProvider, imageAiModel, videoPrompt);
registerCommandOfFormatGrooby(context);
}

Expand All @@ -98,6 +101,109 @@ function registerCommandOfFormatGrooby(context: ExtensionContext) {
);
}

function registerCommandOfReadImages(
context: ExtensionContext,
provider: LogReaderResultWebViewProvider,
imageAiModel: string,
imagePrompt: string
) {
commands.registerCommand("jenkins-log-reader.readImages", async (uri: Uri) => {
// get image file
// turn it into base64
// send to AI (llama3.2-vision)
// show result in result view
if (uri) {
// uri need to be a folder, then we check files one by one, only handle image files(check extension)
const dirItems = fs.readdir(uri.fsPath, (err, files) => {
if (err) {
console.error(err);
} else {
files
.filter((file) => {
file.toLowerCase().endsWith(".png") ||
file.toLowerCase().endsWith(".jpg") ||
file.toLowerCase().endsWith(".jpeg") ||
file.toLowerCase().endsWith(".gif") ||
file.toLowerCase().endsWith(".bmp") ||
file.toLowerCase().endsWith(".webp") ||
file.toLowerCase().endsWith(".tiff") ||
file.toLowerCase().endsWith(".svg");
})
.map(async (file) => {
console.log("file: " + file);
});
// const image_uri = uri;
// const base64String = fs.readFileSync(image_uri.fsPath).toString("base64");
// const long_run_task = analyse_image(base64String, provider, imageAiModel, imagePrompt);
// showStatusBarProgress(long_run_task, "Analysing the image...");
}
});
}
});
}

function registerCommandOfReadVideos(
context: ExtensionContext,
provider: LogReaderResultWebViewProvider,
imageAiModel: string,
videoPrompt: string
) {
commands.registerCommand("jenkins-log-reader.readVideos", async (uri: Uri) => {
// get image file
// turn it into base64
// send to AI (llama3.2-vision)
// show result in result view
if (uri) {
// uri need to be a folder, then we check files one by one, only handle video files(check extension)
fs.readdir(uri.fsPath, (err, files) => {
if (err) {
console.error(err);
} else {
files
.filter((file) => {
file.toLowerCase().endsWith(".mp4") ||
file.toLowerCase().endsWith(".3pg") ||
file.toLowerCase().endsWith(".mov") ||
file.toLowerCase().endsWith(".ogg") ||
file.toLowerCase().endsWith(".avi") ||
file.toLowerCase().endsWith(".mpeg");
})
.map(async (file) => {
console.log("file: " + file);
});
// const image_uri = uri;
// const base64String = fs.readFileSync(image_uri.fsPath).toString("base64");
// const long_run_task = analyse_image(base64String, provider, imageAiModel, imagePrompt);
// showStatusBarProgress(long_run_task, "Analysing the image...");
}
});
}
});
}

function registerCommandOfReadVideo(
context: ExtensionContext,
provider: LogReaderResultWebViewProvider,
imageAiModel: string,
videoPrompt: string
) {
context.subscriptions.push(
commands.registerCommand("jenkins-log-reader.readVideo", async (uri: Uri) => {
// get video file
// turn it into base64
// send to AI (llama3.2-vision)
// show result in result view
if (uri) {
console.log(uri.fsPath);
// const video_uri = uri;
// const base64String = fs.readFileSync(video_uri.fsPath).toString("base64");
// const long_run_task = analyse_image(base64String, provider, imageAiModel, imagePrompt);
// showStatusBarProgress(long_run_task, "Analysing the image...");
}
})
);
}

function registerCommandOfReadImage(
context: ExtensionContext,
provider: LogReaderResultWebViewProvider,
Expand Down
10 changes: 3 additions & 7 deletions src/getInfoFromJenkins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,9 @@ export async function getAnalysis(
});
}

export async function getImageAnalysis(
model: string,
prompt: string,
data: string
) {

return await ollama.chat({
export async function getImageAnalysis(model: string, prompt: string, data: string) {
return await ollama
.chat({
model: model,
messages: [{ role: "user", content: prompt, images: [data] }],
stream: false,
Expand Down

0 comments on commit 6779178

Please sign in to comment.