Skip to content

Commit

Permalink
fix: should run tasks by inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
tychenjiajun committed Sep 14, 2024
1 parent 86a0efa commit 427d915
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "exif-ai",
"version": "3.0.6",
"version": "3.0.7",
"description": "A Node.js CLI and library that uses Ollama or ZhipuAI to intelligently write image description and/or tags to exif metadata by it's content.",
"homepage": "https://github.com/tychenjiajun/exif-ai",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/exif-ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function findFilesRecursive(
}
const program = new Command();
program
.version("3.0.6")
.version("3.0.7")
.description(getText("description") ?? "")
.requiredOption("-a, --api-provider <provider>", getText("api-provider"))
.option("-T, --tasks <tasks...>", getText("tasks"))
Expand Down
44 changes: 24 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,30 @@ export async function execute({
if (verbose) console.log("Imported provider:", provider);

const [description, tags] = await Promise.all([
getDescription({
buffer,
model,
prompt: descriptionPrompt,
providerArgs,
providerModule,
verbose,
descriptionTags,
existingTags,
}),
getTags({
buffer,
model,
prompt: descriptionPrompt,
providerArgs,
providerModule,
verbose,
tagTags,
existingTags,
}),
tasks.includes("description")
? getDescription({
buffer,
model,
prompt: descriptionPrompt,
providerArgs,
providerModule,
verbose,
descriptionTags,
existingTags,
})
: undefined,
tasks.includes("tag") || tasks.includes("tags")
? getTags({
buffer,
model,
prompt: descriptionPrompt,
providerArgs,
providerModule,
verbose,
tagTags,
existingTags,
})
: undefined,
]);

if (dry) {
Expand Down
9 changes: 7 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { deleteAsync } from "del";

let i = 0;

const getDescription = vi.fn(async ({ prompt }: { prompt: string }) => prompt); // Return the prompt as the description
const getTags = vi.fn(async ({ prompt }: { prompt: string }) => prompt); // Return the prompt as the tags

describe("Image Processing Tests", () => {
const baseOptions = {
path: "./test/image0.jpeg",
Expand Down Expand Up @@ -46,7 +49,8 @@ describe("Image Processing Tests", () => {
);
// Mock the provider module
vi.doMock("provider1", () => ({
getDescription: async ({ prompt }: { prompt: string }) => prompt, // Return the prompt as the description
getDescription,
getTags,
}));
});

Expand Down Expand Up @@ -136,6 +140,7 @@ describe("Image Processing Tests", () => {
...baseOptions,
tasks: [],
});

// Verify the existing tag is not overwritten
const descriptionTags = await exiftool.read(resolvedPath);
expect(descriptionTags.XPComment).to.equal("Existing comment");
Expand Down Expand Up @@ -180,7 +185,7 @@ describe("Image Processing Tests", () => {
await exiftool.write(resolvedPath, { XPComment: "Existing comment" });
await execute({
...baseOptions,
provider: 'invalid',
provider: "invalid",
});
// Verify the existing tag is not overwritten
const descriptionTags = await exiftool.read(resolvedPath);
Expand Down

0 comments on commit 427d915

Please sign in to comment.