llm-exe 2.1.8 → 2.2.1

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/index.d.mts CHANGED
@@ -65,20 +65,6 @@ type OpenAIChatModelName = "gpt-3.5-turbo" | "gpt-3.5-turbo-0613" | "gpt-3.5-tur
65
65
  type OpenAIConversationModelName = "davinci" | "text-curie-001" | "text-babbage-001" | "text-ada-001";
66
66
  type OpenAIEmbeddingModelName = "text-embedding-ada-002";
67
67
  type OpenAIModelName = OpenAIChatModelName | OpenAIConversationModelName | OpenAIEmbeddingModelName;
68
- interface LlmExecutorExecuteOptions {
69
- functions?: CallableExecutorCore[];
70
- functionCall?: any;
71
- jsonSchema?: Record<string, any>;
72
- }
73
- type GenericFunctionCall = "auto" | "none" | "any" | {
74
- name: string;
75
- };
76
- interface OpenAiLlmExecutorOptions<T extends GenericFunctionCall = "auto"> extends LlmExecutorExecuteOptions {
77
- functions?: CallableExecutorCore[];
78
- functionCall?: T;
79
- functionCallStrictInput?: boolean;
80
- jsonSchema?: Record<string, any>;
81
- }
82
68
 
83
69
  /**
84
70
  * BaseParser is an abstract class for parsing text and enforcing JSON schema on the parsed data.
@@ -113,21 +99,6 @@ declare abstract class BaseParserWithJson<S extends JSONSchema | undefined = und
113
99
  constructor(name: string, options: BaseParserOptionsWithSchema<S>);
114
100
  }
115
101
 
116
- interface OpenAiFunctionParserOptions<T extends BaseParser<any>> extends BaseParserOptions {
117
- parser: T;
118
- }
119
- declare class OpenAiFunctionParser<T extends BaseParser<any>> extends BaseParser<ParserOutput<T> | {
120
- name: any;
121
- arguments: any;
122
- }> {
123
- parser: T;
124
- constructor(options: OpenAiFunctionParserOptions<T>);
125
- parse(text: OutputResultContent[], _options?: Record<string, any>): ParserOutput<T> | {
126
- name: string;
127
- arguments: any;
128
- };
129
- }
130
-
131
102
  interface StringParserOptions extends BaseParserOptions {
132
103
  }
133
104
  declare class StringParser extends BaseParser<string> {
@@ -330,6 +301,25 @@ declare function createParser<T extends Extract<CreateParserType, "json">, S ext
330
301
  declare function createParser<T extends CreateParserType, S extends JSONSchema | undefined = undefined>(type: T, options?: BaseParserOptionsWithSchema<S> | BaseParserOptions): JsonParser<S> | ListToJsonParser<S> | StringParser | NumberParser | BooleanParser | ListToArrayParser | ListToKeyValueParser | ReplaceStringTemplateParser | MarkdownCodeBlockParser | MarkdownCodeBlocksParser | StringExtractParser;
331
302
  declare function createCustomParser<O>(name: string, parserFn: (text: string, inputValues: ExecutorContext<any, any>) => O): CustomParser<ReturnType<typeof parserFn>>;
332
303
 
304
+ interface LlmNativeFunctionParserOptions<T extends BaseParser<any>> extends BaseParserOptions {
305
+ parser: T;
306
+ }
307
+ declare class LlmNativeFunctionParser<T extends BaseParser<any>> extends BaseParser<ParserOutput<T> | {
308
+ name: any;
309
+ arguments: any;
310
+ }> {
311
+ parser: T;
312
+ constructor(options: LlmNativeFunctionParserOptions<T>);
313
+ parse(text: OutputResultContent[], _options?: Record<string, any>): ParserOutput<T> | {
314
+ name: string;
315
+ arguments: any;
316
+ };
317
+ }
318
+ /**
319
+ * @deprecated Use `LlmExecutorWithFunctions` instead.
320
+ */
321
+ declare const OpenAiFunctionParser: typeof LlmNativeFunctionParser;
322
+
333
323
  declare function replaceTemplateString(templateString?: string, substitutions?: Record<string, any>, configuration?: PromptTemplateOptions): string;
334
324
 
335
325
  declare function replaceTemplateStringAsync(templateString?: string, substitutions?: Record<string, any>, configuration?: PromptTemplateOptions): Promise<string>;
@@ -740,9 +730,14 @@ declare class LlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePrompt<Re
740
730
  /**
741
731
  * Core Executor With LLM
742
732
  */
743
- declare class LlmExecutorOpenAiFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutor<Llm, Prompt, Parser, State> {
733
+ declare class LlmExecutorWithFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutor<Llm, Prompt, Parser, State> {
744
734
  constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
745
- execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: OpenAiLlmExecutorOptions<T>): Promise<ParserOutput<Parser>>;
735
+ execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<ParserOutput<Parser>>;
736
+ }
737
+ /**
738
+ * @deprecated Use `LlmExecutorWithFunctions` instead.
739
+ */
740
+ declare class LlmExecutorOpenAiFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutorWithFunctions<Llm, Prompt, Parser, State> {
746
741
  }
747
742
 
748
743
  /**
@@ -763,6 +758,7 @@ declare function createCoreExecutor<I extends PlainObject, O>(handler: (input: I
763
758
  * @returns - A new LlmExecutor instance.
764
759
  */
765
760
  declare function createLlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePrompt<any>, Parser extends BaseParser, State extends BaseState>(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>): LlmExecutor<Llm, Prompt, Parser, State>;
761
+ declare function createLlmFunctionExecutor<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState>(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>): LlmExecutorWithFunctions<Llm, Prompt, Parser, State>;
766
762
 
767
763
  declare const hookOnComplete = "onComplete";
768
764
  declare const hookOnError = "onError";
@@ -829,6 +825,20 @@ interface CallableExecutorCore {
829
825
  description: string;
830
826
  parameters?: Record<string, any>;
831
827
  }
828
+ interface LlmExecutorExecuteOptions {
829
+ functions?: CallableExecutorCore[];
830
+ functionCall?: any;
831
+ jsonSchema?: Record<string, any>;
832
+ }
833
+ type GenericFunctionCall = "auto" | "none" | "any" | {
834
+ name: string;
835
+ };
836
+ interface LlmExecutorWithFunctionsOptions<T extends GenericFunctionCall = "auto"> extends LlmExecutorExecuteOptions {
837
+ functions?: CallableExecutorCore[];
838
+ functionCall?: T;
839
+ functionCallStrictInput?: boolean;
840
+ jsonSchema?: Record<string, any>;
841
+ }
832
842
 
833
843
  type CreateParserType = "json" | "string" | "boolean" | "number" | "stringExtract" | "listToArray" | "listToJson" | "listToKeyValue" | "replaceStringTemplate" | "markdownCodeBlocks" | "markdownCodeBlock";
834
844
  interface BaseParserOptions {
@@ -1038,6 +1048,7 @@ type AllUseLlmOptions = AllLlm & {
1038
1048
  };
1039
1049
  type LlmProviderKey = keyof AllLlm;
1040
1050
  type EmbeddingProviderKey = keyof AllEmbedding;
1051
+ type UseLlmKey = keyof AllUseLlmOptions;
1041
1052
  interface BaseLlCall {
1042
1053
  getResultContent: () => OutputResultContent[];
1043
1054
  getResultText: () => string;
@@ -1259,8 +1270,8 @@ declare const configs: {
1259
1270
  };
1260
1271
 
1261
1272
  declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): {
1262
- call: (messages: string | IChatMessages, options?: OpenAiLlmExecutorOptions<"auto"> | undefined) => Promise<{
1263
- getResultContent: (index?: number | undefined) => OutputResultContent[];
1273
+ call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<{
1274
+ getResultContent: (index?: number) => OutputResultContent[];
1264
1275
  getResultText: () => string;
1265
1276
  getResult: () => OutputResult;
1266
1277
  }>;
@@ -1279,8 +1290,8 @@ declare function useLlm<T extends keyof typeof configs>(provider: T, options?: A
1279
1290
  };
1280
1291
 
1281
1292
  declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, options: AllEmbedding[T]["input"]): {
1282
- call: (messages: string | string[], options?: OpenAiLlmExecutorOptions<"auto"> | undefined) => Promise<{
1283
- getEmbedding: (index?: number | undefined) => number[];
1293
+ call: (messages: string | string[], options?: LlmExecutorWithFunctionsOptions) => Promise<{
1294
+ getEmbedding: (index?: number) => number[];
1284
1295
  getResult: () => EmbeddingOutputResult;
1285
1296
  }>;
1286
1297
  getTraceId: () => string | null;
@@ -1297,4 +1308,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
1297
1308
  };
1298
1309
  };
1299
1310
 
1300
- export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type ExecutorContext, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, useExecutors, useLlm, index as utils };
1311
+ export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type EmbeddingProviderKey, type ExecutorContext, type IChatMessages, LlmExecutorOpenAiFunctions, LlmExecutorWithFunctions, LlmNativeFunctionParser, type LlmProvider, type LlmProviderKey, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, type UseLlmKey, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createLlmFunctionExecutor, createParser, createPrompt, createState, createStateItem, defineSchema, registerHelpers, registerPartials, useExecutors, useLlm, index as utils };
package/dist/index.d.ts CHANGED
@@ -65,20 +65,6 @@ type OpenAIChatModelName = "gpt-3.5-turbo" | "gpt-3.5-turbo-0613" | "gpt-3.5-tur
65
65
  type OpenAIConversationModelName = "davinci" | "text-curie-001" | "text-babbage-001" | "text-ada-001";
66
66
  type OpenAIEmbeddingModelName = "text-embedding-ada-002";
67
67
  type OpenAIModelName = OpenAIChatModelName | OpenAIConversationModelName | OpenAIEmbeddingModelName;
68
- interface LlmExecutorExecuteOptions {
69
- functions?: CallableExecutorCore[];
70
- functionCall?: any;
71
- jsonSchema?: Record<string, any>;
72
- }
73
- type GenericFunctionCall = "auto" | "none" | "any" | {
74
- name: string;
75
- };
76
- interface OpenAiLlmExecutorOptions<T extends GenericFunctionCall = "auto"> extends LlmExecutorExecuteOptions {
77
- functions?: CallableExecutorCore[];
78
- functionCall?: T;
79
- functionCallStrictInput?: boolean;
80
- jsonSchema?: Record<string, any>;
81
- }
82
68
 
83
69
  /**
84
70
  * BaseParser is an abstract class for parsing text and enforcing JSON schema on the parsed data.
@@ -113,21 +99,6 @@ declare abstract class BaseParserWithJson<S extends JSONSchema | undefined = und
113
99
  constructor(name: string, options: BaseParserOptionsWithSchema<S>);
114
100
  }
115
101
 
116
- interface OpenAiFunctionParserOptions<T extends BaseParser<any>> extends BaseParserOptions {
117
- parser: T;
118
- }
119
- declare class OpenAiFunctionParser<T extends BaseParser<any>> extends BaseParser<ParserOutput<T> | {
120
- name: any;
121
- arguments: any;
122
- }> {
123
- parser: T;
124
- constructor(options: OpenAiFunctionParserOptions<T>);
125
- parse(text: OutputResultContent[], _options?: Record<string, any>): ParserOutput<T> | {
126
- name: string;
127
- arguments: any;
128
- };
129
- }
130
-
131
102
  interface StringParserOptions extends BaseParserOptions {
132
103
  }
133
104
  declare class StringParser extends BaseParser<string> {
@@ -330,6 +301,25 @@ declare function createParser<T extends Extract<CreateParserType, "json">, S ext
330
301
  declare function createParser<T extends CreateParserType, S extends JSONSchema | undefined = undefined>(type: T, options?: BaseParserOptionsWithSchema<S> | BaseParserOptions): JsonParser<S> | ListToJsonParser<S> | StringParser | NumberParser | BooleanParser | ListToArrayParser | ListToKeyValueParser | ReplaceStringTemplateParser | MarkdownCodeBlockParser | MarkdownCodeBlocksParser | StringExtractParser;
331
302
  declare function createCustomParser<O>(name: string, parserFn: (text: string, inputValues: ExecutorContext<any, any>) => O): CustomParser<ReturnType<typeof parserFn>>;
332
303
 
304
+ interface LlmNativeFunctionParserOptions<T extends BaseParser<any>> extends BaseParserOptions {
305
+ parser: T;
306
+ }
307
+ declare class LlmNativeFunctionParser<T extends BaseParser<any>> extends BaseParser<ParserOutput<T> | {
308
+ name: any;
309
+ arguments: any;
310
+ }> {
311
+ parser: T;
312
+ constructor(options: LlmNativeFunctionParserOptions<T>);
313
+ parse(text: OutputResultContent[], _options?: Record<string, any>): ParserOutput<T> | {
314
+ name: string;
315
+ arguments: any;
316
+ };
317
+ }
318
+ /**
319
+ * @deprecated Use `LlmExecutorWithFunctions` instead.
320
+ */
321
+ declare const OpenAiFunctionParser: typeof LlmNativeFunctionParser;
322
+
333
323
  declare function replaceTemplateString(templateString?: string, substitutions?: Record<string, any>, configuration?: PromptTemplateOptions): string;
334
324
 
335
325
  declare function replaceTemplateStringAsync(templateString?: string, substitutions?: Record<string, any>, configuration?: PromptTemplateOptions): Promise<string>;
@@ -740,9 +730,14 @@ declare class LlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePrompt<Re
740
730
  /**
741
731
  * Core Executor With LLM
742
732
  */
743
- declare class LlmExecutorOpenAiFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutor<Llm, Prompt, Parser, State> {
733
+ declare class LlmExecutorWithFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutor<Llm, Prompt, Parser, State> {
744
734
  constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
745
- execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: OpenAiLlmExecutorOptions<T>): Promise<ParserOutput<Parser>>;
735
+ execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<ParserOutput<Parser>>;
736
+ }
737
+ /**
738
+ * @deprecated Use `LlmExecutorWithFunctions` instead.
739
+ */
740
+ declare class LlmExecutorOpenAiFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutorWithFunctions<Llm, Prompt, Parser, State> {
746
741
  }
747
742
 
748
743
  /**
@@ -763,6 +758,7 @@ declare function createCoreExecutor<I extends PlainObject, O>(handler: (input: I
763
758
  * @returns - A new LlmExecutor instance.
764
759
  */
765
760
  declare function createLlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePrompt<any>, Parser extends BaseParser, State extends BaseState>(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>): LlmExecutor<Llm, Prompt, Parser, State>;
761
+ declare function createLlmFunctionExecutor<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState>(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>): LlmExecutorWithFunctions<Llm, Prompt, Parser, State>;
766
762
 
767
763
  declare const hookOnComplete = "onComplete";
768
764
  declare const hookOnError = "onError";
@@ -829,6 +825,20 @@ interface CallableExecutorCore {
829
825
  description: string;
830
826
  parameters?: Record<string, any>;
831
827
  }
828
+ interface LlmExecutorExecuteOptions {
829
+ functions?: CallableExecutorCore[];
830
+ functionCall?: any;
831
+ jsonSchema?: Record<string, any>;
832
+ }
833
+ type GenericFunctionCall = "auto" | "none" | "any" | {
834
+ name: string;
835
+ };
836
+ interface LlmExecutorWithFunctionsOptions<T extends GenericFunctionCall = "auto"> extends LlmExecutorExecuteOptions {
837
+ functions?: CallableExecutorCore[];
838
+ functionCall?: T;
839
+ functionCallStrictInput?: boolean;
840
+ jsonSchema?: Record<string, any>;
841
+ }
832
842
 
833
843
  type CreateParserType = "json" | "string" | "boolean" | "number" | "stringExtract" | "listToArray" | "listToJson" | "listToKeyValue" | "replaceStringTemplate" | "markdownCodeBlocks" | "markdownCodeBlock";
834
844
  interface BaseParserOptions {
@@ -1038,6 +1048,7 @@ type AllUseLlmOptions = AllLlm & {
1038
1048
  };
1039
1049
  type LlmProviderKey = keyof AllLlm;
1040
1050
  type EmbeddingProviderKey = keyof AllEmbedding;
1051
+ type UseLlmKey = keyof AllUseLlmOptions;
1041
1052
  interface BaseLlCall {
1042
1053
  getResultContent: () => OutputResultContent[];
1043
1054
  getResultText: () => string;
@@ -1259,8 +1270,8 @@ declare const configs: {
1259
1270
  };
1260
1271
 
1261
1272
  declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): {
1262
- call: (messages: string | IChatMessages, options?: OpenAiLlmExecutorOptions<"auto"> | undefined) => Promise<{
1263
- getResultContent: (index?: number | undefined) => OutputResultContent[];
1273
+ call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<{
1274
+ getResultContent: (index?: number) => OutputResultContent[];
1264
1275
  getResultText: () => string;
1265
1276
  getResult: () => OutputResult;
1266
1277
  }>;
@@ -1279,8 +1290,8 @@ declare function useLlm<T extends keyof typeof configs>(provider: T, options?: A
1279
1290
  };
1280
1291
 
1281
1292
  declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, options: AllEmbedding[T]["input"]): {
1282
- call: (messages: string | string[], options?: OpenAiLlmExecutorOptions<"auto"> | undefined) => Promise<{
1283
- getEmbedding: (index?: number | undefined) => number[];
1293
+ call: (messages: string | string[], options?: LlmExecutorWithFunctionsOptions) => Promise<{
1294
+ getEmbedding: (index?: number) => number[];
1284
1295
  getResult: () => EmbeddingOutputResult;
1285
1296
  }>;
1286
1297
  getTraceId: () => string | null;
@@ -1297,4 +1308,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
1297
1308
  };
1298
1309
  };
1299
1310
 
1300
- export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type ExecutorContext, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, useExecutors, useLlm, index as utils };
1311
+ export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type EmbeddingProviderKey, type ExecutorContext, type IChatMessages, LlmExecutorOpenAiFunctions, LlmExecutorWithFunctions, LlmNativeFunctionParser, type LlmProvider, type LlmProviderKey, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, type UseLlmKey, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createLlmFunctionExecutor, createParser, createPrompt, createState, createStateItem, defineSchema, registerHelpers, registerPartials, useExecutors, useLlm, index as utils };