Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monorepo #116

Merged
merged 7 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build:esm
- name: Install dependencies
run: npm ci
- name: Test build
run: npm run build:esm
16 changes: 16 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint commit messages

on:
pull_request:
branches: ['main']

permissions:
contents: read
pull-requests: read

jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: wagoid/commitlint-github-action@v6
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ kafka/
zookeeper/
acme.json
temp/
storage/
storage/
lmdb/

#env
.env
1 change: 1 addition & 0 deletions core/embedjs-interfaces/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import { BaseModel } from './interfaces/base-model.js';
import { BaseConversation } from './interfaces/base-conversations.js';

export * from './types.js';
export * from './loaders.js';
export * from './constants.js';
export { BaseDb, BaseCache, BaseLoader, BaseEmbeddings, BaseModel, BaseConversation };
21 changes: 21 additions & 0 deletions core/embedjs-interfaces/src/loaders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// import { BaseLoader } from './interfaces/base-loader.js';
import { importBaseLoader } from './util.js';

await importBaseLoader('ConfluenceLoader', '@llm-tools/embedjs-loader-confluence');
// export type ConfluenceLoaderParam = ConstructorParameters<typeof ConfluenceLoader>[0];

// export type LoaderParam = string | BaseLoader | ({ type: 'Confluence' } & ConfluenceLoaderParam);
// | ({ type: 'Web' } & ConstructorParameters<typeof WebLoader>[0])
// | ({ type: 'Doc' } & ConstructorParameters<typeof DocxLoader>[0])
// | ({ type: 'Excel' } & ConstructorParameters<typeof ExcelLoader>[0])
// | ({ type: 'Json' } & ConstructorParameters<typeof JsonLoader>[0])
// | ({ type: 'Pdf' } & ConstructorParameters<typeof PdfLoader>[0])
// | ({ type: 'Ppt' } & ConstructorParameters<typeof PptLoader>[0])
// | ({ type: 'Sitemap' } & ConstructorParameters<typeof SitemapLoader>[0])
// | ({ type: 'Text' } & ConstructorParameters<typeof TextLoader>[0])
// | ({ type: 'YoutubeChannel' } & ConstructorParameters<typeof YoutubeChannelLoader>[0])
// | ({ type: 'Youtube' } & ConstructorParameters<typeof YoutubeLoader>[0])
// | ({ type: 'YoutubeSearch' } & ConstructorParameters<typeof YoutubeSearchLoader>[0])
// | ({ type: 'LocalPath' } & ConstructorParameters<typeof LocalPathLoader>[0])
// | ({ type: 'Url' } & ConstructorParameters<typeof UrlLoader>[0])
// | ({ type: 'Csv' } & ConstructorParameters<typeof CsvLoader>[0]);
25 changes: 25 additions & 0 deletions core/embedjs-interfaces/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import createDebugMessages from 'debug';
import { BaseLoader } from './interfaces/base-loader.js';

export async function importBaseLoader(moduleName: string, modulePath: string): Promise<BaseLoader> {
createDebugMessages('embedjs:interfaces:importBaseLoader')(
`Starting import of ${moduleName} from path ${modulePath}`,
);

try {
const importedModule = await import(modulePath);
createDebugMessages('embedjs:interfaces:importBaseLoader')(`Imported ${modulePath}`);

if (!importedModule[moduleName] || typeof importedModule[moduleName] !== 'function') {
createDebugMessages('embedjs:interfaces:importBaseLoader')(
`Module ${moduleName} not found at ${modulePath}`,
);
return null;
}

return importedModule[moduleName];
} catch (e) {
createDebugMessages('embedjs:interfaces:importBaseLoader')(`Module ${modulePath} not installed!`, e);
return null;
}
}
4 changes: 2 additions & 2 deletions core/embedjs-interfaces/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions core/embedjs-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions core/embedjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
2 changes: 1 addition & 1 deletion databases/embedjs-astra/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@llm-tools/embedjs-astra",
"name": "@llm-tools/embedjs-astradb",
"version": "0.1.1",
"description": "Add AstraDB support to embedjs",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-astra/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-cosmos/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-hnswlib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-lancedb/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-lmdb/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-mongodb/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-pinecone/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-qdrant/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-redis/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-weaviate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "ES2022.Object"],
"target": "ES2022",
"lib": ["ES2022", "ES2022.Object"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down
3 changes: 3 additions & 0 deletions examples/simple/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import baseConfig from '../../eslint.config.js';

export default [...baseConfig];
27 changes: 27 additions & 0 deletions examples/simple/package-lock.json

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

11 changes: 11 additions & 0 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@llm-tools/embedjs-examples-simple",
"version": "0.1.1",
"type": "module",
"dependencies": {
"dotenv": "^16.4.5"
},
"scripts": {
"start": "nx run examples-simple:serve"
}
}
57 changes: 57 additions & 0 deletions examples/simple/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "examples-simple",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "examples/simple/src",
"projectType": "application",
"tags": [],
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "development",
"options": {
"platform": "node",
"outputPath": "dist/examples/simple",
"format": ["esm"],
"bundle": true,
"main": "examples/simple/src/main.ts",
"tsConfig": "examples/simple/tsconfig.app.json",
"generatePackageJson": false,
"esbuildOptions": {
"sourcemap": true,
"outExtension": {
".js": ".js"
}
}
},
"configurations": {
"development": {},
"production": {
"esbuildOptions": {
"sourcemap": false,
"outExtension": {
".js": ".js"
}
}
}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"dependsOn": ["build"],
"options": {
"buildTarget": "examples-simple:build",
"runBuildTargetDependencies": true
},
"configurations": {
"development": {
"buildTarget": "examples-simple:build:development"
},
"production": {
"buildTarget": "examples-simple:build:production"
}
}
}
}
}
16 changes: 16 additions & 0 deletions examples/simple/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dotenv/config';
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAi, OpenAi3SmallEmbeddings } from '@llm-tools/embedjs-openai';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';

const llmApplication = await new RAGApplicationBuilder()
.setModel(new OpenAi({ modelName: 'gpt-4o' }))
.setEmbeddingModel(new OpenAi3SmallEmbeddings())
.setVectorDb(new HNSWDb())
.setSearchResultCount(30)
.build();

await llmApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));

console.log(await llmApplication.query('Who founded Tesla?'));
9 changes: 9 additions & 0 deletions examples/simple/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
Loading
Loading