Skip to content

Commit 62980ec

Browse files
authored
Merge pull request #193 from llm-tools/confluence_updates
Updates
2 parents dcc1ede + bcfbe83 commit 62980ec

52 files changed

Lines changed: 452 additions & 157 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/embedjs-interfaces/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@llm-tools/embedjs-interfaces",
3-
"version": "0.1.26",
3+
"version": "0.1.27",
44
"description": "Interfaces for extending the embedjs ecosystem",
55
"dependencies": {
66
"@langchain/core": "^0.3.26",

core/embedjs-interfaces/src/interfaces/base-loader.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EventEmitter } from 'node:events';
44

55
import { BaseStore } from './base-store.js';
66
import { LoaderChunk, UnfilteredLoaderChunk } from '../types.js';
7+
import { BaseModel } from './base-model.js';
78

89
export abstract class BaseLoader<
910
MetadataTemplate extends Record<string, string | number | boolean> = Record<string, string | number | boolean>,
@@ -39,13 +40,16 @@ export abstract class BaseLoader<
3940
createDebugMessages('embedjs:loader:BaseLoader')(`New loader class initalized with key ${uniqueId}`);
4041
}
4142

42-
// eslint-disable-next-line @typescript-eslint/no-empty-function
43-
public async init(): Promise<void> {}
44-
4543
public getUniqueId(): string {
4644
return this.uniqueId;
4745
}
4846

47+
// eslint-disable-next-line @typescript-eslint/no-empty-function
48+
public async init(): Promise<void> {}
49+
50+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
51+
public injectModel(_model: BaseModel) {}
52+
4953
private async recordLoaderInCache(chunksProcessed: number) {
5054
if (!BaseLoader.store) return;
5155

core/embedjs-interfaces/src/interfaces/base-model.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,17 @@ export abstract class BaseModel {
135135
};
136136
}
137137

138+
public async simpleQuery(messages: (AIMessage | SystemMessage | HumanMessage)[]) {
139+
const response = await this.runQuery(messages);
140+
141+
return {
142+
result: response.result,
143+
tokenUse: {
144+
inputTokens: response.tokenUse?.inputTokens ?? 'UNKNOWN',
145+
outputTokens: response.tokenUse?.outputTokens ?? 'UNKNOWN',
146+
},
147+
};
148+
}
149+
138150
protected abstract runQuery(messages: (AIMessage | SystemMessage | HumanMessage)[]): Promise<ModelResponse>;
139151
}

core/embedjs-utils/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "@llm-tools/embedjs-utils",
3-
"version": "0.1.26",
3+
"version": "0.1.27",
44
"description": "Useful util functions when extending the embedjs ecosystem",
55
"dependencies": {
6-
"@llm-tools/embedjs-interfaces": "0.1.26"
6+
"@llm-tools/embedjs-interfaces": "0.1.27"
77
},
88
"type": "module",
99
"main": "./src/index.js",

core/embedjs-utils/src/util/stream.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Stream } from 'stream';
22

3-
export async function stream2buffer(stream: Stream): Promise<Buffer> {
3+
export async function streamToBuffer(stream: Stream): Promise<Buffer> {
44
return new Promise<Buffer>((resolve, reject) => {
55
const _buf = Array<Uint8Array>();
66

@@ -10,6 +10,16 @@ export async function stream2buffer(stream: Stream): Promise<Buffer> {
1010
});
1111
}
1212

13+
export async function streamToString(stream: Stream): Promise<string> {
14+
return new Promise((resolve, reject) => {
15+
const chunks = [];
16+
17+
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
18+
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
19+
stream.on('error', (err) => reject(`error converting stream - ${err}`));
20+
});
21+
}
22+
1323
export function contentTypeToMimeType(contentType: string) {
1424
if (!contentType) return contentType;
1525
if (contentType.includes(';')) return contentType.split(';')[0];

core/embedjs/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"type": "module",
33
"name": "@llm-tools/embedjs",
4-
"version": "0.1.26",
4+
"version": "0.1.27",
55
"description": "A NodeJS RAG framework to easily work with LLMs and custom datasets",
66
"dependencies": {
77
"@langchain/textsplitters": "^0.1.0",
8-
"@llm-tools/embedjs-interfaces": "0.1.26",
9-
"@llm-tools/embedjs-utils": "0.1.26",
8+
"@llm-tools/embedjs-interfaces": "0.1.27",
9+
"@llm-tools/embedjs-utils": "0.1.27",
1010
"debug": "^4.4.0",
1111
"langchain": "^0.3.8",
1212
"md5": "^2.3.0",

core/embedjs/src/core/rag-application.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export class RAGApplication {
164164
private async _addLoader(loader: BaseLoader, forceReload: boolean): Promise<AddLoaderReturn> {
165165
const uniqueId = loader.getUniqueId();
166166
this.debug('Exploring loader', uniqueId);
167+
if (this.model) loader.injectModel(this.model);
167168

168169
if (this.store && (await this.store.hasLoaderMetadata(uniqueId))) {
169170
if (forceReload) {

core/embedjs/src/util/mime.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ export async function createLoaderFromMimeType(loaderData: string, mimeType: str
9999
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported MarkdownLoader');
100100
return new MarkdownLoader({ filePathOrUrl: loaderData });
101101
}
102+
case 'image/png':
103+
case 'image/jpeg': {
104+
const { ImageLoader } = await import('@llm-tools/embedjs-loader-image').catch(() => {
105+
throw new Error('Package `@llm-tools/embedjs-loader-image` needs to be installed to load images');
106+
});
107+
createDebugMessages('embedjs:util:createLoaderFromMimeType')('Dynamically imported ImageLoader');
108+
return new ImageLoader({ filePathOrUrl: loaderData, mime: mimeType });
109+
}
110+
102111
case undefined:
103112
throw new Error(`MIME type could not be detected. Please file an issue if you think this is a bug.`);
104113
default:

databases/embedjs-astra/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@llm-tools/embedjs-astradb",
3-
"version": "0.1.26",
3+
"version": "0.1.27",
44
"description": "Add AstraDB support to embedjs",
55
"dependencies": {
66
"@datastax/astra-db-ts": "^1.5.0",
7-
"@llm-tools/embedjs-interfaces": "0.1.26",
7+
"@llm-tools/embedjs-interfaces": "0.1.27",
88
"debug": "^4.4.0"
99
},
1010
"type": "module",

databases/embedjs-cosmos/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@llm-tools/embedjs-cosmos",
3-
"version": "0.1.26",
3+
"version": "0.1.27",
44
"description": "Add CosmosDB support to embedjs",
55
"dependencies": {
66
"@azure/cosmos": "^4.2.0",
7-
"@llm-tools/embedjs-interfaces": "0.1.26",
7+
"@llm-tools/embedjs-interfaces": "0.1.27",
88
"debug": "^4.4.0"
99
},
1010
"type": "module",

0 commit comments

Comments
 (0)