Skip to content

Commit

Permalink
add image read
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjien committed Nov 8, 2024
1 parent a8380cd commit 01b78d6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 27 deletions.
29 changes: 27 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": "AI Log Reader",
"description": "Read jenkins log, analyse with local AI.",
"version": "0.8.8",
"version": "0.8.9",
"engines": {
"vscode": "^1.95.0"
},
Expand Down Expand Up @@ -97,9 +97,34 @@
},
"jenkins-log-reader.jenkinsLogSize": {
"type": "number",
"title": "Retrieve Log Size",
"default": 5120,
"order": 8,
"description": "Jenkins Log Size for Analysis"
},
"jenkins-log-reader.imageAiModel": {
"type": "string",
"enum": [
"llama3.2-vision"
],
"default": "llama3.2-vision",
"title": "Image AI Model",
"order": 9,
"description": "Image AI Model"
},
"jenkins-log-reader.imagePrompt": {
"type": "string",
"title": "Image Prompt",
"default": "I am a QA, testing a product, which name is Curam. Please help me to check the snapshot, this is a functional testing. Do you see anything wrong or something behave weird in it?",
"order": 10,
"description": "Prompt for Image Analysis"
},
"jenkins-log-reader.videoPrompt": {
"type": "string",
"title": "Video Prompt",
"default": "Find a person with a ball",
"order": 11,
"description": "Prompt for Video Analysis"
}
}
},
Expand Down Expand Up @@ -223,7 +248,7 @@
"autoprefixer": "^10.4.20",
"axios": "^1.7.7",
"crypto": "^1.0.1",
"marked": "^14.1.3",
"marked": "^14.1.4",
"ollama": "^0.5.9",
"openai": "^4.71.1",
"tailwindcss": "^3.4.14"
Expand Down
57 changes: 32 additions & 25 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export function activate(context: ExtensionContext) {
window.showInformationMessage("Please configure your Local AI settings.");
}

const imageAiModel = getConfig("jenkins-log-reader.imageAiModel");

const imagePrompt = getConfig("jenkins-log-reader.imagePrompt");

const videoPrompt = getConfig("jenkins-log-reader.videoPrompt");

const settings = new JenkinsSettings(
jenkinsServerUrl,
logSize,
Expand All @@ -69,7 +75,7 @@ export function activate(context: ExtensionContext) {
const resultViewProvider = setupResultWebviewProvider(context);

registerCommandOfShowResult(context, resultViewProvider);
registerCommandOfReadImage(context, resultViewProvider);
registerCommandOfReadImage(context, resultViewProvider, imageAiModel, imagePrompt);
registerCommandOfFormatGrooby(context);
}

Expand All @@ -92,40 +98,43 @@ function registerCommandOfFormatGrooby(context: ExtensionContext) {
);
}

function registerCommandOfReadImage(context: ExtensionContext,
provider: LogReaderResultWebViewProvider) {
function registerCommandOfReadImage(
context: ExtensionContext,
provider: LogReaderResultWebViewProvider,
imageAiModel: string,
imagePrompt: string
) {
context.subscriptions.push(
commands.registerCommand("jenkins-log-reader.readImage", async (uri: Uri) => {
// get image file
// turn it into base64
// send to AI (llama3.2-vision)
// show result in result view
if (uri){


const image_uri = uri

const base64String = fs.readFileSync(image_uri.fsPath).toString('base64')
const long_run_task = analyse_image(base64String, provider);
showStatusBarProgress(long_run_task, 'Analysing the image...')

if (uri) {
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...");
}
})
);
}

async function analyse_image(base64String: string, provider: LogReaderResultWebViewProvider) {
await getImageAnalysis("llama3.2-vision",
'I am a QA, testing a product, which name is Curam. Please help me to check the snapshot, this is a functional testing. Do you see anything wrong or something behave weird in it?',
base64String).then((information: string) => {
if (provider._view) {
// commands.executeCommand("jenkins-log-reader_result-view.focus");
if (information) {
provider.updateContent(information);
commands.executeCommand("jenkins-log-reader_result-view.focus");
}
async function analyse_image(
base64String: string,
provider: LogReaderResultWebViewProvider,
imageAiModel: string,
imagePrompt: string
) {
await getImageAnalysis(imageAiModel, imagePrompt, base64String).then((information: string) => {
if (provider._view) {
// commands.executeCommand("jenkins-log-reader_result-view.focus");
if (information) {
provider.updateContent(information);
commands.executeCommand("jenkins-log-reader_result-view.focus");
}
});
}
});
}

function registerCommandOfShowResult(
Expand Down Expand Up @@ -164,5 +173,3 @@ function setupSettingsViewProvider(context: ExtensionContext) {
function getConfig(config_key: string): any {
return workspace.getConfiguration().get(config_key);
}


0 comments on commit 01b78d6

Please sign in to comment.