Skip to content

Commit 3aaf9f6

Browse files
committed
feat: add ollama support
1 parent accb18c commit 3aaf9f6

8 files changed

Lines changed: 315 additions & 46 deletions

File tree

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules/**
33
pnpm-lock.yaml
44
renovate.json
55
.gitignore
6-
.github/**/*
6+
.github/**/*
7+
.prettierrc

README.md

Lines changed: 108 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,144 @@
11
# Exif AI
22

3-
*Exif AI* is a CLI tool for writing AI-generated image descriptions to metadata.
3+
_Exif AI_ is a powerful CLI tool designed to write AI-generated image descriptions directly into the metadata of image files. This tool leverages advanced AI models to analyze image content and generate descriptive metadata, enhancing the accessibility and searchability of your images.
44

55
## Usage Example
66

7-
Without Installation
7+
### CLI
8+
9+
#### Without Installation
10+
11+
You can run Exif AI directly using npx without installing it globally:
812

913
```bash
10-
ZHIPUAI_API_KEY=Your_Key npx exif-ai -i example.jpeg -a zhipu
14+
npx exif-ai -i example.jpeg -a ollama
1115
```
1216

13-
With Installation
17+
#### With Installation
18+
19+
If you have installed Exif AI globally, you can run it directly from the command line:
1420

1521
```bash
16-
ZHIPUAI_API_KEY=Your_Key exif-ai -i example.jpeg -a zhipu
22+
exif-ai -i example.jpeg -a ollama
23+
```
24+
25+
#### Options
26+
27+
Required options:
28+
29+
- `-i, --input <value>` Path to the input image file.
30+
- `-a, --api-provider <value>` Name of the AI provider to use (`ollama` for Ollama or `zhipu` for ZhipuAI).
31+
32+
Optional options:
33+
34+
- `-p, --prompt [value]`: Custom prompt for the AI provider. Defaults to a generic image description prompt.
35+
- `-m, --model [value]`: Specify the AI model to use, if supported by the provider.
36+
- `-t, --tags [value...]`: EXIF tags to write the description to. Defaults to common description tags.
37+
- `-v, --verbose`: Enable verbose output for debugging.
38+
- `-d, --dry-run`: Preview the AI-generated description without writing to the image file.
39+
- `--exif-tool-write-args [value...]`: Additional ExifTool arguments for writing metadata.
40+
- `--provider-args [value...]`: Additional arguments for the AI provider.
41+
42+
Example usage:
43+
44+
```bash
45+
exif-ai -i example.jpg -a ollama -p "Describe this landscape photo."
46+
```
47+
48+
### Library
49+
50+
To use Exif AI as a library in your project, import it and use the provided functions:
51+
52+
```typescript
53+
import { execute } from "exif-ai";
54+
55+
const options = {
56+
path: "example.jpeg",
57+
provider: "ollama",
58+
model: "moondream", // Optional: specify the model if required by the provider
59+
tags: ["XPComment", "Description", "ImageDescription", "Caption-Abstract"], // Optional: specify the EXIF tags to write
60+
prompt: "请使用中文描述这个图片。", // Optional: specify the prompt for the AI provider
61+
verbose: false, // Optional: enable verbose logging
62+
dry: false, // Optional: perform a dry run without writing to the file
63+
writeArgs: [], // Optional: additional arguments for EXIF write task
64+
providerArgs: [], // Optional: additional arguments for the AI provider
65+
};
66+
execute(options)
67+
.then(() => {
68+
console.log("Image description has been written to EXIF metadata.");
69+
})
70+
.catch((error) => {
71+
console.error("An error occurred:", error);
72+
});
1773
```
1874

1975
## Installation
2076

77+
To install Exif AI globally, use the following command:
78+
2179
```bash
2280
npm install -g exif-ai
2381
```
2482

2583
## API Providers
2684

27-
Exif AI requires an API provider to generate descriptions from images. Currently, we have only one built-in provider, ZhipuAI. You should have a ZhipuAI API key before using Exif AI.
85+
Exif AI relies on API providers to generate image descriptions. Currently, we support two providers: ZhipuAI and Ollama.
86+
87+
### Supported Providers
88+
89+
ZhipuAI: A leading AI service provider. Requires an API key.
90+
Ollama: A local AI service that runs on your machine, eliminating the need for an API key.
91+
92+
### Custom Providers
93+
94+
You can also develop your own custom provider by implementing the provider interface. This allows you to integrate with other AI services or customize the description generation process.
2895

29-
You can also build your own provider by implementing the provider interface.
96+
## Configuration
97+
98+
### Setting API Keys (for ZhipuAI)
99+
100+
To use ZhipuAI, you need to set the API key. You can do this by setting an environment variable:
101+
102+
```bash
103+
export ZHIPUAI_API_KEY=your_zhipuai_api_key
104+
```
105+
106+
### Ollama Configuration
107+
108+
Ollama runs locally and does not require an API key. Ensure that Ollama is installed and properly configured on your machine. Refer to the [Ollama GitHub repository](https://github.com/ollama/ollama) for installation and setup instructions.
30109

31110
## Develop
32111

33-
1. Clone the Repository
112+
### Prerequisites
113+
114+
- Node.js >=18
115+
- pnpm
116+
117+
### Clone the Repository
118+
119+
First, clone the Exif AI repository to your local machine:
34120

35121
```bash
36122
git clone https://github.com/tychenjiajun/exif-ai.git
37123
cd exif-ai
38124
```
39125

40-
2. Install Dependencies
126+
### Install Dependencies
127+
128+
Next, install the required dependencies using `pnpm`.
41129

42130
```bash
43131
pnpm install
44132
```
45133

46-
134+
### Build
135+
136+
```bash
137+
pnpm run build
138+
```
139+
140+
### Watch
141+
142+
```bash
143+
pnpm run watch
144+
```

manual.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# NAME
2+
3+
exif-ai - Write AI-generated image descriptions to EXIF metadata.
4+
5+
# SYNOPSIS
6+
7+
```
8+
exif-ai [options]
9+
```
10+
11+
# DESCRIPTION
12+
13+
The `exif-ai` command is a Node.js CLI tool that uses AI to analyze image content and write descriptive metadata to the EXIF information of an image file. It supports two AI providers: Ollama and ZhipuAI. Ollama runs locally, while ZhipuAI requires an API key.
14+
15+
# OPTIONS
16+
17+
* `-i, --input <file>`:
18+
Specify the path to the input image file.
19+
20+
* `-a, --api-provider <name>`:
21+
Choose the AI provider to use. Acceptable values are ollama or zhipu.
22+
23+
* `-p, --prompt <text>`:
24+
Set a custom prompt for the AI provider. If not specified, a default prompt is used.
25+
26+
* `-m, --model <name>`:
27+
Specify the AI model to use, if supported by the provider.
28+
29+
* `-t, --tags <tags...>`:
30+
List the EXIF tags to write the description to. Defaults to common description tags if not specified.
31+
32+
* `-v, --verbose`:
33+
Enable verbose output for debugging.
34+
35+
* `-d, --dry-run`:
36+
Preview the AI-generated description without writing to the image file.
37+
38+
* `--exif-tool-write-args <args...>`:
39+
Provide additional arguments for ExifTool when writing metadata.
40+
41+
* `--provider-args <args...>`:
42+
Pass additional arguments to the AI provider.
43+
44+
# EXAMPLES
45+
46+
Write a description to an image using Ollama:
47+
48+
```
49+
exif-ai -i image.jpg -a ollama
50+
```
51+
52+
Use ZhipuAI with a custom prompt:
53+
54+
```
55+
exif-ai -i image.jpg -a zhipu -p "Describe the scenery in this photo."
56+
```
57+
58+
Perform a dry run to see the description without modifying the image:
59+
60+
```
61+
exif-ai -i image.jpg -a ollama -d
62+
```
63+
64+
# PROVIDERS
65+
66+
* Ollama:
67+
A local AI service that runs on your machine. No API key is required.
68+
69+
* ZhipuAI:
70+
An AI service provider that requires an API key. Set the environment variable ZHIPUAI_API_KEY with your key.
71+
72+
# CONFIGURATION
73+
74+
For ZhipuAI, set the API key using an environment variable:
75+
76+
```
77+
export ZHIPUAI_API_KEY=your_zhipuai_api_key
78+
```
79+
80+
Ensure Ollama is installed and configured on your machine. Refer to the Ollama GitHub repository for installation and setup instructions.
81+
82+
# DEVELOPMENT
83+
To contribute to Exif AI, clone the repository, install dependencies, and build the project:
84+
85+
```
86+
git clone https://github.com/tychenjiajun/exif-ai.git
87+
cd exif-ai
88+
pnpm install
89+
pnpm run build
90+
```
91+
92+
# LICENSE
93+
94+
Exif AI is licensed under the GPL-2.0-only License.
95+
96+
# SEE ALSO
97+
* exiftool-vendored (https://github.com/photostructure/exiftool-vendored.js)
98+
* ollama (https://github.com/ollama/ollama)
99+
* zhipuAI (https://zhipu.ai)

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
22
"name": "exif-ai",
3-
"version": "1.0.2",
4-
"description": "Write AI-generated image description to metadata.",
3+
"version": "1.1.0",
4+
"description": "A Node.js CLI and library that uses Ollama or ZhipuAI to intelligently write image description to exif metadata by it's content.",
55
"scripts": {
66
"build": "tsc",
77
"watch": "tsc --watch"
88
},
99
"engines": {
1010
"node": ">=18"
1111
},
12+
"man": [
13+
"./exif-ai.1"
14+
],
1215
"main": "./dist/index.js",
1316
"types": "./dist/index.d.ts",
1417
"type": "module",
@@ -19,7 +22,13 @@
1922
"image",
2023
"jpeg",
2124
"jpg",
22-
"photo"
25+
"photo",
26+
"ollama",
27+
"zhipu",
28+
"llm",
29+
"cli",
30+
"cli-tool",
31+
"metadata"
2332
],
2433
"author": {
2534
"name": "Jiajun Chen",
@@ -29,11 +38,10 @@
2938
"dependencies": {
3039
"commander": "^12.1.0",
3140
"exiftool-vendored": "^28.2.1",
32-
"figlet": "^1.7.0",
41+
"ollama": "^0.5.8",
3342
"sharp": "^0.33.5"
3443
},
3544
"devDependencies": {
36-
"@types/figlet": "^1.5.8",
3745
"@types/node": "^22.5.1",
3846
"prettier": "^3.3.3",
3947
"typescript": "^5.5.4"

0 commit comments

Comments
 (0)