@isdk/ai-tool 0.5.8 → 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-YVFGQB4L.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
|
@@ -6,7 +6,34 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: EnvPromptTemplate
|
|
8
8
|
|
|
9
|
-
Defined in:
|
|
9
|
+
Defined in: packages/template-engines/dist/index.d.ts:623
|
|
10
|
+
|
|
11
|
+
The `StringTemplate` class is a versatile template engine that supports dynamic template creation,
|
|
12
|
+
formatting, and partial data processing. It extends the `BaseFactory` class and provides methods
|
|
13
|
+
for handling template strings, validating input variables, and managing template configurations.
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { StringTemplate } from './template';
|
|
19
|
+
|
|
20
|
+
// Register a custom template class
|
|
21
|
+
class CustomTemplate extends StringTemplate {
|
|
22
|
+
_initialize(options?: StringTemplateOptions): void {}
|
|
23
|
+
_format(data: Record<string, any>): string {
|
|
24
|
+
return `Formatted: ${data.text}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
StringTemplate.register(CustomTemplate);
|
|
28
|
+
|
|
29
|
+
// Create a new instance with a custom template format
|
|
30
|
+
const template = new StringTemplate("{{text}}", { templateFormat: "Custom" });
|
|
31
|
+
console.log(template instanceof CustomTemplate); // Output: true
|
|
32
|
+
|
|
33
|
+
// Format the template with data
|
|
34
|
+
const result = await template.format({ text: "Hello World" });
|
|
35
|
+
console.log(result); // Output: "Formatted: Hello World"
|
|
36
|
+
```
|
|
10
37
|
|
|
11
38
|
## Extends
|
|
12
39
|
|
|
@@ -18,22 +45,38 @@ Defined in: [packages/ai-tool/src/utils/prompt/env-prompt-template.ts:5](https:/
|
|
|
18
45
|
|
|
19
46
|
> **new EnvPromptTemplate**(`template`?, `options`?): [`EnvPromptTemplate`](EnvPromptTemplate.md)
|
|
20
47
|
|
|
21
|
-
Defined in:
|
|
48
|
+
Defined in: packages/template-engines/dist/index.d.ts:162
|
|
49
|
+
|
|
50
|
+
Initializes a new instance of the `StringTemplate` class.
|
|
22
51
|
|
|
23
52
|
#### Parameters
|
|
24
53
|
|
|
25
54
|
##### template?
|
|
26
55
|
|
|
56
|
+
Either a template string or an options object.
|
|
57
|
+
|
|
27
58
|
`string` | [`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
28
59
|
|
|
29
60
|
##### options?
|
|
30
61
|
|
|
31
62
|
[`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
32
63
|
|
|
64
|
+
Additional configuration options for the template.
|
|
65
|
+
|
|
33
66
|
#### Returns
|
|
34
67
|
|
|
35
68
|
[`EnvPromptTemplate`](EnvPromptTemplate.md)
|
|
36
69
|
|
|
70
|
+
#### Example
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const template = new StringTemplate("{{text}}", {
|
|
74
|
+
templateFormat: "Test",
|
|
75
|
+
inputVariables: ['text']
|
|
76
|
+
});
|
|
77
|
+
console.log(template instanceof TestStringTemplate); // Output: true
|
|
78
|
+
```
|
|
79
|
+
|
|
37
80
|
#### Inherited from
|
|
38
81
|
|
|
39
82
|
[`PromptTemplate`](PromptTemplate.md).[`constructor`](PromptTemplate.md#constructors)
|
|
@@ -44,7 +87,9 @@ Defined in: [packages/ai-tool/src/utils/prompt/prompt-template.ts:69](https://gi
|
|
|
44
87
|
|
|
45
88
|
> **compiledTemplate**: `any`
|
|
46
89
|
|
|
47
|
-
Defined in:
|
|
90
|
+
Defined in: packages/template-engines/dist/index.d.ts:53
|
|
91
|
+
|
|
92
|
+
Declares the compiled template instance.
|
|
48
93
|
|
|
49
94
|
#### Inherited from
|
|
50
95
|
|
|
@@ -56,7 +101,9 @@ Defined in: [packages/ai-tool/src/utils/prompt/prompt-template.ts:21](https://gi
|
|
|
56
101
|
|
|
57
102
|
> **data**: `undefined` \| `Record`\<`string`, `any`\>
|
|
58
103
|
|
|
59
|
-
Defined in:
|
|
104
|
+
Defined in: packages/template-engines/dist/index.d.ts:65
|
|
105
|
+
|
|
106
|
+
Declares the data object used for template interpolation.
|
|
60
107
|
|
|
61
108
|
#### Inherited from
|
|
62
109
|
|
|
@@ -68,7 +115,9 @@ Defined in: [packages/ai-tool/src/utils/prompt/prompt-template.ts:24](https://gi
|
|
|
68
115
|
|
|
69
116
|
> **inputVariables**: `undefined` \| `string`[]
|
|
70
117
|
|
|
71
|
-
Defined in:
|
|
118
|
+
Defined in: packages/template-engines/dist/index.d.ts:69
|
|
119
|
+
|
|
120
|
+
Declares the list of input variables expected by the template.
|
|
72
121
|
|
|
73
122
|
#### Inherited from
|
|
74
123
|
|
|
@@ -80,7 +129,9 @@ Defined in: [packages/ai-tool/src/utils/prompt/prompt-template.ts:25](https://gi
|
|
|
80
129
|
|
|
81
130
|
> **template**: `string`
|
|
82
131
|
|
|
83
|
-
Defined in:
|
|
132
|
+
Defined in: packages/template-engines/dist/index.d.ts:57
|
|
133
|
+
|
|
134
|
+
Declares the raw template string.
|
|
84
135
|
|
|
85
136
|
#### Inherited from
|
|
86
137
|
|
|
@@ -92,7 +143,9 @@ Defined in: [packages/ai-tool/src/utils/prompt/prompt-template.ts:22](https://gi
|
|
|
92
143
|
|
|
93
144
|
> **templateFormat**: `undefined` \| `string`
|
|
94
145
|
|
|
95
|
-
Defined in:
|
|
146
|
+
Defined in: packages/template-engines/dist/index.d.ts:61
|
|
147
|
+
|
|
148
|
+
Declares the format of the template (e.g., 'default').
|
|
96
149
|
|
|
97
150
|
#### Inherited from
|
|
98
151
|
|
|
@@ -262,7 +315,9 @@ The Root Factory class
|
|
|
262
315
|
|
|
263
316
|
> **\_format**(`data`): `string`
|
|
264
317
|
|
|
265
|
-
Defined in:
|
|
318
|
+
Defined in: packages/template-engines/dist/index.d.ts:627
|
|
319
|
+
|
|
320
|
+
Placeholder method for formatting the template. Must be implemented by subclasses.
|
|
266
321
|
|
|
267
322
|
#### Parameters
|
|
268
323
|
|
|
@@ -270,10 +325,14 @@ Defined in: [packages/ai-tool/src/utils/prompt/env-prompt-template.ts:35](https:
|
|
|
270
325
|
|
|
271
326
|
`Record`\<`string`, `any`\>
|
|
272
327
|
|
|
328
|
+
The data object used for interpolation.
|
|
329
|
+
|
|
273
330
|
#### Returns
|
|
274
331
|
|
|
275
332
|
`string`
|
|
276
333
|
|
|
334
|
+
A formatted string or a promise resolving to the formatted string.
|
|
335
|
+
|
|
277
336
|
#### Overrides
|
|
278
337
|
|
|
279
338
|
[`PromptTemplate`](PromptTemplate.md).[`_format`](PromptTemplate.md#_format)
|
|
@@ -284,7 +343,9 @@ Defined in: [packages/ai-tool/src/utils/prompt/env-prompt-template.ts:35](https:
|
|
|
284
343
|
|
|
285
344
|
> **\_initialize**(`options`?): `void`
|
|
286
345
|
|
|
287
|
-
Defined in:
|
|
346
|
+
Defined in: packages/template-engines/dist/index.d.ts:626
|
|
347
|
+
|
|
348
|
+
Placeholder method for initializing the template. Must be implemented by subclasses.
|
|
288
349
|
|
|
289
350
|
#### Parameters
|
|
290
351
|
|
|
@@ -292,6 +353,8 @@ Defined in: [packages/ai-tool/src/utils/prompt/env-prompt-template.ts:27](https:
|
|
|
292
353
|
|
|
293
354
|
[`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
294
355
|
|
|
356
|
+
Configuration options for initialization.
|
|
357
|
+
|
|
295
358
|
#### Returns
|
|
296
359
|
|
|
297
360
|
`void`
|
|
@@ -306,9 +369,9 @@ Defined in: [packages/ai-tool/src/utils/prompt/env-prompt-template.ts:27](https:
|
|
|
306
369
|
|
|
307
370
|
> **filterData**(`data`): `Record`\<`string`, `any`\>
|
|
308
371
|
|
|
309
|
-
Defined in:
|
|
372
|
+
Defined in: packages/template-engines/dist/index.d.ts:147
|
|
310
373
|
|
|
311
|
-
|
|
374
|
+
Filters the input data to include only the specified input variables.
|
|
312
375
|
|
|
313
376
|
#### Parameters
|
|
314
377
|
|
|
@@ -316,10 +379,24 @@ Validate/filter the data in inputVariables
|
|
|
316
379
|
|
|
317
380
|
`Record`\<`string`, `any`\>
|
|
318
381
|
|
|
382
|
+
The data object to validate and filter.
|
|
383
|
+
|
|
319
384
|
#### Returns
|
|
320
385
|
|
|
321
386
|
`Record`\<`string`, `any`\>
|
|
322
387
|
|
|
388
|
+
The filtered data object containing only the allowed keys.
|
|
389
|
+
|
|
390
|
+
#### Example
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
const template = new StringTemplate({
|
|
394
|
+
inputVariables: ['name']
|
|
395
|
+
});
|
|
396
|
+
const filteredData = template.filterData({ name: "Alice", age: 30 });
|
|
397
|
+
console.log(filteredData); // Output: { name: "Alice" }
|
|
398
|
+
```
|
|
399
|
+
|
|
323
400
|
#### Inherited from
|
|
324
401
|
|
|
325
402
|
[`PromptTemplate`](PromptTemplate.md).[`filterData`](PromptTemplate.md#filterdata)
|
|
@@ -330,7 +407,9 @@ Validate/filter the data in inputVariables
|
|
|
330
407
|
|
|
331
408
|
> **format**(`data`?): `Promise`\<`string`\>
|
|
332
409
|
|
|
333
|
-
Defined in:
|
|
410
|
+
Defined in: packages/template-engines/dist/index.d.ts:194
|
|
411
|
+
|
|
412
|
+
Formats the template using the provided data, supporting asynchronous processing.
|
|
334
413
|
|
|
335
414
|
#### Parameters
|
|
336
415
|
|
|
@@ -338,10 +417,25 @@ Defined in: [packages/ai-tool/src/utils/prompt/prompt-template.ts:109](https://g
|
|
|
338
417
|
|
|
339
418
|
`Record`\<`string`, `any`\>
|
|
340
419
|
|
|
420
|
+
The data object used for interpolation.
|
|
421
|
+
|
|
341
422
|
#### Returns
|
|
342
423
|
|
|
343
424
|
`Promise`\<`string`\>
|
|
344
425
|
|
|
426
|
+
A promise that resolves to the formatted template string.
|
|
427
|
+
|
|
428
|
+
#### Example
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
const template = new StringTemplate("{{text}}", {
|
|
432
|
+
templateFormat: "Test",
|
|
433
|
+
inputVariables: ['text']
|
|
434
|
+
});
|
|
435
|
+
const result = await template.format({ text: "Hello" });
|
|
436
|
+
console.log(result); // Output: "Hello"
|
|
437
|
+
```
|
|
438
|
+
|
|
345
439
|
#### Inherited from
|
|
346
440
|
|
|
347
441
|
[`PromptTemplate`](PromptTemplate.md).[`format`](PromptTemplate.md#format)
|
|
@@ -350,15 +444,15 @@ Defined in: [packages/ai-tool/src/utils/prompt/prompt-template.ts:109](https://g
|
|
|
350
444
|
|
|
351
445
|
### getVariables()
|
|
352
446
|
|
|
353
|
-
> **getVariables**(`template
|
|
447
|
+
> **getVariables**(`template`?): `string`[]
|
|
354
448
|
|
|
355
|
-
Defined in:
|
|
449
|
+
Defined in: packages/template-engines/dist/index.d.ts:625
|
|
356
450
|
|
|
357
451
|
#### Parameters
|
|
358
452
|
|
|
359
|
-
##### template
|
|
453
|
+
##### template?
|
|
360
454
|
|
|
361
|
-
`string`
|
|
455
|
+
`string`
|
|
362
456
|
|
|
363
457
|
#### Returns
|
|
364
458
|
|
|
@@ -368,13 +462,11 @@ Defined in: [packages/ai-tool/src/utils/prompt/env-prompt-template.ts:23](https:
|
|
|
368
462
|
|
|
369
463
|
### initialize()
|
|
370
464
|
|
|
371
|
-
>
|
|
465
|
+
> **initialize**(`options`?): `void`
|
|
372
466
|
|
|
373
|
-
Defined in:
|
|
374
|
-
|
|
375
|
-
**`Internal`**
|
|
467
|
+
Defined in: packages/template-engines/dist/index.d.ts:172
|
|
376
468
|
|
|
377
|
-
|
|
469
|
+
Initializes the template instance with the provided options.
|
|
378
470
|
|
|
379
471
|
#### Parameters
|
|
380
472
|
|
|
@@ -382,6 +474,8 @@ initialize instance method
|
|
|
382
474
|
|
|
383
475
|
[`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
384
476
|
|
|
477
|
+
Configuration options for initialization.
|
|
478
|
+
|
|
385
479
|
#### Returns
|
|
386
480
|
|
|
387
481
|
`void`
|
|
@@ -396,9 +490,10 @@ initialize instance method
|
|
|
396
490
|
|
|
397
491
|
> **partial**(`data`): [`PromptTemplate`](PromptTemplate.md)
|
|
398
492
|
|
|
399
|
-
Defined in:
|
|
493
|
+
Defined in: packages/template-engines/dist/index.d.ts:222
|
|
400
494
|
|
|
401
|
-
|
|
495
|
+
Creates a new `StringTemplate` instance with partially filled data.
|
|
496
|
+
This is useful for pre-filling some variables while leaving others to be filled later.
|
|
402
497
|
|
|
403
498
|
#### Parameters
|
|
404
499
|
|
|
@@ -406,13 +501,35 @@ it can make sense to "partial" a prompt template - eg pass in a subset of the re
|
|
|
406
501
|
|
|
407
502
|
`Record`\<`string`, `any`\>
|
|
408
503
|
|
|
409
|
-
|
|
504
|
+
The partial data to pre-fill in the new template.
|
|
410
505
|
|
|
411
506
|
#### Returns
|
|
412
507
|
|
|
413
508
|
[`PromptTemplate`](PromptTemplate.md)
|
|
414
509
|
|
|
415
|
-
|
|
510
|
+
A new `StringTemplate` instance with the partial data applied.
|
|
511
|
+
|
|
512
|
+
#### Example
|
|
513
|
+
|
|
514
|
+
```typescript
|
|
515
|
+
const template = new StringTemplate("{{role}}:{{text}}", {
|
|
516
|
+
templateFormat: "Test",
|
|
517
|
+
inputVariables: ['role', 'text']
|
|
518
|
+
});
|
|
519
|
+
const partialTemplate = template.partial({ role: "user" });
|
|
520
|
+
console.log(partialTemplate.data); // Output: { role: "user" }
|
|
521
|
+
const result = await partialTemplate.format({ text: "Hello" });
|
|
522
|
+
console.log(result); // Output: { role: "user", text: "Hello" }
|
|
523
|
+
|
|
524
|
+
// Example with a function
|
|
525
|
+
function getDate() {
|
|
526
|
+
return new Date();
|
|
527
|
+
}
|
|
528
|
+
const dateTemplate = template.partial({ date: getDate });
|
|
529
|
+
console.log(dateTemplate.data); // Output: { date: getDate }
|
|
530
|
+
const dateResult = await dateTemplate.format({ role: "user" });
|
|
531
|
+
console.log(dateResult.date instanceof Date); // Output: true
|
|
532
|
+
```
|
|
416
533
|
|
|
417
534
|
#### Inherited from
|
|
418
535
|
|
|
@@ -422,20 +539,38 @@ the new partial PromptTemplate instance
|
|
|
422
539
|
|
|
423
540
|
### toJSON()
|
|
424
541
|
|
|
425
|
-
> **toJSON**(`options
|
|
542
|
+
> **toJSON**(`options`?): [`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
543
|
+
|
|
544
|
+
Defined in: packages/template-engines/dist/index.d.ts:239
|
|
426
545
|
|
|
427
|
-
|
|
546
|
+
Serializes the `StringTemplate` instance into a JSON-compatible object.
|
|
428
547
|
|
|
429
548
|
#### Parameters
|
|
430
549
|
|
|
431
|
-
##### options
|
|
550
|
+
##### options?
|
|
432
551
|
|
|
433
|
-
[`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
552
|
+
[`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
553
|
+
|
|
554
|
+
Optional configuration for serialization.
|
|
434
555
|
|
|
435
556
|
#### Returns
|
|
436
557
|
|
|
437
558
|
[`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
438
559
|
|
|
560
|
+
A JSON-compatible object representing the template's state.
|
|
561
|
+
|
|
562
|
+
#### Example
|
|
563
|
+
|
|
564
|
+
```typescript
|
|
565
|
+
const template = new StringTemplate("{{text}}", {
|
|
566
|
+
templateFormat: "Test",
|
|
567
|
+
inputVariables: ['text']
|
|
568
|
+
});
|
|
569
|
+
const serialized = template.toJSON();
|
|
570
|
+
console.log(serialized);
|
|
571
|
+
// Output: { template: "{{text}}", templateFormat: "Test", inputVariables: ['text'] }
|
|
572
|
+
```
|
|
573
|
+
|
|
439
574
|
#### Inherited from
|
|
440
575
|
|
|
441
576
|
[`PromptTemplate`](PromptTemplate.md).[`toJSON`](PromptTemplate.md#tojson)
|
|
@@ -637,7 +772,9 @@ the forEach callback function
|
|
|
637
772
|
|
|
638
773
|
> `static` **format**(`options`): `Promise`\<`string`\>
|
|
639
774
|
|
|
640
|
-
Defined in:
|
|
775
|
+
Defined in: packages/template-engines/dist/index.d.ts:101
|
|
776
|
+
|
|
777
|
+
Formats a template using the provided options.
|
|
641
778
|
|
|
642
779
|
#### Parameters
|
|
643
780
|
|
|
@@ -645,10 +782,25 @@ Defined in: [packages/ai-tool/src/utils/prompt/prompt-template.ts:31](https://gi
|
|
|
645
782
|
|
|
646
783
|
[`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
647
784
|
|
|
785
|
+
Configuration options for the template.
|
|
786
|
+
|
|
648
787
|
#### Returns
|
|
649
788
|
|
|
650
789
|
`Promise`\<`string`\>
|
|
651
790
|
|
|
791
|
+
A promise that resolves to the formatted template string.
|
|
792
|
+
|
|
793
|
+
#### Example
|
|
794
|
+
|
|
795
|
+
```typescript
|
|
796
|
+
const result = await StringTemplate.format({
|
|
797
|
+
template: "{{text}}",
|
|
798
|
+
data: { text: "Hello" },
|
|
799
|
+
templateFormat: "Test"
|
|
800
|
+
});
|
|
801
|
+
console.log(result); // Output: "Hello"
|
|
802
|
+
```
|
|
803
|
+
|
|
652
804
|
#### Inherited from
|
|
653
805
|
|
|
654
806
|
[`PromptTemplate`](PromptTemplate.md).[`format`](PromptTemplate.md#format-2)
|
|
@@ -659,9 +811,9 @@ Defined in: [packages/ai-tool/src/utils/prompt/prompt-template.ts:31](https://gi
|
|
|
659
811
|
|
|
660
812
|
> `static` **formatIf**(`options`): `Promise`\<`undefined` \| `string`\>
|
|
661
813
|
|
|
662
|
-
Defined in:
|
|
814
|
+
Defined in: packages/template-engines/dist/index.d.ts:117
|
|
663
815
|
|
|
664
|
-
|
|
816
|
+
Formats a template if the provided options represent a valid template.
|
|
665
817
|
|
|
666
818
|
#### Parameters
|
|
667
819
|
|
|
@@ -669,13 +821,24 @@ If the given options.template is the template, perform formatting using that tem
|
|
|
669
821
|
|
|
670
822
|
[`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
671
823
|
|
|
672
|
-
|
|
824
|
+
Configuration options to check and format.
|
|
673
825
|
|
|
674
826
|
#### Returns
|
|
675
827
|
|
|
676
828
|
`Promise`\<`undefined` \| `string`\>
|
|
677
829
|
|
|
678
|
-
A
|
|
830
|
+
A promise that resolves to the formatted template string if valid; otherwise, undefined.
|
|
831
|
+
|
|
832
|
+
#### Example
|
|
833
|
+
|
|
834
|
+
```typescript
|
|
835
|
+
const result = await StringTemplate.formatIf({
|
|
836
|
+
template: "{{text}}",
|
|
837
|
+
data: { text: "Valid Template" },
|
|
838
|
+
templateFormat: "Test"
|
|
839
|
+
});
|
|
840
|
+
console.log(result); // Output: "Valid Template"
|
|
841
|
+
```
|
|
679
842
|
|
|
680
843
|
#### Inherited from
|
|
681
844
|
|
|
@@ -747,22 +910,40 @@ the name to register
|
|
|
747
910
|
|
|
748
911
|
> `static` **from**(`template`?, `options`?): [`PromptTemplate`](PromptTemplate.md)
|
|
749
912
|
|
|
750
|
-
Defined in:
|
|
913
|
+
Defined in: packages/template-engines/dist/index.d.ts:85
|
|
914
|
+
|
|
915
|
+
Creates a new instance of the `StringTemplate` class.
|
|
751
916
|
|
|
752
917
|
#### Parameters
|
|
753
918
|
|
|
754
919
|
##### template?
|
|
755
920
|
|
|
921
|
+
Either a template string or an options object.
|
|
922
|
+
|
|
756
923
|
`string` | [`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
757
924
|
|
|
758
925
|
##### options?
|
|
759
926
|
|
|
760
927
|
[`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
761
928
|
|
|
929
|
+
Additional configuration options for the template.
|
|
930
|
+
|
|
762
931
|
#### Returns
|
|
763
932
|
|
|
764
933
|
[`PromptTemplate`](PromptTemplate.md)
|
|
765
934
|
|
|
935
|
+
A new `StringTemplate` instance.
|
|
936
|
+
|
|
937
|
+
#### Example
|
|
938
|
+
|
|
939
|
+
```typescript
|
|
940
|
+
const template = StringTemplate.from("{{text}}", {
|
|
941
|
+
templateFormat: "Test",
|
|
942
|
+
inputVariables: ['text']
|
|
943
|
+
});
|
|
944
|
+
console.log(template instanceof TestStringTemplate); // Output: true
|
|
945
|
+
```
|
|
946
|
+
|
|
766
947
|
#### Inherited from
|
|
767
948
|
|
|
768
949
|
[`PromptTemplate`](PromptTemplate.md).[`from`](PromptTemplate.md#from)
|
|
@@ -929,18 +1110,34 @@ the unique name in the factory
|
|
|
929
1110
|
|
|
930
1111
|
> `static` **isTemplate**(`templateOpt`): `boolean`
|
|
931
1112
|
|
|
932
|
-
Defined in:
|
|
1113
|
+
Defined in: packages/template-engines/dist/index.d.ts:624
|
|
1114
|
+
|
|
1115
|
+
Determines whether the given options represent a valid template.
|
|
933
1116
|
|
|
934
1117
|
#### Parameters
|
|
935
1118
|
|
|
936
1119
|
##### templateOpt
|
|
937
1120
|
|
|
1121
|
+
The options object to evaluate.
|
|
1122
|
+
|
|
938
1123
|
`string` | [`PromptTemplateOptions`](../interfaces/PromptTemplateOptions.md)
|
|
939
1124
|
|
|
940
1125
|
#### Returns
|
|
941
1126
|
|
|
942
1127
|
`boolean`
|
|
943
1128
|
|
|
1129
|
+
A boolean indicating whether the options represent a valid template.
|
|
1130
|
+
|
|
1131
|
+
#### Example
|
|
1132
|
+
|
|
1133
|
+
```typescript
|
|
1134
|
+
const isValid = StringTemplate.isTemplate({
|
|
1135
|
+
template: "{{text}}",
|
|
1136
|
+
templateFormat: "Test"
|
|
1137
|
+
});
|
|
1138
|
+
console.log(isValid); // Output: true
|
|
1139
|
+
```
|
|
1140
|
+
|
|
944
1141
|
#### Overrides
|
|
945
1142
|
|
|
946
1143
|
[`PromptTemplate`](PromptTemplate.md).[`isTemplate`](PromptTemplate.md#istemplate)
|