@isdk/ai-tool 0.5.7 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-OYDBRUZJ.mjs +1 -0
- package/dist/funcs.js +1 -1
- package/dist/funcs.mjs +1 -1
- package/dist/index.d.mts +11 -637
- package/dist/index.d.ts +11 -637
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/classes/BinarySemaphore.md +25 -25
- package/docs/classes/CancelableAbility.md +25 -25
- package/docs/classes/ClientTools.md +57 -57
- package/docs/classes/ConfigFile.md +78 -262
- package/docs/classes/EnvPromptTemplate.md +233 -36
- package/docs/classes/EventClient.md +80 -80
- package/docs/classes/EventServer.md +81 -81
- package/docs/classes/EventToolFunc.md +49 -49
- package/docs/classes/FStringPromptTemplate.md +234 -37
- package/docs/classes/FewShotPromptTemplate.md +213 -34
- package/docs/classes/GolangPromptTemplate.md +230 -33
- package/docs/classes/IntSet.md +12 -12
- package/docs/classes/PromptExampleSelector.md +9 -9
- package/docs/classes/PromptTemplate.md +230 -34
- package/docs/classes/ReadableStreamError.md +2 -2
- package/docs/classes/ResClientTools.md +64 -64
- package/docs/classes/ResServerTools.md +65 -65
- package/docs/classes/SSEChannel.md +16 -16
- package/docs/classes/Semaphore.md +26 -26
- package/docs/classes/ServerTools.md +53 -53
- package/docs/classes/SignalGate.md +9 -9
- package/docs/classes/TaskAbortController.md +8 -8
- package/docs/classes/ToolFunc.md +46 -46
- package/docs/classes/YamlTypeBaseObject.md +2 -2
- package/docs/enumerations/AsyncFeatureBits.md +4 -4
- package/docs/enumerations/AsyncFeatures.md +4 -4
- package/docs/enumerations/HashAlgorithm.md +12 -12
- package/docs/functions/AIArgProcessor.md +1 -1
- package/docs/functions/AIStream.md +1 -1
- package/docs/functions/ChoiceArgProcessor.md +1 -1
- package/docs/functions/ObjectArgsToArgsInfo.md +1 -1
- package/docs/functions/RateLimit.md +1 -1
- package/docs/functions/TemplateArgProcessor.md +1 -1
- package/docs/functions/assignDirs.md +1 -1
- package/docs/functions/backendEventable.md +1 -1
- package/docs/functions/beforeShutdown.md +1 -1
- package/docs/functions/completeSentences.md +1 -1
- package/docs/functions/concatText.md +1 -1
- package/docs/functions/countLLMTokens.md +1 -1
- package/docs/functions/countRegexMatches.md +1 -1
- package/docs/functions/createCallbacksTransformer.md +1 -1
- package/docs/functions/createEmptyReadableStream.md +1 -1
- package/docs/functions/createEndWithRepetitionDetector.md +1 -1
- package/docs/functions/createEventStreamTransformer.md +1 -1
- package/docs/functions/createHfValueFunc.md +1 -1
- package/docs/functions/createLRUCache.md +1 -1
- package/docs/functions/createYamlObjectTag.md +1 -1
- package/docs/functions/dateToText.md +1 -1
- package/docs/functions/decodeCharset.md +1 -1
- package/docs/functions/detectCharset.md +1 -1
- package/docs/functions/encodeLLMTokens.md +1 -1
- package/docs/functions/ensureQuoted.md +1 -1
- package/docs/functions/expandConfig.md +3 -3
- package/docs/functions/expandEnv.md +4 -4
- package/docs/functions/expandObjEnv.md +4 -4
- package/docs/functions/expandPath.md +1 -1
- package/docs/functions/extNameLevel.md +1 -1
- package/docs/functions/fileIsExists.md +1 -1
- package/docs/functions/filterValidFnScope.md +1 -1
- package/docs/functions/findIndexNonEmptyFrom.md +1 -1
- package/docs/functions/findPort.md +1 -1
- package/docs/functions/formatTextWithSpace.md +1 -1
- package/docs/functions/getAllEnumKeys.md +1 -1
- package/docs/functions/getConfigFileNames.md +1 -1
- package/docs/functions/getConfigs.md +1 -1
- package/docs/functions/getEnvVairables.md +1 -1
- package/docs/functions/getFileMetaInfo.md +1 -1
- package/docs/functions/getHashAlgoBySize.md +1 -1
- package/docs/functions/getKeysPath.md +1 -1
- package/docs/functions/getLLMTokenizer.md +1 -1
- package/docs/functions/getMultiLevelExtname.md +4 -4
- package/docs/functions/getPackageDir.md +1 -1
- package/docs/functions/getRealFilepath.md +1 -1
- package/docs/functions/getResponseErrorReadableStream.md +1 -1
- package/docs/functions/getXDGConfigs.md +1 -1
- package/docs/functions/hasDirectoryIn.md +1 -1
- package/docs/functions/hash.md +1 -1
- package/docs/functions/hashFile.md +1 -1
- package/docs/functions/hashStream.md +1 -1
- package/docs/functions/initShutdown.md +1 -1
- package/docs/functions/isLangUsingSpaces.md +1 -1
- package/docs/functions/isListItemString.md +1 -1
- package/docs/functions/isModelNameMatched.md +1 -1
- package/docs/functions/isPunctuationChar.md +1 -1
- package/docs/functions/isQuoted.md +1 -1
- package/docs/functions/isRegExp.md +1 -1
- package/docs/functions/isSameString.md +1 -1
- package/docs/functions/isSectionString.md +1 -1
- package/docs/functions/isSentenceEnding.md +1 -1
- package/docs/functions/isSepLineString.md +1 -1
- package/docs/functions/isStrWrapped.md +1 -1
- package/docs/functions/isSubdirectory.md +1 -1
- package/docs/functions/isTitleString.md +1 -1
- package/docs/functions/isValidFilename.md +1 -1
- package/docs/functions/isValidFilepath.md +1 -1
- package/docs/functions/isWebStream.md +1 -1
- package/docs/functions/jsonFilterToWhere.md +1 -1
- package/docs/functions/jsonToMarkdownStr.md +1 -1
- package/docs/functions/loadAIConfig.md +1 -1
- package/docs/functions/loadConfig.md +1 -1
- package/docs/functions/loadConfigFile.md +1 -1
- package/docs/functions/loadFileFromPaths.md +1 -1
- package/docs/functions/loadTextFromPaths.md +1 -1
- package/docs/functions/lrucache.md +1 -1
- package/docs/functions/makeToolFuncCancelable.md +1 -1
- package/docs/functions/matchUrlProtocol.md +1 -1
- package/docs/functions/memoize.md +1 -1
- package/docs/functions/messagesToText.md +1 -1
- package/docs/functions/paramsSizeToScaleStr.md +1 -1
- package/docs/functions/parseCommand.md +1 -1
- package/docs/functions/parseJsJson.md +1 -1
- package/docs/functions/parseJsJsonSimpleSync.md +1 -1
- package/docs/functions/parseObjectArgInfo.md +1 -1
- package/docs/functions/parseObjectArgumentInfos.md +1 -1
- package/docs/functions/parseObjectArguments.md +1 -1
- package/docs/functions/parseObjectArgumentsAsArgInfos.md +1 -1
- package/docs/functions/parseYaml.md +21 -1
- package/docs/functions/quoteStr.md +1 -1
- package/docs/functions/readFilenamesRecursiveSync.md +7 -1
- package/docs/functions/readTextFileChunks.md +1 -1
- package/docs/functions/readTextFileChunksEx.md +1 -1
- package/docs/functions/readableFromAsyncIterable.md +1 -1
- package/docs/functions/registerCoreTools.md +1 -1
- package/docs/functions/registerYamlTag.md +18 -2
- package/docs/functions/removeMarkdownBold.md +1 -1
- package/docs/functions/removeMarkdownBoldAndItalic.md +1 -1
- package/docs/functions/removeMarkdownItalic.md +1 -1
- package/docs/functions/replaceWithPlaceholder.md +1 -1
- package/docs/functions/restoreFromPlacehoders.md +1 -1
- package/docs/functions/sanitizeFilename.md +4 -4
- package/docs/functions/sanitizeFilepath.md +4 -4
- package/docs/functions/saveConfigFile.md +1 -1
- package/docs/functions/scaleStrToParamsSize.md +1 -1
- package/docs/functions/shutdown.md +1 -1
- package/docs/functions/simplifyObjectArguments.md +1 -1
- package/docs/functions/sortedValues.md +1 -1
- package/docs/functions/splitChunks.md +1 -1
- package/docs/functions/splitParagraph.md +1 -1
- package/docs/functions/splitSentence.md +1 -1
- package/docs/functions/stringifyYaml.md +21 -1
- package/docs/functions/stripConsoleColor.md +1 -1
- package/docs/functions/textToDate.md +1 -1
- package/docs/functions/toDateTime.md +1 -1
- package/docs/functions/trimStartOfStreamHelper.md +1 -1
- package/docs/functions/truncTo.md +1 -1
- package/docs/functions/truncateByToken.md +1 -1
- package/docs/functions/truncateToTokenLimit.md +1 -1
- package/docs/functions/truncateToTokenLimitEx.md +1 -1
- package/docs/functions/uuid.md +1 -1
- package/docs/functions/wait.md +1 -1
- package/docs/functions/xxhash.md +1 -1
- package/docs/functions/xxhash32.md +1 -1
- package/docs/functions/xxhash64.md +1 -1
- package/docs/functions/xxhashAsStr.md +1 -1
- package/docs/globals.md +0 -23
- package/docs/interfaces/AIChatAssistantMessageParam.md +12 -12
- package/docs/interfaces/AIChatContentPartImage.md +3 -3
- package/docs/interfaces/AIChatContentPartText.md +3 -3
- package/docs/interfaces/AIChatMessageParamBase.md +7 -7
- package/docs/interfaces/AIChatMessageToolCall.md +4 -4
- package/docs/interfaces/AIChatSystemMessageParam.md +9 -9
- package/docs/interfaces/AIChatToolChoiceFuncObject.md +3 -3
- package/docs/interfaces/AIChatToolChoiceObject.md +2 -2
- package/docs/interfaces/AIChatToolFunc.md +5 -5
- package/docs/interfaces/AIChatToolFuncParam.md +3 -3
- package/docs/interfaces/AIChatToolMessageParam.md +10 -10
- package/docs/interfaces/AIChatToolParam.md +2 -2
- package/docs/interfaces/AIChatToolTypeObject.md +2 -2
- package/docs/interfaces/AIChatUserMessageParam.md +13 -13
- package/docs/interfaces/AIChoiceConfig.md +8 -8
- package/docs/interfaces/AIResult.md +6 -6
- package/docs/interfaces/AIStreamParser.md +2 -2
- package/docs/interfaces/AIStreamParserOptions.md +2 -2
- package/docs/interfaces/BaseFunc.md +11 -11
- package/docs/interfaces/BaseFuncItem.md +10 -10
- package/docs/interfaces/BinarySemaphoreAcquireOptions.md +2 -2
- package/docs/interfaces/BinarySemaphoreOptions.md +5 -5
- package/docs/interfaces/BinarySemaphoreReleaseOptions.md +2 -2
- package/docs/interfaces/BinarySemaphoreReleaserFunc.md +3 -3
- package/docs/interfaces/CancelableAbilityOptions.md +4 -4
- package/docs/interfaces/ClientFuncItem.md +13 -13
- package/docs/interfaces/EventClientFuncParams.md +5 -5
- package/docs/interfaces/EventServerFuncParams.md +6 -6
- package/docs/interfaces/FewShotPromptTemplateOptions.md +12 -12
- package/docs/interfaces/FuncItem.md +11 -11
- package/docs/interfaces/FuncParam.md +7 -7
- package/docs/interfaces/FuncParams.md +1 -1
- package/docs/interfaces/Funcs.md +1 -1
- package/docs/interfaces/HashAlgoParams.md +4 -4
- package/docs/interfaces/IFileMetaInfo.md +8 -8
- package/docs/interfaces/IReadTextFileChunksOptions.md +11 -11
- package/docs/interfaces/ITruncateToTokenLimitOptions.md +10 -10
- package/docs/interfaces/JsonFilter.md +1 -1
- package/docs/interfaces/ParseObjectArgumentOptions.md +11 -11
- package/docs/interfaces/PromptExampleSelectorOptions.md +3 -3
- package/docs/interfaces/PromptTemplateOptions.md +7 -7
- package/docs/interfaces/RemoteFuncItem.md +13 -13
- package/docs/interfaces/ReplacePlacehoderOptions.md +5 -5
- package/docs/interfaces/ResClientFuncParams.md +3 -3
- package/docs/interfaces/ResServerFuncParams.md +6 -6
- package/docs/interfaces/SanitizeFilenameOptions.md +3 -3
- package/docs/interfaces/SectionStringOptions.md +3 -3
- package/docs/interfaces/SemaphoreOptions.md +7 -7
- package/docs/interfaces/SemaphoreTaskItem.md +5 -5
- package/docs/interfaces/ServerFuncItem.md +14 -14
- package/docs/interfaces/ServerFuncParams.md +3 -3
- package/docs/interfaces/SplitSentenceOptions.md +5 -5
- package/docs/interfaces/StreamCallbacksAndOptions.md +5 -5
- package/docs/interfaces/TaskAbortControllers.md +1 -1
- package/docs/interfaces/TaskPromise.md +2 -2
- package/docs/interfaces/ToolFuncPackage.md +4 -4
- package/docs/type-aliases/AIChatContentPart.md +1 -1
- package/docs/type-aliases/AIChatMessageParam.md +1 -1
- package/docs/type-aliases/AIChatRole.md +1 -1
- package/docs/type-aliases/AIChatToolChoiceParam.md +1 -1
- package/docs/type-aliases/AIMessageType.md +1 -1
- package/docs/type-aliases/AIModelNameRule.md +1 -1
- package/docs/type-aliases/AIModelNameRuleFn.md +1 -1
- package/docs/type-aliases/AIModelNameRules.md +1 -1
- package/docs/type-aliases/AITextGenerationFinishReason.md +1 -1
- package/docs/type-aliases/ActionName.md +1 -1
- package/docs/type-aliases/AsyncTaskId.md +1 -1
- package/docs/type-aliases/BeforeShutdownListener.md +1 -1
- package/docs/type-aliases/EventErrorListenerFn.md +1 -1
- package/docs/type-aliases/EventListenerFn.md +1 -1
- package/docs/type-aliases/FuncParamType.md +1 -1
- package/docs/type-aliases/PromptExamples.md +1 -1
- package/docs/type-aliases/SemaphoreIsReadyFuncType.md +1 -1
- package/docs/type-aliases/TFunc.md +1 -1
- package/docs/variables/AIChatRoles.md +1 -1
- package/docs/variables/AIMessageTypes.md +1 -1
- package/docs/variables/AITextGenerationFinishReasons.md +1 -1
- package/docs/variables/ActionNames.md +1 -1
- package/docs/variables/ClientToolFuncSchema.md +1 -1
- package/docs/variables/DEFAULT_CONFIG_NAME.md +1 -1
- package/docs/variables/DefaultAsyncSemaphoreCapacity.md +1 -1
- package/docs/variables/EventBusName.md +1 -1
- package/docs/variables/EventName.md +1 -1
- package/docs/variables/FilenameReservedRegex.md +1 -1
- package/docs/variables/LLM_TOKENIZER_NAMES.md +1 -1
- package/docs/variables/LLM_TOKENIZER_NAMES_MAP.md +1 -1
- package/docs/variables/PASSING_SCORE.md +1 -1
- package/docs/variables/RStreamErrCode.md +1 -1
- package/docs/variables/RemoteToolFuncSchema.md +1 -1
- package/docs/variables/ResponseRStreamErrCode.md +1 -1
- package/docs/variables/SHUTDOWN_SIGNALS.md +1 -1
- package/docs/variables/SSEChannelAlreadyClosedErrCode.md +1 -1
- package/docs/variables/SecondaryCache.md +1 -1
- package/docs/variables/ServerToolFuncSchema.md +1 -1
- package/docs/variables/ToolAsyncCancelableBit.md +1 -1
- package/docs/variables/ToolAsyncMultiTaskBit.md +1 -1
- package/docs/variables/ToolAsyncPriorityBit.md +1 -1
- package/docs/variables/ToolFuncSchema.md +1 -1
- package/docs/variables/WindowsReservedNameRegex.md +1 -1
- package/docs/variables/base32768.md +1 -1
- package/docs/variables/defaultTemplateFormat.md +2 -2
- package/docs/variables/event.md +1 -1
- package/docs/variables/eventClient.md +1 -1
- package/docs/variables/eventServer.md +1 -1
- package/docs/variables/lrucache.md +1 -1
- package/package.json +5 -3
- package/dist/chunk-XLXW6OPN.mjs +0 -1
- package/docs/classes/HFEnvironment.md +0 -184
- package/docs/classes/HFInterpreter.md +0 -77
- package/docs/classes/HFTemplate.md +0 -67
- package/docs/classes/HfPromptTemplate.md +0 -1158
- package/docs/functions/filenameReservedRegex.md +0 -20
- package/docs/functions/hfParse.md +0 -24
- package/docs/functions/hfTokenize.md +0 -27
- package/docs/functions/interpolateEnv.md +0 -29
- package/docs/functions/interpolateFString.md +0 -29
- package/docs/functions/interpolateGolangTemplate.md +0 -35
- package/docs/functions/parseFString.md +0 -26
- package/docs/functions/reControlCharsRegex.md +0 -19
- package/docs/interfaces/DotenvExpandOptions.md +0 -43
- package/docs/interfaces/DotenvExpandOutput.md +0 -25
- package/docs/interfaces/DotenvParseInput.md +0 -13
- package/docs/interfaces/DotenvParseOutput.md +0 -13
- package/docs/interfaces/DotenvPopulateInput.md +0 -13
- package/docs/type-aliases/FStringPromptTemplateNode.md +0 -14
- package/docs/type-aliases/PromptTemplateType.md +0 -11
- package/docs/type-aliases/PromptType.md +0 -11
- package/docs/variables/HFBuiltins.md +0 -122
- package/docs/variables/PromptTemplateTypes.md +0 -11
- package/docs/variables/PromptTypes.md +0 -14
package/dist/index.d.mts
CHANGED
|
@@ -5,20 +5,20 @@ import { A as AsyncTaskId, a as AIModelNameRules } from './index-BkwhCK1q.mjs';
|
|
|
5
5
|
export { e as AIModelNameRule, d as AIModelNameRuleFn, c as ActionName, b as ActionNames, s as AsyncFeatureBits, t as AsyncFeatures, J as BaseFunc, H as BaseFuncItem, n as BinarySemaphore, i as BinarySemaphoreAcquireOptions, B as BinarySemaphoreOptions, j as BinarySemaphoreReleaseOptions, k as BinarySemaphoreReleaserFunc, x as CancelableAbility, C as CancelableAbilityOptions, O as ClientFuncItem, U as ClientToolFuncSchema, Q as ClientTools, D as DefaultAsyncSemaphoreCapacity, a5 as EventClient, a4 as EventClientFuncParams, a8 as EventServer, a7 as EventServerFuncParams, _ as EventToolFunc, I as FuncItem, z as FuncParam, F as FuncParamType, E as FuncParams, K as Funcs, P as PASSING_SCORE, p as RateLimit, f as RemoteFuncItem, R as RemoteToolFuncSchema, aa as ResClientFuncParams, ab as ResClientTools, ac as ResServerFuncParams, ad as ResServerTools, g as SSEChannel, S as SSEChannelAlreadyClosedErrCode, a0 as SecondaryCache, o as Semaphore, h as SemaphoreIsReadyFuncType, l as SemaphoreOptions, m as SemaphoreTaskItem, W as ServerFuncItem, V as ServerFuncParams, Y as ServerToolFuncSchema, X as ServerTools, G as TFunc, u as TaskAbortController, v as TaskAbortControllers, w as TaskPromise, q as ToolAsyncCancelableBit, T as ToolAsyncMultiTaskBit, r as ToolAsyncPriorityBit, M as ToolFunc, L as ToolFuncPackage, N as ToolFuncSchema, a1 as _lrucache, a2 as createLRUCache, $ as event, a6 as eventClient, a9 as eventServer, a3 as lrucache, y as makeToolFuncCancelable, Z as registerCoreTools } from './index-BkwhCK1q.mjs';
|
|
6
6
|
import { BaseError } from '@isdk/common-error';
|
|
7
7
|
export { AbortError, AbortErrorCode, AlreadyExistsError, AlreadyExistsErrorCode, BaseError, CommonError, ErrorCode, InternalErrorCode, NotFoundError, NotFoundErrorCode, NotImplementationError, NotImplementedErrorCode, createError, throwError } from '@isdk/common-error';
|
|
8
|
-
import {
|
|
8
|
+
import { StringTemplateOptions, StringTemplate } from '@isdk/template-engines';
|
|
9
|
+
export { EnvStringTemplate as EnvPromptTemplate, FStringTemplate as FStringPromptTemplate, GolangStringTemplate as GolangPromptTemplate, StringTemplate as PromptTemplate, StringTemplateOptions as PromptTemplateOptions, createHfValueFunc, defaultTemplateFormat, expandEnv, expandObjEnv, getEnvVairables } from '@isdk/template-engines';
|
|
9
10
|
import { Event, EventEmitter } from 'events-ex';
|
|
10
11
|
export { EventEmitter, states as EventStates, eventable, wrapEventEmitter } from 'events-ex';
|
|
11
12
|
import * as _base32768 from 'base32768';
|
|
12
13
|
import { IDataType } from 'hash-wasm';
|
|
14
|
+
export { ConfigFile, FilenameReservedRegex, SanitizeFilenameOptions, WindowsReservedNameRegex, extNameLevel, getMultiLevelExtname, isValidFilename, isValidFilepath, parseYaml, registerYamlTag, sanitizeFilename, sanitizeFilepath, stringifyYaml } from '@isdk/util';
|
|
13
15
|
import * as fs from 'fs';
|
|
14
|
-
import { ParseOptions, DocumentOptions, SchemaOptions, ToJSOptions, CreateNodeOptions, ToStringOptions } from 'yaml';
|
|
15
16
|
import _memoize, { Options } from 'memoizee';
|
|
16
17
|
export { f as findPort } from './find-port-qS1CZ9c-.mjs';
|
|
17
18
|
import { PreTrainedTokenizer } from '@xenova/transformers';
|
|
18
19
|
export { NIL as uuidNIL, parse as uuidParse, stringify as uuidStringify, validate as uuidValidate, version as uuidVersion, v1 as uuidv1, v4 as uuidv4, v5 as uuidv5 } from 'uuid';
|
|
19
20
|
export { canonicalize } from 'json-canonicalize';
|
|
20
21
|
export { mimeType } from 'mime-type/with-db';
|
|
21
|
-
export { Config as ConfigFile } from 'load-config-file';
|
|
22
22
|
export { formatISO, parse as parseDateFormat, parseISO, toDate } from 'date-fns';
|
|
23
23
|
export { LRUCache } from 'secondary-cache';
|
|
24
24
|
import 'property-manager';
|
|
@@ -132,60 +132,6 @@ interface AIChatToolTypeObject {
|
|
|
132
132
|
}
|
|
133
133
|
declare function messagesToText(messages: AIChatMessageParamBase[]): string;
|
|
134
134
|
|
|
135
|
-
/**
|
|
136
|
-
* Prompt Type
|
|
137
|
-
* defaults to `chat`
|
|
138
|
-
*/
|
|
139
|
-
declare const PromptTypes: readonly ["chat", "char", "plan"];
|
|
140
|
-
type PromptType = typeof PromptTypes[number];
|
|
141
|
-
declare const PromptTemplateTypes: readonly ["internal", "hf", "fill"];
|
|
142
|
-
type PromptTemplateType = typeof PromptTemplateTypes[number];
|
|
143
|
-
|
|
144
|
-
declare const defaultTemplateFormat = "default";
|
|
145
|
-
interface PromptTemplateOptions {
|
|
146
|
-
template?: string;
|
|
147
|
-
data?: Record<string, any>;
|
|
148
|
-
templateFormat?: string;
|
|
149
|
-
inputVariables?: string[];
|
|
150
|
-
compiledTemplate?: any;
|
|
151
|
-
ignoreInitialize?: boolean;
|
|
152
|
-
[name: string]: any;
|
|
153
|
-
}
|
|
154
|
-
declare class PromptTemplate extends BaseFactory {
|
|
155
|
-
compiledTemplate: any;
|
|
156
|
-
template: string;
|
|
157
|
-
templateFormat: string | undefined;
|
|
158
|
-
data: Record<string, any> | undefined;
|
|
159
|
-
inputVariables: string[] | undefined;
|
|
160
|
-
static from(template?: string | PromptTemplateOptions, options?: PromptTemplateOptions): PromptTemplate;
|
|
161
|
-
static format(options: PromptTemplateOptions): Promise<string>;
|
|
162
|
-
/**
|
|
163
|
-
* If the given options.template is the template, perform formatting using that template.
|
|
164
|
-
* @param options - The options object to check for being a template and to format.
|
|
165
|
-
* @returns A Promise that resolves to the formatted result if options is a template; otherwise, no value is returned.
|
|
166
|
-
*/
|
|
167
|
-
static formatIf(options: PromptTemplateOptions): Promise<string | undefined>;
|
|
168
|
-
static isTemplate(templateOpt: PromptTemplateOptions): any;
|
|
169
|
-
/**
|
|
170
|
-
* Validate/filter the data in inputVariables
|
|
171
|
-
* @param data
|
|
172
|
-
* @returns
|
|
173
|
-
*/
|
|
174
|
-
filterData(data: Record<string, any>): Record<string, any>;
|
|
175
|
-
constructor(template?: string | PromptTemplateOptions, options?: PromptTemplateOptions);
|
|
176
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
177
|
-
initialize(options?: PromptTemplateOptions): void;
|
|
178
|
-
_format(data: Record<string, any>): string | Promise<string>;
|
|
179
|
-
format(data?: Record<string, any>): Promise<string>;
|
|
180
|
-
/**
|
|
181
|
-
* it can make sense to "partial" a prompt template - eg pass in a subset of the required values, as to create a new prompt template which expects only the remaining subset of values.
|
|
182
|
-
* @param data the partial data
|
|
183
|
-
* @returns the new partial PromptTemplate instance
|
|
184
|
-
*/
|
|
185
|
-
partial(data: Record<string, any>): PromptTemplate;
|
|
186
|
-
toJSON(options?: PromptTemplateOptions): PromptTemplateOptions;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
135
|
type PromptExamples<T = any> = Iterable<PromiseLike<T> | T> | AsyncIterable<T>;
|
|
190
136
|
interface PromptExampleSelectorOptions {
|
|
191
137
|
/**
|
|
@@ -269,394 +215,8 @@ declare class PromptExampleSelector<T = any> {
|
|
|
269
215
|
[Symbol.asyncIterator](): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
270
216
|
}
|
|
271
217
|
|
|
272
|
-
/**
|
|
273
|
-
* Represents tokens that our language understands in parsing.
|
|
274
|
-
*/
|
|
275
|
-
declare const TOKEN_TYPES: Readonly<{
|
|
276
|
-
Text: "Text";
|
|
277
|
-
NumericLiteral: "NumericLiteral";
|
|
278
|
-
BooleanLiteral: "BooleanLiteral";
|
|
279
|
-
NullLiteral: "NullLiteral";
|
|
280
|
-
StringLiteral: "StringLiteral";
|
|
281
|
-
Identifier: "Identifier";
|
|
282
|
-
Equals: "Equals";
|
|
283
|
-
OpenParen: "OpenParen";
|
|
284
|
-
CloseParen: "CloseParen";
|
|
285
|
-
OpenStatement: "OpenStatement";
|
|
286
|
-
CloseStatement: "CloseStatement";
|
|
287
|
-
OpenExpression: "OpenExpression";
|
|
288
|
-
CloseExpression: "CloseExpression";
|
|
289
|
-
OpenSquareBracket: "OpenSquareBracket";
|
|
290
|
-
CloseSquareBracket: "CloseSquareBracket";
|
|
291
|
-
OpenCurlyBracket: "OpenCurlyBracket";
|
|
292
|
-
CloseCurlyBracket: "CloseCurlyBracket";
|
|
293
|
-
Comma: "Comma";
|
|
294
|
-
Dot: "Dot";
|
|
295
|
-
Colon: "Colon";
|
|
296
|
-
Pipe: "Pipe";
|
|
297
|
-
CallOperator: "CallOperator";
|
|
298
|
-
AdditiveBinaryOperator: "AdditiveBinaryOperator";
|
|
299
|
-
MultiplicativeBinaryOperator: "MultiplicativeBinaryOperator";
|
|
300
|
-
ComparisonBinaryOperator: "ComparisonBinaryOperator";
|
|
301
|
-
UnaryOperator: "UnaryOperator";
|
|
302
|
-
Set: "Set";
|
|
303
|
-
If: "If";
|
|
304
|
-
For: "For";
|
|
305
|
-
In: "In";
|
|
306
|
-
Is: "Is";
|
|
307
|
-
NotIn: "NotIn";
|
|
308
|
-
Else: "Else";
|
|
309
|
-
EndIf: "EndIf";
|
|
310
|
-
ElseIf: "ElseIf";
|
|
311
|
-
EndFor: "EndFor";
|
|
312
|
-
And: "And";
|
|
313
|
-
Or: "Or";
|
|
314
|
-
Not: "UnaryOperator";
|
|
315
|
-
Macro: "Macro";
|
|
316
|
-
EndMacro: "EndMacro";
|
|
317
|
-
}>;
|
|
318
|
-
type TokenType = keyof typeof TOKEN_TYPES;
|
|
319
|
-
/**
|
|
320
|
-
* Represents a single token in the template.
|
|
321
|
-
*/
|
|
322
|
-
declare class Token {
|
|
323
|
-
value: string;
|
|
324
|
-
type: TokenType;
|
|
325
|
-
/**
|
|
326
|
-
* Constructs a new Token.
|
|
327
|
-
* @param {string} value The raw value as seen inside the source code.
|
|
328
|
-
* @param {TokenType} type The type of token.
|
|
329
|
-
*/
|
|
330
|
-
constructor(value: string, type: TokenType);
|
|
331
|
-
}
|
|
332
|
-
interface PreprocessOptions {
|
|
333
|
-
trim_blocks?: boolean;
|
|
334
|
-
lstrip_blocks?: boolean;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Generate a list of tokens from a source string.
|
|
338
|
-
*/
|
|
339
|
-
declare function tokenize(source: string, options?: PreprocessOptions): Token[];
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Statements do not result in a value at runtime. They contain one or more expressions internally.
|
|
343
|
-
*/
|
|
344
|
-
declare class Statement {
|
|
345
|
-
isStatement?: boolean;
|
|
346
|
-
type: string;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Defines a block which contains many statements. Each chat template corresponds to one Program.
|
|
350
|
-
*/
|
|
351
|
-
declare class Program extends Statement {
|
|
352
|
-
body: Statement[];
|
|
353
|
-
type: string;
|
|
354
|
-
constructor(body: Statement[]);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Generate the Abstract Syntax Tree (AST) from a list of tokens.
|
|
359
|
-
* Operator precedence can be found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#table
|
|
360
|
-
*/
|
|
361
|
-
declare function parse(tokens: Token[]): Program;
|
|
362
|
-
|
|
363
|
-
type AnyRuntimeValue = NumericValue | StringValue | BooleanValue | ObjectValue | ArrayValue | FunctionValue | NullValue | UndefinedValue;
|
|
364
|
-
/**
|
|
365
|
-
* Abstract base class for all Runtime values.
|
|
366
|
-
* Should not be instantiated directly.
|
|
367
|
-
*/
|
|
368
|
-
declare abstract class RuntimeValue<T> {
|
|
369
|
-
type: string;
|
|
370
|
-
value: T;
|
|
371
|
-
/**
|
|
372
|
-
* A collection of built-in functions for this type.
|
|
373
|
-
*/
|
|
374
|
-
builtins: Map<string, AnyRuntimeValue>;
|
|
375
|
-
/**
|
|
376
|
-
* Creates a new RuntimeValue.
|
|
377
|
-
*/
|
|
378
|
-
constructor(value?: T);
|
|
379
|
-
/**
|
|
380
|
-
* Determines truthiness or falsiness of the runtime value.
|
|
381
|
-
* This function should be overridden by subclasses if it has custom truthiness criteria.
|
|
382
|
-
* @returns {BooleanValue} BooleanValue(true) if the value is truthy, BooleanValue(false) otherwise.
|
|
383
|
-
*/
|
|
384
|
-
__bool__(): BooleanValue;
|
|
385
|
-
toString(): string;
|
|
386
|
-
toJSON(): any;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Represents a numeric value at runtime.
|
|
390
|
-
*/
|
|
391
|
-
declare class NumericValue extends RuntimeValue<number> {
|
|
392
|
-
type: string;
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Represents a string value at runtime.
|
|
396
|
-
*/
|
|
397
|
-
declare class StringValue extends RuntimeValue<string> {
|
|
398
|
-
type: string;
|
|
399
|
-
builtins: Map<string, AnyRuntimeValue>;
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Represents a boolean value at runtime.
|
|
403
|
-
*/
|
|
404
|
-
declare class BooleanValue extends RuntimeValue<boolean> {
|
|
405
|
-
type: string;
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Represents an Object value at runtime.
|
|
409
|
-
*/
|
|
410
|
-
declare class ObjectValue extends RuntimeValue<Map<string, AnyRuntimeValue>> {
|
|
411
|
-
orgValue?: Record<string, any> | undefined;
|
|
412
|
-
type: string;
|
|
413
|
-
constructor(value: Map<string, AnyRuntimeValue>, orgValue?: Record<string, any> | undefined);
|
|
414
|
-
toString(): string;
|
|
415
|
-
toJSON(): Record<string, any>;
|
|
416
|
-
/**
|
|
417
|
-
* NOTE: necessary to override since all JavaScript arrays are considered truthy,
|
|
418
|
-
* while only non-empty Python arrays are consider truthy.
|
|
419
|
-
*
|
|
420
|
-
* e.g.,
|
|
421
|
-
* - JavaScript: {} && 5 -> 5
|
|
422
|
-
* - Python: {} and 5 -> {}
|
|
423
|
-
*/
|
|
424
|
-
__bool__(): BooleanValue;
|
|
425
|
-
builtins: Map<string, AnyRuntimeValue>;
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Represents an Array value at runtime.
|
|
429
|
-
*/
|
|
430
|
-
declare class ArrayValue extends RuntimeValue<AnyRuntimeValue[]> {
|
|
431
|
-
type: string;
|
|
432
|
-
builtins: Map<string, AnyRuntimeValue>;
|
|
433
|
-
/**
|
|
434
|
-
* NOTE: necessary to override since all JavaScript arrays are considered truthy,
|
|
435
|
-
* while only non-empty Python arrays are consider truthy.
|
|
436
|
-
*
|
|
437
|
-
* e.g.,
|
|
438
|
-
* - JavaScript: [] && 5 -> 5
|
|
439
|
-
* - Python: [] and 5 -> []
|
|
440
|
-
*/
|
|
441
|
-
__bool__(): BooleanValue;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Represents a Function value at runtime.
|
|
445
|
-
*/
|
|
446
|
-
declare class FunctionValue extends RuntimeValue<(args: AnyRuntimeValue[], scope: Environment) => AnyRuntimeValue> {
|
|
447
|
-
type: string;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Represents a Null value at runtime.
|
|
451
|
-
*/
|
|
452
|
-
declare class NullValue extends RuntimeValue<null> {
|
|
453
|
-
type: string;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Represents an Undefined value at runtime.
|
|
457
|
-
*/
|
|
458
|
-
declare class UndefinedValue extends RuntimeValue<undefined> {
|
|
459
|
-
type: string;
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Represents the current environment (scope) at runtime.
|
|
463
|
-
*/
|
|
464
|
-
declare class Environment {
|
|
465
|
-
parent?: Environment | undefined;
|
|
466
|
-
/**
|
|
467
|
-
* The variables declared in this environment.
|
|
468
|
-
*/
|
|
469
|
-
variables: Map<string, AnyRuntimeValue>;
|
|
470
|
-
/**
|
|
471
|
-
* The tests available in this environment.
|
|
472
|
-
*/
|
|
473
|
-
tests: Map<string, (...value: AnyRuntimeValue[]) => boolean>;
|
|
474
|
-
constructor(parent?: Environment | undefined);
|
|
475
|
-
/**
|
|
476
|
-
* Set the value of a variable in the current environment.
|
|
477
|
-
*/
|
|
478
|
-
set(name: string, value: unknown): AnyRuntimeValue;
|
|
479
|
-
private declareVariable;
|
|
480
|
-
/**
|
|
481
|
-
* Set variable in the current scope.
|
|
482
|
-
* See https://jinja.palletsprojects.com/en/3.0.x/templates/#assignments for more information.
|
|
483
|
-
*/
|
|
484
|
-
setVariable(name: string, value: AnyRuntimeValue): AnyRuntimeValue;
|
|
485
|
-
/**
|
|
486
|
-
* Resolve the environment in which the variable is declared.
|
|
487
|
-
* @param {string} name The name of the variable.
|
|
488
|
-
* @returns {Environment} The environment in which the variable is declared.
|
|
489
|
-
*/
|
|
490
|
-
private resolve;
|
|
491
|
-
lookupVariable(name: string): AnyRuntimeValue;
|
|
492
|
-
}
|
|
493
|
-
declare class Interpreter {
|
|
494
|
-
global: Environment;
|
|
495
|
-
constructor(env?: Environment);
|
|
496
|
-
/**
|
|
497
|
-
* Run the program.
|
|
498
|
-
*/
|
|
499
|
-
run(program: Program): AnyRuntimeValue;
|
|
500
|
-
/**
|
|
501
|
-
* Evaluates expressions following the binary operation type.
|
|
502
|
-
*/
|
|
503
|
-
private evaluateBinaryExpression;
|
|
504
|
-
private evaluateArguments;
|
|
505
|
-
/**
|
|
506
|
-
* Evaluates expressions following the filter operation type.
|
|
507
|
-
*/
|
|
508
|
-
private evaluateFilterExpression;
|
|
509
|
-
/**
|
|
510
|
-
* Evaluates expressions following the test operation type.
|
|
511
|
-
*/
|
|
512
|
-
private evaluateTestExpression;
|
|
513
|
-
/**
|
|
514
|
-
* Evaluates expressions following the unary operation type.
|
|
515
|
-
*/
|
|
516
|
-
private evaluateUnaryExpression;
|
|
517
|
-
private evalProgram;
|
|
518
|
-
private evaluateBlock;
|
|
519
|
-
private evaluateIdentifier;
|
|
520
|
-
private evaluateCallExpression;
|
|
521
|
-
private evaluateSliceExpression;
|
|
522
|
-
private evaluateMemberExpression;
|
|
523
|
-
private evaluateSet;
|
|
524
|
-
private evaluateIf;
|
|
525
|
-
private evaluateFor;
|
|
526
|
-
/**
|
|
527
|
-
* See https://jinja.palletsprojects.com/en/3.1.x/templates/#macros for more information.
|
|
528
|
-
*/
|
|
529
|
-
private evaluateMacro;
|
|
530
|
-
evaluate(statement: Statement | undefined, environment: Environment): AnyRuntimeValue;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
declare function randomInt(to: number, from?: number): number;
|
|
534
|
-
/**
|
|
535
|
-
* Selects an element from the given object, array, or string.
|
|
536
|
-
* @param obj Can be an object, array, or string to select from.
|
|
537
|
-
* @param index Optional, specifies the index or key to select. Negative values indicate indices from the end.
|
|
538
|
-
* @returns The selected element, or `undefined` if the input is empty or not provided.
|
|
539
|
-
*
|
|
540
|
-
* @example
|
|
541
|
-
* // Selecting an element from an array
|
|
542
|
-
* const array = ['apple', 'banana', 'cherry']
|
|
543
|
-
* console.log(select(array)) // Random element from the array
|
|
544
|
-
* console.log(select(array, 1)) // Second element
|
|
545
|
-
* console.log(select(array, -1)) // Last element
|
|
546
|
-
*
|
|
547
|
-
* @example
|
|
548
|
-
* // Selecting a property from an object
|
|
549
|
-
* const obj = { fruit1: 'apple', fruit2: 'banana', fruit3: 'cherry' }
|
|
550
|
-
* console.log(select(obj)) // Random property from the object
|
|
551
|
-
* console.log(select(obj, 'fruit2')) // Property with key 'fruit2'
|
|
552
|
-
*
|
|
553
|
-
* @example
|
|
554
|
-
* // Selecting a character from a string
|
|
555
|
-
* const str = 'hello'
|
|
556
|
-
* console.log(select(str)) // Random character from the string
|
|
557
|
-
* console.log(select(str, 1)) // Second character
|
|
558
|
-
* console.log(select(str, -1)) // Last character
|
|
559
|
-
*/
|
|
560
|
-
declare function select(obj: any | any[], index?: number | string): any;
|
|
561
|
-
declare function tojson(value: any, indent?: number | {
|
|
562
|
-
indent?: number;
|
|
563
|
-
depth?: number;
|
|
564
|
-
}, depth?: number): string;
|
|
565
|
-
declare function join(value: any, separator?: string): any;
|
|
566
|
-
declare const builtins: {
|
|
567
|
-
randomInt: typeof randomInt;
|
|
568
|
-
select: typeof select;
|
|
569
|
-
tojson: typeof tojson;
|
|
570
|
-
join: typeof join;
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* @file Jinja templating engine
|
|
575
|
-
*
|
|
576
|
-
* A minimalistic JavaScript reimplementation of the [Jinja](https://github.com/pallets/jinja) templating engine,
|
|
577
|
-
* to support the chat templates. Special thanks to [Tyler Laceby](https://github.com/tlaceby) for his amazing
|
|
578
|
-
* ["Guide to Interpreters"](https://github.com/tlaceby/guide-to-interpreters-series) tutorial series,
|
|
579
|
-
* which provided the basis for this implementation.
|
|
580
|
-
*
|
|
581
|
-
* See the [Transformers documentation](https://huggingface.co/docs/transformers/main/en/chat_templating) for more information.
|
|
582
|
-
*
|
|
583
|
-
* @module index
|
|
584
|
-
*/
|
|
585
|
-
|
|
586
|
-
declare class EnvironmentEx extends Environment {
|
|
587
|
-
parent?: EnvironmentEx | undefined;
|
|
588
|
-
constructor(parent?: EnvironmentEx | undefined);
|
|
589
|
-
assign(items: Record<string, unknown>): void;
|
|
590
|
-
clear(): void;
|
|
591
|
-
}
|
|
592
|
-
declare class Template {
|
|
593
|
-
parsed: Program;
|
|
594
|
-
static global: EnvironmentEx;
|
|
595
|
-
/**
|
|
596
|
-
* @param {string} template The template string
|
|
597
|
-
*/
|
|
598
|
-
constructor(template: string, options?: PreprocessOptions);
|
|
599
|
-
render(items?: Record<string, unknown>): string;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
declare class HfPromptTemplate extends PromptTemplate {
|
|
603
|
-
compiledTemplate: Template;
|
|
604
|
-
static isTemplate(templateOpt: PromptTemplateOptions | string): boolean;
|
|
605
|
-
getVariables(template?: Template): string[];
|
|
606
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
607
|
-
_format(data: Record<string, any>): string;
|
|
608
|
-
}
|
|
609
|
-
declare function createHfValueFunc(fn: Function): (_data: any) => Function;
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Type that represents a node in a parsed format string. It can be either
|
|
613
|
-
* a literal text or a variable name.
|
|
614
|
-
*/
|
|
615
|
-
type FStringPromptTemplateNode = {
|
|
616
|
-
type: "literal";
|
|
617
|
-
text: string;
|
|
618
|
-
} | {
|
|
619
|
-
type: "variable";
|
|
620
|
-
name: string;
|
|
621
|
-
};
|
|
622
|
-
/**
|
|
623
|
-
* Type that represents a function that takes a template string and
|
|
624
|
-
* returns an array of `ParsedFStringNode`.
|
|
625
|
-
*
|
|
626
|
-
* extract from langchain.js/langchain-core/src/prompts/template.ts
|
|
627
|
-
*/
|
|
628
|
-
declare function parseFString(template: string): FStringPromptTemplateNode[];
|
|
629
|
-
/**
|
|
630
|
-
* Type that represents a function that takes a template string and a set
|
|
631
|
-
* of input values, and returns a string where all variables in the
|
|
632
|
-
* template have been replaced with their corresponding values.
|
|
633
|
-
*/
|
|
634
|
-
declare function interpolateFString(nodes: FStringPromptTemplateNode[], values: Record<string, any>): string;
|
|
635
|
-
|
|
636
|
-
declare class FStringPromptTemplate extends PromptTemplate {
|
|
637
|
-
compiledTemplate: FStringPromptTemplateNode[];
|
|
638
|
-
static isTemplate(templateOpt: PromptTemplateOptions | string): boolean;
|
|
639
|
-
getVariables(template?: FStringPromptTemplateNode[]): string[];
|
|
640
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
641
|
-
_format(data: Record<string, any>): string;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
declare class GolangPromptTemplate extends PromptTemplate {
|
|
645
|
-
static isTemplate(templateOpt: PromptTemplateOptions | string): boolean | undefined;
|
|
646
|
-
getVariables(template: string): string[];
|
|
647
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
648
|
-
_format(data: Record<string, any>): string;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
declare class EnvPromptTemplate extends PromptTemplate {
|
|
652
|
-
static isTemplate(templateOpt: PromptTemplateOptions | string): boolean;
|
|
653
|
-
getVariables(template?: string): string[];
|
|
654
|
-
_initialize(options?: PromptTemplateOptions): void;
|
|
655
|
-
_format(data: Record<string, any>): string;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
218
|
declare function sortedValues<T>(values: Record<string, T>): T[];
|
|
659
|
-
interface FewShotPromptTemplateOptions<T = any> extends
|
|
219
|
+
interface FewShotPromptTemplateOptions<T = any> extends StringTemplateOptions {
|
|
660
220
|
/**
|
|
661
221
|
* The few shot examples to use in the prompt.
|
|
662
222
|
*/
|
|
@@ -664,7 +224,7 @@ interface FewShotPromptTemplateOptions<T = any> extends PromptTemplateOptions {
|
|
|
664
224
|
/**
|
|
665
225
|
* An {@link PromptTemplate} used to format a single example.
|
|
666
226
|
*/
|
|
667
|
-
examplePrompt:
|
|
227
|
+
examplePrompt: StringTemplate | StringTemplateOptions;
|
|
668
228
|
/**
|
|
669
229
|
* String separator used to join the prefix, the examples, and suffix.
|
|
670
230
|
*/
|
|
@@ -680,9 +240,9 @@ interface FewShotPromptTemplateOptions<T = any> extends PromptTemplateOptions {
|
|
|
680
240
|
*/
|
|
681
241
|
suffix?: string;
|
|
682
242
|
}
|
|
683
|
-
declare class FewShotPromptTemplate<T = any> extends
|
|
243
|
+
declare class FewShotPromptTemplate<T = any> extends StringTemplate {
|
|
684
244
|
examples: PromptExamples<T>;
|
|
685
|
-
examplePrompt:
|
|
245
|
+
examplePrompt: StringTemplate | undefined;
|
|
686
246
|
suffix: string;
|
|
687
247
|
exampleSeparator: string;
|
|
688
248
|
prefix: string;
|
|
@@ -693,103 +253,6 @@ declare class FewShotPromptTemplate<T = any> extends PromptTemplate {
|
|
|
693
253
|
toJSON(options?: this): FewShotPromptTemplateOptions<T>;
|
|
694
254
|
}
|
|
695
255
|
|
|
696
|
-
/**
|
|
697
|
-
* Parse and interpolate template
|
|
698
|
-
* @param str golang style template
|
|
699
|
-
* @param variables object of variables to insert
|
|
700
|
-
*/
|
|
701
|
-
declare function interpolateGolangTemplate(str: string, variables: Record<string, any>, initVars?: boolean): string;
|
|
702
|
-
|
|
703
|
-
declare function getEnvVairables(value: string): string[];
|
|
704
|
-
declare function interpolateEnv(value: string, processEnv: Record<string, any>, parsed?: Record<string, any>): any;
|
|
705
|
-
/**
|
|
706
|
-
* Expand environment variables in the parsed object
|
|
707
|
-
* @param options.processEnv Specify an object to write your secrets to. Defaults to `process.env` environment variables.
|
|
708
|
-
* @param options.parsed Specify an object to provide the value of environment variables.
|
|
709
|
-
*
|
|
710
|
-
* Follows these rules to handle environment variable expansion:
|
|
711
|
-
*
|
|
712
|
-
* 1. Simple Variable Expansion: If a string contains `$KEY`, it will be replaced by the value of the environment variable named `KEY`.
|
|
713
|
-
* 2. Braced Variable Expansion: When a string contains `${KEY}`, it also looks up the environment variable named `KEY`.
|
|
714
|
-
* This syntax is typically used to disambiguate variable names that contain special characters.
|
|
715
|
-
* 3. Escaped Dollar Sign: If you want to include a literal `$` followed by a variable name, you can escape it with a backslash (`\$KEY`).
|
|
716
|
-
* This ensures the `$` character is treated as part of the literal string rather than a variable reference.
|
|
717
|
-
* 4. Default Value: In the case of `${KEY:-default}` or `${KEY-default}`, the engine first tries to expand the KEY environment variable.
|
|
718
|
-
* If there's no such environment variable, it will use default as the fallback value.
|
|
719
|
-
*
|
|
720
|
-
* @example
|
|
721
|
-
* const myEnv = {}
|
|
722
|
-
* const env = {
|
|
723
|
-
* processEnv: myEnv,
|
|
724
|
-
* parsed: {
|
|
725
|
-
* WORD: 'World',
|
|
726
|
-
* HELLO: 'Hello ${WORD}'
|
|
727
|
-
* }
|
|
728
|
-
* }
|
|
729
|
-
* expandEnv.expand(env)
|
|
730
|
-
*
|
|
731
|
-
* console.log(myEnv.HELLO) // Hello World
|
|
732
|
-
* console.log(process.env.HELLO) // undefined
|
|
733
|
-
*/
|
|
734
|
-
declare function expandEnv(options: DotenvExpandOptions): DotenvExpandOptions;
|
|
735
|
-
/**
|
|
736
|
-
* Expands environment variables in an object/array or string.
|
|
737
|
-
*
|
|
738
|
-
* This function replaces placeholders like `${VAR}` in strings and recursively
|
|
739
|
-
* processes objects and arrays with environment variable references.
|
|
740
|
-
*
|
|
741
|
-
* @param obj - The object/array or string to be processed. Can be any value, but
|
|
742
|
-
* primarily designed for objects, array and strings.
|
|
743
|
-
* @param options - Configuration options:
|
|
744
|
-
* - processEnv: - An object to source environment variables from, defaults to `process.env`.
|
|
745
|
-
* - parsed: - Specify an object to provide the value of environment variables.
|
|
746
|
-
* @returns - Returns the expanded object or string.
|
|
747
|
-
*
|
|
748
|
-
* @example
|
|
749
|
-
* const obj = {
|
|
750
|
-
* name: 'MyApp',
|
|
751
|
-
* envVar: '${ENV_VAR_NAME}',
|
|
752
|
-
* config: {
|
|
753
|
-
* url: 'http://${HOST}:${PORT}'
|
|
754
|
-
* },
|
|
755
|
-
* list: ['item1', '${ITEM2}']
|
|
756
|
-
* };
|
|
757
|
-
* // the expandedObj will have the actual values instead of placeholders.
|
|
758
|
-
* const expandedObj = expandObjEnv(obj, { processEnv: myCustomEnv }); // Assuming 'ENV_VAR_NAME' is defined as 'Production' and 'HOST', 'PORT', 'ITEM2' are set,
|
|
759
|
-
*
|
|
760
|
-
*/
|
|
761
|
-
declare function expandObjEnv(obj: any, options?: DotenvExpandOptions, parsedObjs?: WeakSet<any>): any;
|
|
762
|
-
interface DotenvPopulateInput {
|
|
763
|
-
[name: string]: string | undefined;
|
|
764
|
-
}
|
|
765
|
-
interface DotenvParseInput {
|
|
766
|
-
[name: string]: string | undefined;
|
|
767
|
-
}
|
|
768
|
-
interface DotenvParseOutput {
|
|
769
|
-
[name: string]: string | undefined;
|
|
770
|
-
}
|
|
771
|
-
interface DotenvExpandOptions {
|
|
772
|
-
error?: Error;
|
|
773
|
-
/**
|
|
774
|
-
* Default: `process.env`
|
|
775
|
-
*
|
|
776
|
-
* Specify an object to write your secrets to. Defaults to process.env environment variables.
|
|
777
|
-
*
|
|
778
|
-
* example: `const processEnv = {}; require('dotenv').config({ processEnv: processEnv })`
|
|
779
|
-
*/
|
|
780
|
-
processEnv?: DotenvPopulateInput;
|
|
781
|
-
/**
|
|
782
|
-
* Default: `object`
|
|
783
|
-
*
|
|
784
|
-
* Object coming from dotenv's parsed result.
|
|
785
|
-
*/
|
|
786
|
-
parsed?: DotenvParseInput;
|
|
787
|
-
}
|
|
788
|
-
interface DotenvExpandOutput {
|
|
789
|
-
error?: Error;
|
|
790
|
-
parsed?: DotenvParseOutput;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
256
|
interface SplitSentenceOptions {
|
|
794
257
|
best?: boolean;
|
|
795
258
|
completeSentence?: boolean;
|
|
@@ -1045,93 +508,6 @@ interface HashAlgoParams {
|
|
|
1045
508
|
declare function hashStream(stream: ReadableStream, { hashAlgo, seed, outputType }?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
1046
509
|
declare function hash(value: IDataType, { hashAlgo, seed, outputType }?: HashAlgoParams): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
1047
510
|
|
|
1048
|
-
/**
|
|
1049
|
-
* Regular expression pattern for reserved characters in a filename.
|
|
1050
|
-
* do not use /g global option here: when the regex is executed multiple times, it will always begin where it left off last time.
|
|
1051
|
-
*/
|
|
1052
|
-
declare const FilenameReservedRegex: RegExp;
|
|
1053
|
-
/**
|
|
1054
|
-
* Regular expression pattern for reserved names on Windows systems.
|
|
1055
|
-
*/
|
|
1056
|
-
declare const WindowsReservedNameRegex: RegExp;
|
|
1057
|
-
/**
|
|
1058
|
-
* Returns a new regular expression instance for reserved filename characters with the 'g' flag.
|
|
1059
|
-
* use this to reset the with global option
|
|
1060
|
-
* @returns A compiled regular expression for reserved filename characters.
|
|
1061
|
-
*/
|
|
1062
|
-
declare function filenameReservedRegex(): RegExp;
|
|
1063
|
-
/**
|
|
1064
|
-
* Returns a new regular expression instance for control characters in a filename with the 'g' flag.
|
|
1065
|
-
* @returns A compiled regular expression for control characters in a filename.
|
|
1066
|
-
*/
|
|
1067
|
-
declare function reControlCharsRegex(): RegExp;
|
|
1068
|
-
/**
|
|
1069
|
-
* Validates if a given string is a valid filename.
|
|
1070
|
-
* @param {string} filename - The filename to be validated.
|
|
1071
|
-
* @returns True if the filename is valid, false otherwise.
|
|
1072
|
-
* @throws {TypeError} If the input is not a string.
|
|
1073
|
-
* @example
|
|
1074
|
-
* isValidFilename('myFile.txt'); // Returns true
|
|
1075
|
-
* isValidFilename('my<file.txt'); // Returns false
|
|
1076
|
-
*/
|
|
1077
|
-
declare function isValidFilename(filename: string): boolean | "";
|
|
1078
|
-
/**
|
|
1079
|
-
* Validates whether the given filepath is valid.
|
|
1080
|
-
* @param filepath - The filepath to be checked, represented as a string.
|
|
1081
|
-
* @returns A boolean indicating whether the filepath is valid. Returns true if valid; false otherwise.
|
|
1082
|
-
*/
|
|
1083
|
-
declare function isValidFilepath(filepath: string): boolean;
|
|
1084
|
-
interface SanitizeFilenameOptions {
|
|
1085
|
-
replacement?: string;
|
|
1086
|
-
maxLength?: number;
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* Sanitizes a given filename by replacing invalid characters with a specified replacement character or a default.
|
|
1090
|
-
* @param filename - The filename to sanitize, represented as a string.
|
|
1091
|
-
* @param options - An optional object containing configuration options:
|
|
1092
|
-
* - `replacement` {string} - The character to replace invalid characters with. Default is '!'. Cannot contain reserved filename characters.
|
|
1093
|
-
* - `maxLength` {number} - The maximum length of the sanitized filename. Default is `MAX_FILENAME_LENGTH`.
|
|
1094
|
-
* @returns The sanitized filename.
|
|
1095
|
-
* @throws {Error} - If the `replacement` contains reserved filename characters or control characters.
|
|
1096
|
-
*/
|
|
1097
|
-
declare function sanitizeFilename(filename: string, options?: SanitizeFilenameOptions): string;
|
|
1098
|
-
/**
|
|
1099
|
-
* Sanitizes each part of a file path and reassembles it, ensuring the path is valid according to provided options.
|
|
1100
|
-
* @param filepath - The file path to sanitize, represented as a string.
|
|
1101
|
-
* @param options - Optional settings for sanitization, extending `SanitizeFilenameOptions`. Allows customization of replacement characters and maximum filename length.
|
|
1102
|
-
* @returns The sanitized file path as a string.
|
|
1103
|
-
*/
|
|
1104
|
-
declare function sanitizeFilepath(filepath: string, options?: SanitizeFilenameOptions): string;
|
|
1105
|
-
/**
|
|
1106
|
-
* Retrieves multi-level file extension
|
|
1107
|
-
* @param filename The file name
|
|
1108
|
-
* @param level The level, default is 1, indicating the number of extension levels to retrieve
|
|
1109
|
-
* @returns Returns a concatenated string of multiple extensions, or an empty string if no extension is found
|
|
1110
|
-
*/
|
|
1111
|
-
declare function getMultiLevelExtname(filename: string, level?: number): string;
|
|
1112
|
-
/**
|
|
1113
|
-
* Calculates the level of an extension name.
|
|
1114
|
-
*
|
|
1115
|
-
* The level represents the number of dots ('.') in the extension name, excluding the first dot which separates
|
|
1116
|
-
* the base filename from the extension. For example, the level of ".txt" is 1, and the level of ".tar.gz" is 2.
|
|
1117
|
-
*
|
|
1118
|
-
* @param extName - The extension name to analyze. It should start with a dot ('.').
|
|
1119
|
-
* @returns The level of the extension name, which is the count of dots minus one.
|
|
1120
|
-
*
|
|
1121
|
-
* @example
|
|
1122
|
-
* ```typescript
|
|
1123
|
-
* // Returns 0
|
|
1124
|
-
* extNameLevel("no-file-ext");
|
|
1125
|
-
*
|
|
1126
|
-
* // Returns 2
|
|
1127
|
-
* extNameLevel(".tar.gz");
|
|
1128
|
-
*
|
|
1129
|
-
* // Returns 1
|
|
1130
|
-
* extNameLevel(".json5");
|
|
1131
|
-
* ```
|
|
1132
|
-
*/
|
|
1133
|
-
declare function extNameLevel(extName: string): number;
|
|
1134
|
-
|
|
1135
511
|
/**
|
|
1136
512
|
* Checks if the provided model name matches the given rule.
|
|
1137
513
|
* @param modelName The name of the model to check.
|
|
@@ -1235,6 +611,7 @@ declare function decodeCharset(result: Buffer, encoding?: BufferEncoding): strin
|
|
|
1235
611
|
* @param dir - A single directory path or an array of directory paths to start the search from.
|
|
1236
612
|
* @param options.isFileMatched - An optional callback that determines whether a file should be included in the result.
|
|
1237
613
|
* @param options.signal - An optional signal to abort the operation.
|
|
614
|
+
* @param options.resolveSymlinks - Whether to resolve symbolic links to their real paths. Defaults to true.
|
|
1238
615
|
* @returns An array of file paths that match the criteria.
|
|
1239
616
|
*
|
|
1240
617
|
* @example
|
|
@@ -1247,6 +624,7 @@ declare function readFilenamesRecursiveSync(dir: string | string[], options?: {
|
|
|
1247
624
|
isFileMatched?: (filepath: string, file: fs.Dirent | fs.Stats) => boolean;
|
|
1248
625
|
signal?: AbortSignal;
|
|
1249
626
|
level?: number;
|
|
627
|
+
resolveSymlinks?: boolean;
|
|
1250
628
|
}): string[];
|
|
1251
629
|
/**
|
|
1252
630
|
* Resolves the real file path, handling symbolic links.
|
|
@@ -1275,10 +653,6 @@ declare function getFileMetaInfo(filepath: string): Promise<IFileMetaInfo>;
|
|
|
1275
653
|
declare function getHashAlgoBySize(size: number): HashAlgorithm;
|
|
1276
654
|
declare function detectCharset(content: Buffer | string, options?: any): string;
|
|
1277
655
|
|
|
1278
|
-
declare function registerYamlTag(tags: any): void;
|
|
1279
|
-
declare function parseYaml(content: string, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
|
|
1280
|
-
declare function stringifyYaml(content: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions): string;
|
|
1281
|
-
|
|
1282
656
|
interface ConfigFilesFilter {
|
|
1283
657
|
after?: {
|
|
1284
658
|
[filepath: string]: number;
|
|
@@ -1950,7 +1324,7 @@ declare function isSameString(str1: string, str2: string): boolean;
|
|
|
1950
1324
|
declare const DEFAULT_CONFIG_NAME = ".ai";
|
|
1951
1325
|
type Config = any;
|
|
1952
1326
|
declare function loadConfigFile(filename: string, searchPaths?: string[]): any;
|
|
1953
|
-
declare function expandConfig(config: any, defaultConfig
|
|
1327
|
+
declare function expandConfig(config: any, defaultConfig?: any): any;
|
|
1954
1328
|
declare function loadConfig(filename: string, config: Config): any;
|
|
1955
1329
|
declare function loadAIConfig(config: Config): any;
|
|
1956
1330
|
declare function getXDGConfigs(config: Config): {
|
|
@@ -1991,4 +1365,4 @@ declare function shutdown(signalOrEvent?: string | number, exitCode?: number | s
|
|
|
1991
1365
|
declare function beforeShutdown(listener: BeforeShutdownListener): BeforeShutdownListener | undefined;
|
|
1992
1366
|
declare function initShutdown(): void;
|
|
1993
1367
|
|
|
1994
|
-
export { AIArgProcessor, type AIChatAssistantMessageParam, type AIChatContentPart, type AIChatContentPartImage, type AIChatContentPartText, type AIChatMessageParam, type AIChatMessageParamBase, type AIChatMessageToolCall, type AIChatRole, AIChatRoles, type AIChatSystemMessageParam, type AIChatToolChoiceFuncObject, type AIChatToolChoiceObject, type AIChatToolChoiceParam, type AIChatToolFunc, type AIChatToolFuncParam, type AIChatToolMessageParam, type AIChatToolParam, type AIChatToolTypeObject, type AIChatUserMessageParam, type AIChoiceConfig, type AIMessageType, AIMessageTypes, AIModelNameRules, type AIResult, AIStream, type AIStreamParser, type AIStreamParserOptions, type AITextGenerationFinishReason, AITextGenerationFinishReasons, AsyncTaskId, type BeforeShutdownListener, ChoiceArgProcessor, DEFAULT_CONFIG_NAME,
|
|
1368
|
+
export { AIArgProcessor, type AIChatAssistantMessageParam, type AIChatContentPart, type AIChatContentPartImage, type AIChatContentPartText, type AIChatMessageParam, type AIChatMessageParamBase, type AIChatMessageToolCall, type AIChatRole, AIChatRoles, type AIChatSystemMessageParam, type AIChatToolChoiceFuncObject, type AIChatToolChoiceObject, type AIChatToolChoiceParam, type AIChatToolFunc, type AIChatToolFuncParam, type AIChatToolMessageParam, type AIChatToolParam, type AIChatToolTypeObject, type AIChatUserMessageParam, type AIChoiceConfig, type AIMessageType, AIMessageTypes, AIModelNameRules, type AIResult, AIStream, type AIStreamParser, type AIStreamParserOptions, type AITextGenerationFinishReason, AITextGenerationFinishReasons, AsyncTaskId, type BeforeShutdownListener, ChoiceArgProcessor, DEFAULT_CONFIG_NAME, EventBusName, type EventErrorListenerFn, type EventListenerFn, EventName, FewShotPromptTemplate, type FewShotPromptTemplateOptions, type HashAlgoParams, HashAlgorithm, type IFileMetaInfo, type IReadTextFileChunksOptions, type ITruncateToTokenLimitOptions, IntSet, type JsonFilter, LLM_TOKENIZER_NAMES, LLM_TOKENIZER_NAMES_MAP, ObjectArgsToArgsInfo, type ParseObjectArgumentOptions, PromptExampleSelector, type PromptExampleSelectorOptions, type PromptExamples, RStreamErrCode, ReadableStreamError, type ReplacePlacehoderOptions, ResponseRStreamErrCode, SHUTDOWN_SIGNALS, type SectionStringOptions, SignalGate, type SplitSentenceOptions, type StreamCallbacksAndOptions, TemplateArgProcessor, YamlTypeBaseObject, assignDirs, backendEventable, base32768, beforeShutdown, completeSentences, concatText, countLLMTokens, countRegexMatches, createCallbacksTransformer, createEmptyReadableStream, createEndWithRepetitionDetector, createEventStreamTransformer, createYamlObjectTag, dateToText, decodeCharset, detectCharset, encodeLLMTokens, ensureQuoted, expandConfig, expandPath, fileIsExists, filterValidFnScope, findIndexNonEmptyFrom, formatTextWithSpace, getAllEnumKeys, getConfigFileNames, getConfigs, getFileMetaInfo, getHashAlgoBySize, getKeysPath, getLLMTokenizer, getPackageDir, getRealFilepath, getResponseErrorReadableStream, getXDGConfigs, hasDirectoryIn, hash, hashFile, hashStream, initShutdown, isLangUsingSpaces, isListItemString, isModelNameMatched, isPunctuationChar, isQuoted, isRegExp, isSameString, isSectionString, isSentenceEnding, isSepLineString, isStrWrapped, isSubdirectory, isTitleString, isWebStream, jsonFilterToWhere, jsonToMarkdownStr, loadAIConfig, loadConfig, loadConfigFile, loadFileFromPaths, loadTextFromPaths, matchUrlProtocol, memoize, messagesToText, paramsSizeToScaleStr, parseCommand, parseJsJson, parseJsJsonSimpleSync, parseObjectArgInfo, parseObjectArgumentInfos, parseObjectArguments, parseObjectArgumentsAsArgInfos, quoteStr, readFilenamesRecursiveSync, readTextFileChunks, readTextFileChunksEx, readableFromAsyncIterable, removeMarkdownBold, removeMarkdownBoldAndItalic, removeMarkdownItalic, replaceWithPlaceholder, restoreFromPlacehoders, saveConfigFile, scaleStrToParamsSize, shutdown, simplifyObjectArguments, sortedValues, splitChunks, splitParagraph, splitSentence, stripConsoleColor, textToDate, toDateTime, trimStartOfStreamHelper, truncTo, truncateByToken, truncateToTokenLimit, truncateToTokenLimitEx, uuid, wait, xxhash, xxhash32, xxhash64, xxhashAsStr };
|