@llamaindex/core
Advanced tools
Comparing version 0.1.11 to 0.1.12
@@ -30,9 +30,9 @@ declare enum NodeRelationship { | ||
type BaseNodeParams<T extends Metadata = Metadata> = { | ||
id_?: string; | ||
metadata?: T; | ||
excludedEmbedMetadataKeys?: string[]; | ||
excludedLlmMetadataKeys?: string[]; | ||
relationships?: Partial<Record<NodeRelationship, RelatedNodeType<T>>>; | ||
hash?: string; | ||
embedding?: number[]; | ||
id_?: string | undefined; | ||
metadata?: T | undefined; | ||
excludedEmbedMetadataKeys?: string[] | undefined; | ||
excludedLlmMetadataKeys?: string[] | undefined; | ||
relationships?: Partial<Record<NodeRelationship, RelatedNodeType<T>>> | undefined; | ||
hash?: string | undefined; | ||
embedding?: number[] | undefined; | ||
}; | ||
@@ -50,3 +50,3 @@ /** | ||
id_: string; | ||
embedding?: number[]; | ||
embedding: number[] | undefined; | ||
metadata: T; | ||
@@ -53,0 +53,0 @@ excludedEmbedMetadataKeys: string[]; |
import { CustomEvent, Tokenizer } from '@llamaindex/env'; | ||
import { ChatMessage, ToolCall, ToolOutput, ChatResponse, ChatResponseChunk } from '../llms/index.js'; | ||
import { ChatMessage, ToolCall, ToolOutput, ChatResponse, ChatResponseChunk, LLM } from '../llms/index.js'; | ||
import { TextNode } from '../schema/index.js'; | ||
@@ -98,2 +98,4 @@ | ||
declare const Settings: { | ||
llm: LLM<object, object>; | ||
withLLM<Result>(llm: LLM, fn: () => Result): Result; | ||
tokenizer: Tokenizer; | ||
@@ -100,0 +102,0 @@ withTokenizer<Result>(tokenizer: Tokenizer, fn: () => Result): Result; |
@@ -105,2 +105,18 @@ import { path, AsyncLocalStorage, CustomEvent, tokenizers } from '@llamaindex/env'; | ||
const llmAsyncLocalStorage = new AsyncLocalStorage(); | ||
let globalLLM; | ||
function getLLM() { | ||
const currentLLM = globalLLM ?? llmAsyncLocalStorage.getStore(); | ||
if (!currentLLM) { | ||
throw new Error("Cannot find LLM, please set `Settings.llm = ...` on the top of your code"); | ||
} | ||
return currentLLM; | ||
} | ||
function setLLM(llm) { | ||
globalLLM = llm; | ||
} | ||
function withLLM(llm, fn) { | ||
return llmAsyncLocalStorage.run(llm, fn); | ||
} | ||
const chunkSizeAsyncLocalStorage = new AsyncLocalStorage(); | ||
@@ -121,2 +137,11 @@ let globalTokenizer = tokenizers.tokenizer(); | ||
const Settings = { | ||
get llm () { | ||
return getLLM(); | ||
}, | ||
set llm (llm){ | ||
setLLM(llm); | ||
}, | ||
withLLM (llm1, fn) { | ||
return withLLM(llm1, fn); | ||
}, | ||
get tokenizer () { | ||
@@ -123,0 +148,0 @@ return getTokenizer(); |
@@ -70,3 +70,3 @@ import { Tokenizers } from '@llamaindex/env'; | ||
topP: number; | ||
maxTokens?: number; | ||
maxTokens?: number | undefined; | ||
contextWindow: number; | ||
@@ -93,3 +93,3 @@ tokenizer: Tokenizers | undefined; | ||
interface LLMCompletionParamsNonStreaming extends LLMCompletionParamsBase { | ||
stream?: false | null; | ||
stream?: false | null | undefined; | ||
} | ||
@@ -96,0 +96,0 @@ type MessageContentTextDetail = { |
@@ -14,3 +14,3 @@ import { ChatMessage } from '../llms/index.js'; | ||
options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>; | ||
outputParser?: BaseOutputParser; | ||
outputParser?: BaseOutputParser | undefined; | ||
templateVarMappings?: Partial<Record<Vars[number] | (string & {}), TemplatesVar[number] | (string & {})>>; | ||
@@ -23,3 +23,3 @@ functionMappings?: Partial<Record<TemplatesVar[number] | (string & {}), MappingFn>>; | ||
options: Partial<Record<TemplatesVar[number] | (string & {}), string>>; | ||
outputParser?: BaseOutputParser; | ||
outputParser: BaseOutputParser | undefined; | ||
templateVarMappings: Partial<Record<Vars[number] | (string & {}), TemplatesVar[number] | (string & {})>>; | ||
@@ -26,0 +26,0 @@ functionMappings: Partial<Record<TemplatesVar[number] | (string & {}), MappingFn>>; |
@@ -8,138 +8,136 @@ import { objectEntries } from '../utils/index.js'; | ||
Object.defineProperty(String.prototype, "format", { | ||
value: function(...args_) { | ||
// Create variables | ||
let self = this; | ||
let __patterns__ = self.match(/({.*?})/g); | ||
const { REF, FILL_CHAR, MASK_NUMBER, ALIGN_OP, CROP_SIZE, DOT, FRACTION, TYPE_VAR } = { | ||
REF: 1, | ||
FILL_CHAR: 2, | ||
MASK_NUMBER: 3, | ||
ALIGN_OP: 4, | ||
CROP_SIZE: 5, | ||
DOT: 6, | ||
FRACTION: 7, | ||
TYPE_VAR: 8 | ||
}; | ||
const DEFAULT_PLACE = 6; | ||
const ALL_REGEXP = /{(\w+)?:([^>\^<\d#]|0)?([#%,])?([>^<\.])?(\d+)?(\.)?(\d+)?([eEfFgGdxXobn#%])?}/g; | ||
const regExpBasic = /{\[?(\w+)\]?}/; // it's not best solution | ||
const isObject = typeof args_[0] === "object"; | ||
// types/use logic | ||
__patterns__?.map((pattern, patt_index)=>{ | ||
const kargs = ALL_REGEXP.exec(pattern) || ALL_REGEXP.exec(pattern); | ||
const wargs = regExpBasic.exec(pattern); | ||
// Insert values (one 2 one / array / object) | ||
const INDEX_VAR = (wargs ? wargs[REF] : kargs ? kargs[REF] : patt_index) || patt_index; | ||
let NATUAL_VALUE = isObject ? args_[0][INDEX_VAR] : args_[INDEX_VAR]; | ||
let ACTUAL_VALUE = isObject ? args_[0][INDEX_VAR] : args_[INDEX_VAR]; | ||
// Verify sintax/semantic | ||
if (ACTUAL_VALUE === null || ACTUAL_VALUE === undefined) throw new Error(`Replacement index ${INDEX_VAR} out of range for positional args tuple`); | ||
if (kargs) { | ||
// If TYPE_VAR is not defined and the first argument is a number, pad a string should from left, so set TYPE_VAR to "d" | ||
if (kargs[TYPE_VAR] === undefined && typeof ACTUAL_VALUE === "number") { | ||
kargs[TYPE_VAR] = "d"; | ||
function format(...args_) { | ||
// Create variables | ||
let self = this; | ||
let __patterns__ = self.match(/({.*?})/g); | ||
const { REF, FILL_CHAR, MASK_NUMBER, ALIGN_OP, CROP_SIZE, DOT, FRACTION, TYPE_VAR } = { | ||
REF: 1, | ||
FILL_CHAR: 2, | ||
MASK_NUMBER: 3, | ||
ALIGN_OP: 4, | ||
CROP_SIZE: 5, | ||
DOT: 6, | ||
FRACTION: 7, | ||
TYPE_VAR: 8 | ||
}; | ||
const DEFAULT_PLACE = 6; | ||
const ALL_REGEXP = /{(\w+)?:([^>\^<\d#]|0)?([#%,])?([>^<\.])?(\d+)?(\.)?(\d+)?([eEfFgGdxXobn#%])?}/g; | ||
const regExpBasic = /{\[?(\w+)\]?}/; // it's not best solution | ||
const isObject = typeof args_[0] === "object"; | ||
// types/use logic | ||
__patterns__?.map((pattern, patt_index)=>{ | ||
const kargs = ALL_REGEXP.exec(pattern) || ALL_REGEXP.exec(pattern); | ||
const wargs = regExpBasic.exec(pattern); | ||
// Insert values (one 2 one / array / object) | ||
const INDEX_VAR = (wargs ? wargs[REF] : kargs ? kargs[REF] : patt_index) || patt_index; | ||
let NATUAL_VALUE = isObject ? args_[0][INDEX_VAR] : args_[INDEX_VAR]; | ||
let ACTUAL_VALUE = isObject ? args_[0][INDEX_VAR] : args_[INDEX_VAR]; | ||
// Verify sintax/semantic | ||
if (ACTUAL_VALUE === null || ACTUAL_VALUE === undefined) throw new Error(`Replacement index ${INDEX_VAR} out of range for positional args tuple`); | ||
if (kargs) { | ||
// If TYPE_VAR is not defined and the first argument is a number, pad a string should from left, so set TYPE_VAR to "d" | ||
if (kargs[TYPE_VAR] === undefined && typeof ACTUAL_VALUE === "number") { | ||
kargs[TYPE_VAR] = "d"; | ||
} | ||
const LETTER = (!kargs[FILL_CHAR] ? false : !kargs[ALIGN_OP] && [ | ||
..."FfbefoxXn" | ||
].includes(kargs[FILL_CHAR].toLowerCase()) ? kargs[FILL_CHAR] : kargs[TYPE_VAR]) || kargs[TYPE_VAR]; | ||
// padronaze | ||
if (LETTER) { | ||
const floatSize = pattern.includes(".") ? Number(kargs[FRACTION] || kargs[CROP_SIZE]) : DEFAULT_PLACE; | ||
switch(LETTER){ | ||
case "E": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toExponential(DEFAULT_PLACE).toUpperCase(); | ||
break; | ||
case "e": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toExponential(DEFAULT_PLACE); | ||
break; | ||
case "X": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(16).toUpperCase(); | ||
break; | ||
case "x": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(16); // Hexadecimal | ||
break; | ||
case "b": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(2); // Binary | ||
break; | ||
case "f": | ||
case "F": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toFixed(floatSize); | ||
break; | ||
case "o": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(8); // Octal | ||
break; | ||
} | ||
const LETTER = (!kargs[FILL_CHAR] ? false : !kargs[ALIGN_OP] && [ | ||
..."FfbefoxXn" | ||
].includes(kargs[FILL_CHAR].toLowerCase()) ? kargs[FILL_CHAR] : kargs[TYPE_VAR]) || kargs[TYPE_VAR]; | ||
// padronaze | ||
if (LETTER) { | ||
const floatSize = pattern.includes(".") ? Number(kargs[FRACTION] || kargs[CROP_SIZE]) : DEFAULT_PLACE; | ||
switch(LETTER){ | ||
case "E": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toExponential(DEFAULT_PLACE).toUpperCase(); | ||
break; | ||
case "e": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toExponential(DEFAULT_PLACE); | ||
break; | ||
case "X": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(16).toUpperCase(); | ||
break; | ||
case "x": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(16); // Hexadecimal | ||
break; | ||
case "b": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(2); // Binary | ||
break; | ||
case "f": | ||
case "F": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toFixed(floatSize); | ||
break; | ||
case "o": | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(8); // Octal | ||
break; | ||
} | ||
// mask | ||
switch(kargs[MASK_NUMBER]){ | ||
case "#": | ||
const MASK = { | ||
x: "0x", | ||
X: "0X", | ||
o: "0o", | ||
b: "0b" | ||
}[LETTER]; | ||
ACTUAL_VALUE = MASK + ACTUAL_VALUE; | ||
break; | ||
} | ||
// mask | ||
switch(kargs[MASK_NUMBER]){ | ||
case "#": | ||
const MASK = { | ||
x: "0x", | ||
X: "0X", | ||
o: "0o", | ||
b: "0b" | ||
}[LETTER]; | ||
ACTUAL_VALUE = MASK + ACTUAL_VALUE; | ||
break; | ||
} | ||
// signal | ||
if ([ | ||
..." +-,%" | ||
].includes(kargs[FILL_CHAR]) && typeof NATUAL_VALUE === "number") { | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString().replace("-", ""); | ||
if (NATUAL_VALUE >= 0) switch(kargs[FILL_CHAR]){ | ||
case "+": | ||
ACTUAL_VALUE = "+" + ACTUAL_VALUE; | ||
break; | ||
case " ": | ||
ACTUAL_VALUE = " " + ACTUAL_VALUE; | ||
break; | ||
case ",": | ||
ACTUAL_VALUE = NATUAL_VALUE.toString().split(/(?=(?:...)*$)/).join(kargs[FILL_CHAR]); | ||
break; | ||
case "%": | ||
ACTUAL_VALUE = (NATUAL_VALUE * 100).toFixed(kargs[FRACTION] || DEFAULT_PLACE) + "%"; | ||
break; | ||
} | ||
else ACTUAL_VALUE = "-" + ACTUAL_VALUE; | ||
} | ||
// signal | ||
if ([ | ||
..." +-,%" | ||
].includes(kargs[FILL_CHAR]) && typeof NATUAL_VALUE === "number") { | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString().replace("-", ""); | ||
if (NATUAL_VALUE >= 0) switch(kargs[FILL_CHAR]){ | ||
case "+": | ||
ACTUAL_VALUE = "+" + ACTUAL_VALUE; | ||
break; | ||
case " ": | ||
ACTUAL_VALUE = " " + ACTUAL_VALUE; | ||
break; | ||
case ",": | ||
ACTUAL_VALUE = NATUAL_VALUE.toString().split(/(?=(?:...)*$)/).join(kargs[FILL_CHAR]); | ||
break; | ||
case "%": | ||
ACTUAL_VALUE = (NATUAL_VALUE * 100).toFixed(kargs[FRACTION] || DEFAULT_PLACE) + "%"; | ||
break; | ||
} | ||
// space / order / trim | ||
if (kargs[CROP_SIZE]) { | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(); | ||
const FILL_ELEMENT = kargs[FILL_CHAR] || " "; | ||
const SIZE_STRING = ACTUAL_VALUE.length; | ||
const SIZE_ARG = kargs[CROP_SIZE]; | ||
const FILL_LENGTH = SIZE_STRING > SIZE_ARG ? SIZE_STRING : SIZE_ARG; | ||
const FILL = FILL_ELEMENT.repeat(FILL_LENGTH); | ||
switch(kargs[ALIGN_OP] || kargs[FILL_CHAR]){ | ||
case "<": | ||
ACTUAL_VALUE = ACTUAL_VALUE.padEnd(FILL_LENGTH, FILL_ELEMENT); | ||
break; | ||
case ".": | ||
if (!(LETTER && /[fF]/.test(LETTER))) ACTUAL_VALUE = ACTUAL_VALUE.slice(0, SIZE_ARG); | ||
break; | ||
case ">": | ||
ACTUAL_VALUE = ACTUAL_VALUE.padStart(FILL_LENGTH, FILL_ELEMENT); | ||
break; | ||
case "^": | ||
const length_start = Math.floor((FILL_LENGTH - SIZE_STRING) / 2); | ||
const string_start = length_start > 0 ? FILL_ELEMENT.repeat(length_start) + ACTUAL_VALUE : ACTUAL_VALUE; | ||
ACTUAL_VALUE = FILL.replace(RegExp(`.{${string_start.length}}`), string_start); | ||
break; | ||
default: | ||
ACTUAL_VALUE = LETTER ? ACTUAL_VALUE.padStart(FILL_LENGTH, FILL_ELEMENT) : ACTUAL_VALUE.padEnd(FILL_LENGTH, FILL_ELEMENT); | ||
break; | ||
} | ||
else ACTUAL_VALUE = "-" + ACTUAL_VALUE; | ||
} | ||
// space / order / trim | ||
if (kargs[CROP_SIZE]) { | ||
ACTUAL_VALUE = ACTUAL_VALUE.toString(); | ||
const FILL_ELEMENT = kargs[FILL_CHAR] || " "; | ||
const SIZE_STRING = ACTUAL_VALUE.length; | ||
const SIZE_ARG = kargs[CROP_SIZE]; | ||
const FILL_LENGTH = SIZE_STRING > SIZE_ARG ? SIZE_STRING : SIZE_ARG; | ||
const FILL = FILL_ELEMENT.repeat(FILL_LENGTH); | ||
switch(kargs[ALIGN_OP] || kargs[FILL_CHAR]){ | ||
case "<": | ||
ACTUAL_VALUE = ACTUAL_VALUE.padEnd(FILL_LENGTH, FILL_ELEMENT); | ||
break; | ||
case ".": | ||
if (!(LETTER && /[fF]/.test(LETTER))) ACTUAL_VALUE = ACTUAL_VALUE.slice(0, SIZE_ARG); | ||
break; | ||
case ">": | ||
ACTUAL_VALUE = ACTUAL_VALUE.padStart(FILL_LENGTH, FILL_ELEMENT); | ||
break; | ||
case "^": | ||
const length_start = Math.floor((FILL_LENGTH - SIZE_STRING) / 2); | ||
const string_start = length_start > 0 ? FILL_ELEMENT.repeat(length_start) + ACTUAL_VALUE : ACTUAL_VALUE; | ||
ACTUAL_VALUE = FILL.replace(RegExp(`.{${string_start.length}}`), string_start); | ||
break; | ||
default: | ||
ACTUAL_VALUE = LETTER ? ACTUAL_VALUE.padStart(FILL_LENGTH, FILL_ELEMENT) : ACTUAL_VALUE.padEnd(FILL_LENGTH, FILL_ELEMENT); | ||
break; | ||
} | ||
} | ||
// SET Definitive value | ||
self = self.replace(pattern, ACTUAL_VALUE); | ||
}); | ||
return self; | ||
} | ||
}); | ||
var pythonFormatJs = (inputString, ...param)=>inputString.format(...param); | ||
} | ||
// SET Definitive value | ||
self = self.replace(pattern, ACTUAL_VALUE); | ||
}); | ||
return self; | ||
} | ||
var pythonFormatJs = (inputString, ...param)=>format.call(inputString, ...param); | ||
var format = /*@__PURE__*/getDefaultExportFromCjs(pythonFormatJs); | ||
var format$1 = /*@__PURE__*/getDefaultExportFromCjs(pythonFormatJs); | ||
@@ -289,3 +287,3 @@ const promptType = { | ||
const mappedAllOptions = this.mapAllVars(allOptions); | ||
const prompt = format(this.template, mappedAllOptions); | ||
const prompt = format$1(this.template, mappedAllOptions); | ||
if (this.outputParser) { | ||
@@ -343,14 +341,14 @@ return this.outputParser.format(prompt); | ||
if (key.includes(":")) { | ||
const [module_name, sub_key] = key.split(":"); | ||
if (!subPrompt[module_name]) { | ||
subPrompt[module_name] = {}; | ||
const [moduleName, subKey] = key.split(":"); | ||
if (!subPrompt[moduleName]) { | ||
subPrompt[moduleName] = {}; | ||
} | ||
subPrompt[module_name][sub_key] = prompts[key]; | ||
subPrompt[moduleName][subKey] = prompts[key]; | ||
} | ||
} | ||
for (const [module_name, subPromptDict] of Object.entries(subPrompt)){ | ||
if (!promptModules[module_name]) { | ||
throw new Error(`Module ${module_name} not found.`); | ||
for (const [moduleName, subPromptDict] of Object.entries(subPrompt)){ | ||
if (!promptModules[moduleName]) { | ||
throw new Error(`Module ${moduleName} not found.`); | ||
} | ||
const moduleToUpdate = promptModules[module_name]; | ||
const moduleToUpdate = promptModules[moduleName]; | ||
moduleToUpdate.updatePrompts(subPromptDict); | ||
@@ -357,0 +355,0 @@ } |
@@ -33,9 +33,9 @@ import { ChatResponse, ChatResponseChunk, ChatMessage } from '../llms/index.js'; | ||
type BaseNodeParams<T extends Metadata = Metadata> = { | ||
id_?: string; | ||
metadata?: T; | ||
excludedEmbedMetadataKeys?: string[]; | ||
excludedLlmMetadataKeys?: string[]; | ||
relationships?: Partial<Record<NodeRelationship, RelatedNodeType<T>>>; | ||
hash?: string; | ||
embedding?: number[]; | ||
id_?: string | undefined; | ||
metadata?: T | undefined; | ||
excludedEmbedMetadataKeys?: string[] | undefined; | ||
excludedLlmMetadataKeys?: string[] | undefined; | ||
relationships?: Partial<Record<NodeRelationship, RelatedNodeType<T>>> | undefined; | ||
hash?: string | undefined; | ||
embedding?: number[] | undefined; | ||
}; | ||
@@ -53,3 +53,3 @@ /** | ||
id_: string; | ||
embedding?: number[]; | ||
embedding: number[] | undefined; | ||
metadata: T; | ||
@@ -88,7 +88,7 @@ excludedEmbedMetadataKeys: string[]; | ||
type TextNodeParams<T extends Metadata = Metadata> = BaseNodeParams<T> & { | ||
text?: string; | ||
textTemplate?: string; | ||
startCharIdx?: number; | ||
endCharIdx?: number; | ||
metadataSeparator?: string; | ||
text?: string | undefined; | ||
textTemplate?: string | undefined; | ||
startCharIdx?: number | undefined; | ||
endCharIdx?: number | undefined; | ||
metadataSeparator?: string | undefined; | ||
}; | ||
@@ -158,3 +158,3 @@ /** | ||
node: BaseNode<T>; | ||
score?: number; | ||
score?: number | undefined; | ||
} | ||
@@ -204,3 +204,3 @@ declare enum ModalityType { | ||
declare class EngineResponse implements ChatResponse, ChatResponseChunk { | ||
sourceNodes?: NodeWithScore[]; | ||
sourceNodes: NodeWithScore[] | undefined; | ||
metadata: Metadata; | ||
@@ -207,0 +207,0 @@ message: ChatMessage; |
{ | ||
"name": "@llamaindex/core", | ||
"type": "module", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "LlamaIndex Core Module", | ||
@@ -132,2 +132,16 @@ "exports": { | ||
} | ||
}, | ||
"./indices": { | ||
"require": { | ||
"types": "./dist/indices/index.d.cts", | ||
"default": "./dist/indices/index.cjs" | ||
}, | ||
"import": { | ||
"types": "./dist/indices/index.d.ts", | ||
"default": "./dist/indices/index.js" | ||
}, | ||
"default": { | ||
"types": "./dist/indices/index.d.ts", | ||
"default": "./dist/indices/index.js" | ||
} | ||
} | ||
@@ -134,0 +148,0 @@ }, |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
305316
42
6666