Skip to content

Commit

Permalink
feat: add support for coze
Browse files Browse the repository at this point in the history
  • Loading branch information
tychenjiajun committed Sep 22, 2024
1 parent ffda572 commit 0723148
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 24 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exif-ai -i example.jpeg -a ollama

Required options:

- `-a, --api-provider <value>`: Name of the AI provider to use (`ollama` for Ollama, `zhipu` for ZhipuAI, `google` for Google Gemini).
- `-a, --api-provider <value>`: Name of the AI provider to use (`ollama` for Ollama, `zhipu` for ZhipuAI, `google` for Google Gemini, `coze_bot` for Coze Bot).

Optional options:

Expand Down Expand Up @@ -133,21 +133,22 @@ Please ensure that you securely manage your API keys. Do not expose them in publ

## API Providers

Exif AI relies on API providers to generate image descriptions and tags. Currently, we support three providers: ZhipuAI, Ollama and Google Gemini.
Exif AI relies on API providers to generate image descriptions and tags. Currently, we support four providers: ZhipuAI, Ollama, Google Gemini and Coze.

### Supported Providers

- ZhipuAI: A leading AI service provider. Requires an API key.
- Ollama: A local AI service that runs on your machine, eliminating the need for an API key.
- Google Gemini: A powerful AI service provided by Google.
- Coze: Coze is a next-generation AI application and chatbot developing platform for everyone.

### Custom Providers

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.

## Configuration

### Setting API Keys (for ZhipuAI)
### Zhipu AI

To use [ZhipuAI](https://open.bigmodel.cn/usercenter/apikeys), you need to set the API key. You can do this by setting an environment variable:

Expand All @@ -163,7 +164,29 @@ To use [Google Gemini](https://ai.google.dev/), you need to set the API key. You
export API_KEY=your_google_api_key
```

### Ollama Configuration
### Coze Bot

To use [Coze](https://www.coze.com/) bot, you need to set the API key. You can do this by setting an environment variable:

```bash
export COZE_API_KEY=your_coze_api_key
```

When utilizing Coze within the Chinese region, configure the endpoint setting as follows:

```bash
export COZE_ENDPOINT=https://api.coze.cn
```

In Coze Bot, the `model` parameter corresponds to the bot's identifier. To interact with the Coze API, use the following command format:

```bash
exif-ai -a coze_bot -i image.jpg -m 7402199305639034921
```

Here, `-a coze_bot` specifies the Coze API, `-i image.jpg` indicates the input image file, and `-m 7402199305639034921` is the unique identifier for the bot model you wish to use.

### Ollama

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.

Expand Down
28 changes: 26 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,15 @@ Exif AI依赖于API供应商来生成图像描述和标签。目前,我们支
- ZhipuAI:领先的AI服务供应商。需要API密钥。
- Ollama:在您的机器上运行的本地AI服务,无需API密钥。
- Google Gemini:由Google提供的强大AI服务。
- Coze: 扣子是新一代 AI 大模型智能体开发平台。您可以使用API来调用扣子的bot或工作流。

### 自定义供应商

您还可以通过实现供应商接口来开发您自己的自定义供应商。这允许您与其他AI服务集成或自定义描述生成过程。

## 配置

### 设置API密钥(适用于ZhipuAI)
### ZhipuAI

要使用[ZhipuAI](https://open.bigmodel.cn/usercenter/apikeys),您需要设置API密钥。您可以通过设置环境变量来完成此操作:

Expand All @@ -154,7 +155,30 @@ export ZHIPUAI_API_KEY=your_zhipuai_api_key
export API_KEY=your_google_api_key
```

### Ollama Configuration
### Coze

要使用[Coze](https://www.coze.com/) Bot,您需要设置API密钥。您可以通过设置环境变量来完成此操作:

```bash
export COZE_API_KEY=your_coze_api_key
```

在中国地区使用Coze时,请按照以下方式配置端点设置:

```bash
export COZE_ENDPOINT=https://api.coze.cn
```

在Coze中,`model`参数对应于bot的id。要使用Coze API进行交互,请使用以下命令格式:


```bash
exif-ai -a coze_bot -i image.jpg -m 7402199305639034921
```

在此处,`-a coze_bot`指定了Coze API,`-i image.jpg`表示输入图像文件,而`-m 7402199305639034921`是您希望使用的bot的id。

### Ollama

Ollama在本地运行,不需要API密钥。请确保Ollama已安装在您的机器上并正确配置。有关安装和设置说明,请参考[Ollama](https://github.com/ollama/ollama)

Expand Down
6 changes: 4 additions & 2 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ exif-ai [options]

# DESCRIPTION

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 three AI providers: Ollama, ZhipuAI and Google Gemini. Ollama runs locally, while ZhipuAI and Google Gemini requires an API key.
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 four AI providers: Ollama, ZhipuAI, Google Gemini and Coze. Ollama runs locally, while ZhipuAI, Google Gemini and Coze requires an API key.

# OPTIONS

* `-i, --input <file>`:
Specify the path to the input image file.

* `-a, --api-provider <name>`:
Choose the AI provider to use. Acceptable values are ollama or zhipu.
Choose the AI provider to use. Acceptable values are ollama, zhipu, google or coze.

* `-p, --prompt <text>`:
Set a custom prompt for the AI provider. If not specified, a default prompt is used.
Expand Down Expand Up @@ -78,6 +78,8 @@ An AI service provider that requires an API key. Set the environment variable ZH
* Google Gemini:
An AI service provider that requires an API key. Set the environment variable API_KEY with your key.

* Coze:

# CONFIGURATION

## Zhipu AI
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "exif-ai",
"version": "3.1.0",
"description": "A Node.js CLI and library that uses Ollama, ZhipuAI or Google Gemini to intelligently write image description and/or tags to exif metadata by it's content.",
"version": "3.1.1",
"description": "A Node.js CLI and library that uses Ollama, ZhipuAI, Google Gemini or Coze to intelligently write image description and/or tags to exif metadata by it's content.",
"homepage": "https://github.com/tychenjiajun/exif-ai",
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,14 +40,16 @@
"cli",
"cli-tool",
"metadata",
"gemini"
"gemini",
"coze"
],
"author": {
"name": "Jiajun Chen",
"email": "[email protected]"
},
"license": "GPL-2.0-only",
"dependencies": {
"@coze/coze-js": "^0.2.0",
"@fluent/bundle": "^0.18.0",
"@google/generative-ai": "^0.19.0",
"chokidar": "^4.0.0",
Expand Down
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.1.0")
.version("3.1.1")
.description(getText("description") ?? "")
.requiredOption("-a, --api-provider <provider>", getText("api-provider"))
.option("-T, --tasks <tasks...>", getText("tasks"))
Expand Down
8 changes: 4 additions & 4 deletions src/fluent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const bundles: Record<string, FluentBundle> = {

bundles["en-US"].addResource(
new FluentResource(`
description = A Node.js CLI that uses Ollama, ZhipuAI or Google Gemini to intelligently write image description and/or tags to exif metadata by it's content.
api-provider = Name of the AI provider to use ('ollama' for Ollama, 'zhipu' for ZhipuAI, 'google' for Google Gemini).
description = A Node.js CLI that uses Ollama, ZhipuAI, Google Gemini or Cozw to intelligently write image description and/or tags to exif metadata by it's content.
api-provider = Name of the AI provider to use ('ollama' for Ollama, 'zhipu' for ZhipuAI, 'google' for Google Gemini, 'coze_bot' for Coze Bot).
input = Path to the input image file.
model = Specify the AI model to use, if supported by the provider.
description-tags = List of EXIF tags to write the description to. Defaults to common description tags.
Expand All @@ -31,8 +31,8 @@ face-group-ids = List of face group IDs to use for face recognition.

bundles["zh-CN"].addResource(
new FluentResource(`
description = 一个Node.js命令行工具,它使用Ollama或ZhipuAI根据图像内容智能地将图像描述和/或标签写入EXIF元数据。
api-provider = 要使用的AI供应商名称('ollama'代表Ollama,'zhipu'代表ZhipuAI,'google'代表Google Gemini)。
description = 一个Node.js命令行工具,它使用Ollama或ZhipuAI或Google Gemini或Coze根据图像内容智能地将图像描述和/或标签写入EXIF元数据。
api-provider = 要使用的AI供应商名称('ollama'代表Ollama,'zhipu'代表ZhipuAI,'google'代表Google Gemini, 'coze_bot'代表Coze)。
input = 输入图像文件的路径。
model = 指定要使用的AI模型,如果供应商支持。
description-tags = 要写入描述的EXIF标签列表。默认为常见描述标签。
Expand Down
18 changes: 18 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ export async function execute({
})
: undefined;

let file_id: string | undefined;

if ("uploadFile" in providerModule) {
if (verbose) console.log("Uploading file to provider");
const { id } = await providerModule.uploadFile({
path,
buffer,
});

file_id = id;
}

const [description, tags] = await Promise.all([
tasks.includes("description")
? getDescription({
Expand All @@ -190,6 +202,8 @@ export async function execute({
verbose,
descriptionTags,
existingTags,
path: resolvedPath,
file_id,
})
: undefined,
tasks.includes("tag") || tasks.includes("tags")
Expand All @@ -202,6 +216,8 @@ export async function execute({
tagTags,
existingTags,
additionalTags: faces,
path: resolvedPath,
file_id,
})
: tasks.includes("face")
? getTags({
Expand All @@ -212,6 +228,8 @@ export async function execute({
tagTags,
existingTags,
additionalTags: faces,
path: resolvedPath,
file_id,
})
: undefined,
]);
Expand Down
Loading

0 comments on commit 0723148

Please sign in to comment.