Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@llamaindex/core

Package Overview
Dependencies
Maintainers
0
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@llamaindex/core - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

dist/response-synthesizers/index.cjs

20

dist/global/index.d.ts
import { CustomEvent, Tokenizer } from '@llamaindex/env';
import { ChatMessage, ToolCall, ToolOutput, ChatResponse, ChatResponseChunk, LLM } from '../llms/index.js';
import { QueryStartEvent, QueryEndEvent } from '../query-engine/index.js';
import { SynthesizeStartEvent, SynthesizeEndEvent } from '../response-synthesizers/index.js';
import { TextNode } from '../schema/index.js';
import { EventCaller } from '../utils/index.js';

@@ -22,15 +25,2 @@ declare const DEFAULT_CONTEXT_WINDOW = 3900;

/**
* EventCaller is used to track the caller of an event.
*/
declare class EventCaller {
#private;
readonly caller: unknown;
readonly parent: EventCaller | null;
readonly id: `${string}-${string}-${string}-${string}-${string}`;
private constructor();
get computedCallers(): unknown[];
static create(caller: unknown, parent: EventCaller | null): EventCaller;
}
type UUID = `${string}-${string}-${string}-${string}-${string}`;

@@ -84,2 +74,6 @@ type JSONValue = string | number | boolean | JSONObject | JSONArray;

"node-parsing-end": NodeParsingEndEvent;
"query-start": QueryStartEvent;
"query-end": QueryEndEvent;
"synthesize-start": SynthesizeStartEvent;
"synthesize-end": SynthesizeEndEvent;
}

@@ -86,0 +80,0 @@ declare class LlamaIndexCustomEvent<T = any> extends CustomEvent<T> {

import { path, AsyncLocalStorage, CustomEvent, tokenizers } from '@llamaindex/env';
import { getEventCaller } from '../utils/index.js';

@@ -25,7 +26,2 @@ //#region llm

const eventReasonAsyncLocalStorage = new AsyncLocalStorage();
function getEventCaller() {
return eventReasonAsyncLocalStorage.getStore() ?? null;
}
class LlamaIndexCustomEvent extends CustomEvent {

@@ -32,0 +28,0 @@ constructor(event, options){

import { Tokenizer } from '@llamaindex/env';
import { LLMMetadata } from '../llms/index.js';
import { SentenceSplitter } from '../node-parser/index.js';

@@ -47,4 +48,10 @@ import { PromptTemplate } from '../prompts/index.js';

repack(prompt: PromptTemplate, textChunks: string[], padding?: number): string[];
static fromLLMMetadata(metadata: LLMMetadata, options?: {
chunkOverlapRatio?: number;
chunkSizeLimit?: number;
tokenizer?: Tokenizer;
separator?: string;
}): PromptHelper;
}
export { PromptHelper, type PromptHelperOptions, getBiggestPrompt };
import { tokenizers } from '@llamaindex/env';
import { DEFAULT_CONTEXT_WINDOW, DEFAULT_NUM_OUTPUTS, DEFAULT_CHUNK_OVERLAP_RATIO, DEFAULT_PADDING } from '../global/index.js';
import { DEFAULT_CONTEXT_WINDOW, DEFAULT_NUM_OUTPUTS, DEFAULT_CHUNK_OVERLAP_RATIO, DEFAULT_PADDING, DEFAULT_CHUNK_SIZE, Settings } from '../global/index.js';
import { SentenceSplitter } from '../node-parser/index.js';

@@ -86,4 +86,15 @@

}
static fromLLMMetadata(metadata, options) {
const { chunkOverlapRatio = DEFAULT_CHUNK_OVERLAP_RATIO, chunkSizeLimit = DEFAULT_CHUNK_SIZE, tokenizer = Settings.tokenizer, separator = " " } = options ?? {};
return new PromptHelper({
contextWindow: metadata.contextWindow,
numOutput: metadata.maxTokens ?? DEFAULT_NUM_OUTPUTS,
chunkOverlapRatio,
chunkSizeLimit,
tokenizer,
separator
});
}
}
export { PromptHelper, getBiggestPrompt };
import { streamConverter } from '../utils/index.js';
import '@llamaindex/env';
import 'magic-bytes.js';
import '../schema/index.js';

@@ -3,0 +6,0 @@ /**

import { MessageContent } from '../llms/index.js';
import { EngineResponse, NodeWithScore } from '../schema/index.js';
import { PromptMixin } from '../prompts/index.js';
import { EngineResponse } from '../schema/index.js';

@@ -15,8 +16,19 @@ /**

type QueryType = string | QueryBundle;
interface BaseQueryEngine {
type QueryFn = (strOrQueryBundle: QueryType, stream?: boolean) => Promise<AsyncIterable<EngineResponse> | EngineResponse>;
declare abstract class BaseQueryEngine extends PromptMixin {
protected readonly _query: QueryFn;
protected constructor(_query: QueryFn);
query(strOrQueryBundle: QueryType, stream: true): Promise<AsyncIterable<EngineResponse>>;
query(strOrQueryBundle: QueryType, stream?: false): Promise<EngineResponse>;
synthesize?(strOrQueryBundle: QueryType, nodes: NodeWithScore[], additionalSources?: Iterator<NodeWithScore>): Promise<EngineResponse>;
}
export type { BaseQueryEngine, QueryBundle, QueryType };
type QueryStartEvent = {
id: string;
query: QueryType;
};
type QueryEndEvent = {
id: string;
response: EngineResponse | AsyncIterable<EngineResponse>;
};
export { BaseQueryEngine, type QueryBundle, type QueryEndEvent, type QueryStartEvent, type QueryType };

@@ -0,1 +1,410 @@

import { randomUUID } from '@llamaindex/env';
import { Settings } from '../global/index.js';
import { PromptMixin } from '../prompts/index.js';
import { wrapEventCaller } from '../utils/index.js';
function applyDecs2203RFactory() {
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
return function addInitializer(initializer) {
assertNotFinished(decoratorFinishedRef, "addInitializer");
assertCallable(initializer, "An initializer");
initializers.push(initializer);
};
}
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
var kindStr;
switch(kind){
case 1:
kindStr = "accessor";
break;
case 2:
kindStr = "method";
break;
case 3:
kindStr = "getter";
break;
case 4:
kindStr = "setter";
break;
default:
kindStr = "field";
}
var ctx = {
kind: kindStr,
name: isPrivate ? "#" + name : name,
static: isStatic,
private: isPrivate,
metadata: metadata
};
var decoratorFinishedRef = {
v: false
};
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
var get, set;
if (kind === 0) {
if (isPrivate) {
get = desc.get;
set = desc.set;
} else {
get = function() {
return this[name];
};
set = function(v) {
this[name] = v;
};
}
} else if (kind === 2) {
get = function() {
return desc.value;
};
} else {
if (kind === 1 || kind === 3) {
get = function() {
return desc.get.call(this);
};
}
if (kind === 1 || kind === 4) {
set = function(v) {
desc.set.call(this, v);
};
}
}
ctx.access = get && set ? {
get: get,
set: set
} : get ? {
get: get
} : {
set: set
};
try {
return dec(value, ctx);
} finally{
decoratorFinishedRef.v = true;
}
}
function assertNotFinished(decoratorFinishedRef, fnName) {
if (decoratorFinishedRef.v) {
throw new Error("attempted to call " + fnName + " after decoration was finished");
}
}
function assertCallable(fn, hint) {
if (typeof fn !== "function") {
throw new TypeError(hint + " must be a function");
}
}
function assertValidReturnValue(kind, value) {
var type = typeof value;
if (kind === 1) {
if (type !== "object" || value === null) {
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
}
if (value.get !== undefined) {
assertCallable(value.get, "accessor.get");
}
if (value.set !== undefined) {
assertCallable(value.set, "accessor.set");
}
if (value.init !== undefined) {
assertCallable(value.init, "accessor.init");
}
} else if (type !== "function") {
var hint;
if (kind === 0) {
hint = "field";
} else if (kind === 10) {
hint = "class";
} else {
hint = "method";
}
throw new TypeError(hint + " decorators must return a function or void 0");
}
}
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
var decs = decInfo[0];
var desc, init, value;
if (isPrivate) {
if (kind === 0 || kind === 1) {
desc = {
get: decInfo[3],
set: decInfo[4]
};
} else if (kind === 3) {
desc = {
get: decInfo[3]
};
} else if (kind === 4) {
desc = {
set: decInfo[3]
};
} else {
desc = {
value: decInfo[3]
};
}
} else if (kind !== 0) {
desc = Object.getOwnPropertyDescriptor(base, name);
}
if (kind === 1) {
value = {
get: desc.get,
set: desc.set
};
} else if (kind === 2) {
value = desc.value;
} else if (kind === 3) {
value = desc.get;
} else if (kind === 4) {
value = desc.set;
}
var newValue, get, set;
if (typeof decs === "function") {
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
if (newValue !== void 0) {
assertValidReturnValue(kind, newValue);
if (kind === 0) {
init = newValue;
} else if (kind === 1) {
init = newValue.init;
get = newValue.get || value.get;
set = newValue.set || value.set;
value = {
get: get,
set: set
};
} else {
value = newValue;
}
}
} else {
for(var i = decs.length - 1; i >= 0; i--){
var dec = decs[i];
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
if (newValue !== void 0) {
assertValidReturnValue(kind, newValue);
var newInit;
if (kind === 0) {
newInit = newValue;
} else if (kind === 1) {
newInit = newValue.init;
get = newValue.get || value.get;
set = newValue.set || value.set;
value = {
get: get,
set: set
};
} else {
value = newValue;
}
if (newInit !== void 0) {
if (init === void 0) {
init = newInit;
} else if (typeof init === "function") {
init = [
init,
newInit
];
} else {
init.push(newInit);
}
}
}
}
}
if (kind === 0 || kind === 1) {
if (init === void 0) {
init = function(instance, init) {
return init;
};
} else if (typeof init !== "function") {
var ownInitializers = init;
init = function(instance, init) {
var value = init;
for(var i = 0; i < ownInitializers.length; i++){
value = ownInitializers[i].call(instance, value);
}
return value;
};
} else {
var originalInitializer = init;
init = function(instance, init) {
return originalInitializer.call(instance, init);
};
}
ret.push(init);
}
if (kind !== 0) {
if (kind === 1) {
desc.get = value.get;
desc.set = value.set;
} else if (kind === 2) {
desc.value = value;
} else if (kind === 3) {
desc.get = value;
} else if (kind === 4) {
desc.set = value;
}
if (isPrivate) {
if (kind === 1) {
ret.push(function(instance, args) {
return value.get.call(instance, args);
});
ret.push(function(instance, args) {
return value.set.call(instance, args);
});
} else if (kind === 2) {
ret.push(value);
} else {
ret.push(function(instance, args) {
return value.call(instance, args);
});
}
} else {
Object.defineProperty(base, name, desc);
}
}
}
function applyMemberDecs(Class, decInfos, metadata) {
var ret = [];
var protoInitializers;
var staticInitializers;
var existingProtoNonFields = new Map();
var existingStaticNonFields = new Map();
for(var i = 0; i < decInfos.length; i++){
var decInfo = decInfos[i];
if (!Array.isArray(decInfo)) continue;
var kind = decInfo[1];
var name = decInfo[2];
var isPrivate = decInfo.length > 3;
var isStatic = kind >= 5;
var base;
var initializers;
if (isStatic) {
base = Class;
kind = kind - 5;
staticInitializers = staticInitializers || [];
initializers = staticInitializers;
} else {
base = Class.prototype;
protoInitializers = protoInitializers || [];
initializers = protoInitializers;
}
if (kind !== 0 && !isPrivate) {
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
var existingKind = existingNonFields.get(name) || 0;
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
} else if (!existingKind && kind > 2) {
existingNonFields.set(name, kind);
} else {
existingNonFields.set(name, true);
}
}
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
}
pushInitializers(ret, protoInitializers);
pushInitializers(ret, staticInitializers);
return ret;
}
function pushInitializers(ret, initializers) {
if (initializers) {
ret.push(function(instance) {
for(var i = 0; i < initializers.length; i++){
initializers[i].call(instance);
}
return instance;
});
}
}
function applyClassDecs(targetClass, classDecs, metadata) {
if (classDecs.length > 0) {
var initializers = [];
var newClass = targetClass;
var name = targetClass.name;
for(var i = classDecs.length - 1; i >= 0; i--){
var decoratorFinishedRef = {
v: false
};
try {
var nextNewClass = classDecs[i](newClass, {
kind: "class",
name: name,
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
metadata
});
} finally{
decoratorFinishedRef.v = true;
}
if (nextNewClass !== undefined) {
assertValidReturnValue(10, nextNewClass);
newClass = nextNewClass;
}
}
return [
defineMetadata(newClass, metadata),
function() {
for(var i = 0; i < initializers.length; i++){
initializers[i].call(newClass);
}
}
];
}
}
function defineMetadata(Class, metadata) {
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
configurable: true,
enumerable: true,
value: metadata
});
}
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
if (parentClass !== void 0) {
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
}
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
var e = applyMemberDecs(targetClass, memberDecs, metadata);
if (!classDecs.length) defineMetadata(targetClass, metadata);
return {
e: e,
get c () {
return applyClassDecs(targetClass, classDecs, metadata);
}
};
};
}
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
}
var _initProto;
class BaseQueryEngine extends PromptMixin {
static{
({ e: [_initProto] } = _apply_decs_2203_r(this, [
[
wrapEventCaller,
2,
"query"
]
], []));
}
constructor(_query){
super();
this._query = _query;
_initProto(this);
}
async query(strOrQueryBundle, stream = false) {
const id = randomUUID();
const callbackManager = Settings.callbackManager;
callbackManager.dispatchEvent("query-start", {
id,
query: strOrQueryBundle
});
const response = await this._query(strOrQueryBundle, stream);
callbackManager.dispatchEvent("query-end", {
id,
response
});
return response;
}
}
export { BaseQueryEngine };
import * as ___llms from '../llms/index.js';
import { LLMChat, LLM, MessageContent, MessageContentDetail, ChatMessage, ToolMetadata } from '../llms/index.js';
import { BasePromptTemplate } from '../prompts/index.js';
import { QueryType } from '../query-engine/index.js';
import { ImageType } from '../schema/index.js';
import { ImageType, BaseNode, MetadataMode } from '../schema/index.js';
/**
* EventCaller is used to track the caller of an event.
*/
declare class EventCaller {
#private;
readonly caller: unknown;
readonly parent: EventCaller | null;
readonly id: `${string}-${string}-${string}-${string}-${string}`;
private constructor();
get computedCallers(): unknown[];
static create(caller: unknown, parent: EventCaller | null): EventCaller;
}
declare function getEventCaller(): EventCaller | null;
declare function wrapEventCaller<This, Result, Args extends unknown[]>(originalMethod: (this: This, ...args: Args) => Result, context: ClassMethodDecoratorContext<object>): (this: This, ...args: Args) => Result;

@@ -40,2 +54,4 @@

declare function toToolDescriptions(tools: ToolMetadata[]): string;
declare function imageToDataUrl(input: ImageType | Uint8Array): Promise<string>;
declare function createMessageContent(prompt: BasePromptTemplate, nodes: BaseNode[], extraParams?: Record<string, string>, metadataMode?: MetadataMode): Promise<MessageContentDetail[]>;

@@ -63,2 +79,2 @@ type ObjectEntries<T extends Record<string, any>> = {

export { extractDataUrlComponents, extractImage, extractSingleText, extractText, messagesToHistory, objectEntries, streamCallbacks, streamConverter, streamReducer, toToolDescriptions, wrapEventCaller, wrapLLMEvent };
export { EventCaller, createMessageContent, extractDataUrlComponents, extractImage, extractSingleText, extractText, getEventCaller, imageToDataUrl, messagesToHistory, objectEntries, streamCallbacks, streamConverter, streamReducer, toToolDescriptions, wrapEventCaller, wrapLLMEvent };

@@ -1,3 +0,5 @@

import { AsyncLocalStorage, randomUUID } from '@llamaindex/env';
import { AsyncLocalStorage, randomUUID, fs } from '@llamaindex/env';
import { Settings } from '../global/index.js';
import { filetypemime } from 'magic-bytes.js';
import { splitNodesByType, MetadataMode, ModalityType } from '../schema/index.js';

@@ -229,2 +231,70 @@ const isAsyncIterable = (obj)=>{

}
async function blobToDataUrl(input) {
const buffer = Buffer.from(await input.arrayBuffer());
const mimes = filetypemime(buffer);
if (mimes.length < 1) {
throw new Error("Unsupported image type");
}
return "data:" + mimes[0] + ";base64," + buffer.toString("base64");
}
async function imageToDataUrl(input) {
// first ensure, that the input is a Blob
if (input instanceof URL && input.protocol === "file:" || typeof input === "string") {
// string or file URL
const dataBuffer = await fs.readFile(input instanceof URL ? input.pathname : input);
input = new Blob([
dataBuffer
]);
} else if (!(input instanceof Blob)) {
if (input instanceof URL) {
throw new Error(`Unsupported URL with protocol: ${input.protocol}`);
} else if (input instanceof Uint8Array) {
input = new Blob([
input
]); // convert Uint8Array to Blob
} else {
throw new Error(`Unsupported input type: ${typeof input}`);
}
}
return await blobToDataUrl(input);
}
// eslint-disable-next-line max-params
async function createContentPerModality(prompt, type, nodes, extraParams, metadataMode) {
switch(type){
case ModalityType.TEXT:
return [
{
type: "text",
text: prompt.format({
...extraParams,
context: nodes.map((r)=>r.getContent(metadataMode)).join("\n\n")
})
}
];
case ModalityType.IMAGE:
const images = await Promise.all(nodes.map(async (node)=>{
return {
type: "image_url",
image_url: {
url: await imageToDataUrl(node.image)
}
};
}));
return images;
default:
return [];
}
}
async function createMessageContent(prompt, nodes, extraParams = {}, metadataMode = MetadataMode.NONE) {
const content = [];
const nodeMap = splitNodesByType(nodes);
for(const type in nodeMap){
// for each retrieved modality type, create message content
const nodes = nodeMap[type];
if (nodes) {
content.push(...await createContentPerModality(prompt, type, nodes, extraParams, metadataMode));
}
}
return content;
}

@@ -266,2 +336,2 @@ /**

export { extractDataUrlComponents, extractImage, extractSingleText, extractText, messagesToHistory, objectEntries, streamCallbacks, streamConverter, streamReducer, toToolDescriptions, wrapEventCaller, wrapLLMEvent };
export { EventCaller, createMessageContent, extractDataUrlComponents, extractImage, extractSingleText, extractText, getEventCaller, imageToDataUrl, messagesToHistory, objectEntries, streamCallbacks, streamConverter, streamReducer, toToolDescriptions, wrapEventCaller, wrapLLMEvent };
{
"name": "@llamaindex/core",
"type": "module",
"version": "0.2.2",
"version": "0.2.3",
"description": "LlamaIndex Core Module",

@@ -188,2 +188,16 @@ "exports": {

}
},
"./response-synthesizers": {
"require": {
"types": "./dist/response-synthesizers/index.d.cts",
"default": "./dist/response-synthesizers/index.cjs"
},
"import": {
"types": "./dist/response-synthesizers/index.d.ts",
"default": "./dist/response-synthesizers/index.js"
},
"default": {
"types": "./dist/response-synthesizers/index.d.ts",
"default": "./dist/response-synthesizers/index.js"
}
}

@@ -209,2 +223,3 @@ },

"@types/node": "^22.5.1",
"magic-bytes.js": "^1.10.0",
"zod": "^3.23.8",

@@ -211,0 +226,0 @@ "@llamaindex/env": "0.1.11"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc