Skip to content

Commit 53e5187

Browse files
authored
Merge pull request #197 from llm-tools/confluence_updates
Added image loader
2 parents 78c7d27 + 800011d commit 53e5187

14 files changed

Lines changed: 179 additions & 7 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: '🖼️ Image'
3+
---
4+
5+
You can load most images using an LLM to describe the contents of the image. This LLM by default is the one used with the application,
6+
but a special LLM can also be specified for the content description. To load images, follow the steps below.
7+
8+
## Install Image addon
9+
10+
```bash
11+
npm install @llm-tools/embedjs-loader-image
12+
```
13+
14+
## Usage
15+
16+
### Load from a local file
17+
18+
```ts
19+
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
20+
import { ImageLoader } from '@llm-tools/embedjs-loader-image';
21+
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
22+
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
23+
24+
const app = await new RAGApplicationBuilder()
25+
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
26+
.setEmbeddingModel(new OpenAiEmbeddings())
27+
.setVectorDatabase(new HNSWDb())
28+
.build();
29+
30+
app.addLoader(new ImageLoader({ filePathOrUrl: '/path/to/file.jpeg' }))
31+
```

docs/components/data-sources/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ We handle the complexity of loading unstructured data from these data sources, a
2222
<Card title="Excel file" href="/components/data-sources/excel" />
2323
<Card title="Sitemap" href="/components/data-sources/sitemap" />
2424
<Card title="Markdown / MDX" href="/components/data-sources/markdown" />
25+
<Card title="Image" href="/components/data-sources/image" />
2526
<Card title="Custom" href="/components/data-sources/custom" />
2627
</CardGroup>
2728

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"components/data-sources/markdown",
8585
"components/data-sources/xml",
8686
"components/data-sources/directory",
87+
"components/data-sources/image",
8788
"components/data-sources/custom"
8889
]
8990
}

examples/image/assets/test.jpg

51.6 KB
Loading

examples/image/eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import baseConfig from '../../eslint.config.js';
2+
3+
export default [...baseConfig];

examples/image/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@llm-tools/embedjs-examples-image",
3+
"version": "0.1.1",
4+
"type": "module",
5+
"dependencies": {
6+
"dotenv": "^16.4.7"
7+
},
8+
"scripts": {
9+
"start": "nx run examples-image:serve"
10+
}
11+
}

examples/image/project.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "examples-image",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "examples/image/src",
5+
"projectType": "application",
6+
"tags": [],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/esbuild:esbuild",
10+
"outputs": ["{options.outputPath}"],
11+
"defaultConfiguration": "development",
12+
"options": {
13+
"platform": "node",
14+
"outputPath": "dist/examples/image",
15+
"format": ["esm"],
16+
"bundle": true,
17+
"main": "examples/image/src/main.ts",
18+
"tsConfig": "examples/image/tsconfig.app.json",
19+
"generatePackageJson": false,
20+
"esbuildOptions": {
21+
"sourcemap": true,
22+
"outExtension": {
23+
".js": ".js"
24+
}
25+
}
26+
},
27+
"configurations": {
28+
"development": {},
29+
"production": {
30+
"esbuildOptions": {
31+
"sourcemap": false,
32+
"outExtension": {
33+
".js": ".js"
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"serve": {
40+
"executor": "@nx/js:node",
41+
"defaultConfiguration": "development",
42+
"dependsOn": ["build"],
43+
"options": {
44+
"buildTarget": "examples-image:build",
45+
"runBuildTargetDependencies": true
46+
},
47+
"configurations": {
48+
"development": {
49+
"buildTarget": "examples-image:build:development"
50+
},
51+
"production": {
52+
"buildTarget": "examples-image:build:production"
53+
}
54+
}
55+
}
56+
}
57+
}

examples/image/src/main.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'dotenv/config';
2+
import path from 'node:path';
3+
import { RAGApplicationBuilder, SIMPLE_MODELS } from '@llm-tools/embedjs';
4+
import { ImageLoader } from '@llm-tools/embedjs-loader-image';
5+
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
6+
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
7+
8+
const ragApplication = await new RAGApplicationBuilder()
9+
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
10+
.setEmbeddingModel(new OpenAiEmbeddings())
11+
.setVectorDatabase(new HNSWDb())
12+
.build();
13+
14+
const imagePath = path.resolve('./examples/image/assets/test.jpg');
15+
await ragApplication.addLoader(new ImageLoader({ filePathOrUrl: imagePath }));
16+
17+
await ragApplication.query('How does deep learning relate to artifical intelligence');

examples/image/tsconfig.app.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"types": ["node"]
6+
},
7+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
8+
"include": ["src/**/*.ts"]
9+
}

examples/image/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"files": [],
4+
"include": [],
5+
"references": [
6+
{
7+
"path": "./tsconfig.app.json"
8+
}
9+
],
10+
"compilerOptions": {
11+
"esModuleInterop": true,
12+
"target": "ES2022",
13+
"lib": ["ES2022", "ES2022.Object"],
14+
"module": "NodeNext",
15+
"moduleResolution": "nodenext"
16+
}
17+
}

0 commit comments

Comments
 (0)