@jaypie/llm 1.1.26 → 1.1.27
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/cjs/index.cjs +2128 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{types → cjs/types}/LlmProvider.interface.d.ts +1 -1
- package/dist/esm/Llm.d.ts +23 -0
- package/dist/esm/constants.d.ts +100 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/{index.js → esm/index.js} +8 -6
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/providers/anthropic/AnthropicProvider.class.d.ts +15 -0
- package/dist/esm/providers/anthropic/index.d.ts +2 -0
- package/dist/esm/providers/anthropic/operate.d.ts +16 -0
- package/dist/esm/providers/anthropic/types.d.ts +2 -0
- package/dist/esm/providers/anthropic/utils.d.ts +48 -0
- package/dist/esm/providers/openai/OpenAiProvider.class.d.ts +15 -0
- package/dist/esm/providers/openai/index.d.ts +1 -0
- package/dist/esm/providers/openai/operate.d.ts +26 -0
- package/dist/esm/providers/openai/types.d.ts +100 -0
- package/dist/esm/providers/openai/utils.d.ts +59 -0
- package/dist/esm/tools/Toolkit.class.d.ts +28 -0
- package/dist/esm/tools/index.d.ts +12 -0
- package/dist/esm/tools/random.d.ts +2 -0
- package/dist/esm/tools/roll.d.ts +2 -0
- package/dist/esm/tools/time.d.ts +2 -0
- package/dist/esm/tools/weather.d.ts +2 -0
- package/dist/esm/types/LlmProvider.interface.d.ts +198 -0
- package/dist/esm/types/LlmTool.interface.d.ts +11 -0
- package/dist/esm/util/determineModelProvider.d.ts +4 -0
- package/dist/esm/util/formatOperateInput.d.ts +24 -0
- package/dist/esm/util/formatOperateMessage.d.ts +24 -0
- package/dist/esm/util/index.d.ts +8 -0
- package/dist/esm/util/logger.d.ts +71 -0
- package/dist/esm/util/maxTurnsFromOptions.d.ts +10 -0
- package/dist/esm/util/naturalZodSchema.d.ts +3 -0
- package/dist/esm/util/random.d.ts +39 -0
- package/dist/esm/util/tryParseNumber.d.ts +22 -0
- package/package.json +8 -6
- package/dist/index.js.map +0 -1
- /package/dist/{Llm.d.ts → cjs/Llm.d.ts} +0 -0
- /package/dist/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{providers → cjs/providers}/anthropic/AnthropicProvider.class.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/anthropic/index.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/anthropic/operate.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/anthropic/types.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/anthropic/utils.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/openai/OpenAiProvider.class.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/openai/index.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/openai/operate.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/openai/types.d.ts +0 -0
- /package/dist/{providers → cjs/providers}/openai/utils.d.ts +0 -0
- /package/dist/{tools → cjs/tools}/Toolkit.class.d.ts +0 -0
- /package/dist/{tools → cjs/tools}/index.d.ts +0 -0
- /package/dist/{tools → cjs/tools}/random.d.ts +0 -0
- /package/dist/{tools → cjs/tools}/roll.d.ts +0 -0
- /package/dist/{tools → cjs/tools}/time.d.ts +0 -0
- /package/dist/{tools → cjs/tools}/weather.d.ts +0 -0
- /package/dist/{types → cjs/types}/LlmTool.interface.d.ts +0 -0
- /package/dist/{util → cjs/util}/determineModelProvider.d.ts +0 -0
- /package/dist/{util → cjs/util}/formatOperateInput.d.ts +0 -0
- /package/dist/{util → cjs/util}/formatOperateMessage.d.ts +0 -0
- /package/dist/{util → cjs/util}/index.d.ts +0 -0
- /package/dist/{util → cjs/util}/logger.d.ts +0 -0
- /package/dist/{util → cjs/util}/maxTurnsFromOptions.d.ts +0 -0
- /package/dist/{util → cjs/util}/naturalZodSchema.d.ts +0 -0
- /package/dist/{util → cjs/util}/random.d.ts +0 -0
- /package/dist/{util → cjs/util}/tryParseNumber.d.ts +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { log as defaultLog } from "@jaypie/core";
|
|
2
|
+
import { JsonObject, NaturalSchema } from "@jaypie/types";
|
|
3
|
+
import { OpenAI } from "openai";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
|
|
6
|
+
export declare const getLogger: () => {
|
|
7
|
+
debug: {
|
|
8
|
+
(...args: unknown[]): void;
|
|
9
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
10
|
+
};
|
|
11
|
+
error: {
|
|
12
|
+
(...args: unknown[]): void;
|
|
13
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
14
|
+
};
|
|
15
|
+
fatal: {
|
|
16
|
+
(...args: unknown[]): void;
|
|
17
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
18
|
+
};
|
|
19
|
+
info: {
|
|
20
|
+
(...args: unknown[]): void;
|
|
21
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
22
|
+
};
|
|
23
|
+
trace: {
|
|
24
|
+
(...args: unknown[]): void;
|
|
25
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
26
|
+
};
|
|
27
|
+
warn: {
|
|
28
|
+
(...args: unknown[]): void;
|
|
29
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
30
|
+
};
|
|
31
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
32
|
+
with(tags: Record<string, unknown>): typeof defaultLog;
|
|
33
|
+
tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
|
|
34
|
+
untag(tags: string | string[] | Record<string, unknown> | null): void;
|
|
35
|
+
lib(options: {
|
|
36
|
+
level?: string;
|
|
37
|
+
lib?: string;
|
|
38
|
+
tags?: Record<string, unknown>;
|
|
39
|
+
}): typeof defaultLog;
|
|
40
|
+
};
|
|
41
|
+
export declare function initializeClient({ apiKey, }?: {
|
|
42
|
+
apiKey?: string;
|
|
43
|
+
}): Promise<OpenAI>;
|
|
44
|
+
export interface ChatMessage {
|
|
45
|
+
role: "user" | "developer";
|
|
46
|
+
content: string;
|
|
47
|
+
}
|
|
48
|
+
export declare function formatSystemMessage(systemPrompt: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
|
|
49
|
+
export declare function formatUserMessage(message: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
|
|
50
|
+
export declare function prepareMessages(message: string, { system, data, placeholders }?: LlmMessageOptions): ChatMessage[];
|
|
51
|
+
export declare function createStructuredCompletion(client: OpenAI, { messages, responseSchema, model, }: {
|
|
52
|
+
messages: ChatMessage[];
|
|
53
|
+
responseSchema: z.ZodType | NaturalSchema;
|
|
54
|
+
model: string;
|
|
55
|
+
}): Promise<JsonObject>;
|
|
56
|
+
export declare function createTextCompletion(client: OpenAI, { messages, model, }: {
|
|
57
|
+
messages: ChatMessage[];
|
|
58
|
+
model: string;
|
|
59
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LlmTool } from "../types/LlmTool.interface";
|
|
2
|
+
type LogFunction = (message: string, context: {
|
|
3
|
+
name: string;
|
|
4
|
+
args: any;
|
|
5
|
+
}) => void | Promise<void>;
|
|
6
|
+
export interface ToolkitOptions {
|
|
7
|
+
explain?: boolean;
|
|
8
|
+
log?: boolean | LogFunction;
|
|
9
|
+
}
|
|
10
|
+
export declare class Toolkit {
|
|
11
|
+
private readonly _tools;
|
|
12
|
+
private readonly _options;
|
|
13
|
+
private readonly explain;
|
|
14
|
+
private readonly log;
|
|
15
|
+
constructor(tools: LlmTool[], options?: ToolkitOptions);
|
|
16
|
+
get tools(): Omit<LlmTool, "call">[];
|
|
17
|
+
call({ name, arguments: args }: {
|
|
18
|
+
name: string;
|
|
19
|
+
arguments: string;
|
|
20
|
+
}): Promise<import("@jaypie/types").AnyValue>;
|
|
21
|
+
extend(tools: LlmTool[], options?: {
|
|
22
|
+
warn?: boolean;
|
|
23
|
+
replace?: boolean;
|
|
24
|
+
log?: boolean | LogFunction;
|
|
25
|
+
explain?: boolean;
|
|
26
|
+
}): this;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Toolkit } from "./Toolkit.class.js";
|
|
2
|
+
import type { LlmTool } from "../types/LlmTool.interface.js";
|
|
3
|
+
export declare const tools: LlmTool[];
|
|
4
|
+
export declare class JaypieToolkit extends Toolkit {
|
|
5
|
+
readonly random: LlmTool;
|
|
6
|
+
readonly roll: LlmTool;
|
|
7
|
+
readonly time: LlmTool;
|
|
8
|
+
readonly weather: LlmTool;
|
|
9
|
+
constructor(tools: LlmTool[], options?: any);
|
|
10
|
+
}
|
|
11
|
+
export declare const toolkit: JaypieToolkit;
|
|
12
|
+
export { Toolkit };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { AnyValue, JsonObject, JsonReturn, NaturalMap, NaturalSchema } from "@jaypie/types";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
import { LlmTool } from "./LlmTool.interface.js";
|
|
4
|
+
import { Toolkit } from "../tools/Toolkit.class.js";
|
|
5
|
+
export declare enum LlmMessageRole {
|
|
6
|
+
Assistant = "assistant",
|
|
7
|
+
Developer = "developer",
|
|
8
|
+
System = "system",
|
|
9
|
+
User = "user"
|
|
10
|
+
}
|
|
11
|
+
export declare enum LlmMessageType {
|
|
12
|
+
FunctionCall = "function_call",
|
|
13
|
+
FunctionCallOutput = "function_call_output",
|
|
14
|
+
InputFile = "input_file",
|
|
15
|
+
InputImage = "input_image",
|
|
16
|
+
InputText = "input_text",
|
|
17
|
+
ItemReference = "item_reference",
|
|
18
|
+
Message = "message",
|
|
19
|
+
OutputText = "output_text",
|
|
20
|
+
Refusal = "refusal"
|
|
21
|
+
}
|
|
22
|
+
export declare enum LlmResponseStatus {
|
|
23
|
+
Completed = "completed",
|
|
24
|
+
Incomplete = "incomplete",
|
|
25
|
+
InProgress = "in_progress"
|
|
26
|
+
}
|
|
27
|
+
interface LlmError {
|
|
28
|
+
detail?: string;
|
|
29
|
+
status: number | string;
|
|
30
|
+
title: string;
|
|
31
|
+
}
|
|
32
|
+
export interface LlmInputContentFile {
|
|
33
|
+
type: LlmMessageType.InputFile;
|
|
34
|
+
file_data: File | string;
|
|
35
|
+
file_id?: string;
|
|
36
|
+
filename?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface LlmInputContentImage {
|
|
39
|
+
type: LlmMessageType.InputImage;
|
|
40
|
+
detail?: File;
|
|
41
|
+
file_id?: string;
|
|
42
|
+
image_url?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface LlmInputContentText {
|
|
45
|
+
type: LlmMessageType.InputText;
|
|
46
|
+
text: string;
|
|
47
|
+
}
|
|
48
|
+
export type LlmInputContent = LlmInputContentFile | LlmInputContentImage | LlmInputContentText;
|
|
49
|
+
/**
|
|
50
|
+
* Represents the "Input message object" in the "input item list"
|
|
51
|
+
* from [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses/create)
|
|
52
|
+
*/
|
|
53
|
+
export interface LlmInputMessage {
|
|
54
|
+
content: string | Array<LlmInputContent>;
|
|
55
|
+
role: LlmMessageRole;
|
|
56
|
+
type?: LlmMessageType.Message;
|
|
57
|
+
}
|
|
58
|
+
export interface LlmOutputContentText {
|
|
59
|
+
annotations?: AnyValue[];
|
|
60
|
+
text: string;
|
|
61
|
+
type: LlmMessageType.OutputText;
|
|
62
|
+
}
|
|
63
|
+
interface LlmOutputRefusal {
|
|
64
|
+
refusal: string;
|
|
65
|
+
type: LlmMessageType.Refusal;
|
|
66
|
+
}
|
|
67
|
+
type LlmOutputContent = LlmOutputContentText | LlmOutputRefusal;
|
|
68
|
+
/**
|
|
69
|
+
* Represents the "Output message object" in the "input item list"
|
|
70
|
+
* from [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses/create)
|
|
71
|
+
*/
|
|
72
|
+
export interface LlmOutputMessage {
|
|
73
|
+
content: string | Array<LlmOutputContent>;
|
|
74
|
+
id?: string;
|
|
75
|
+
role: LlmMessageRole.Assistant;
|
|
76
|
+
status?: LlmResponseStatus;
|
|
77
|
+
type?: LlmMessageType.Message;
|
|
78
|
+
}
|
|
79
|
+
type LlmOutputItem = LlmToolCall | LlmToolResult | LlmOutputMessage;
|
|
80
|
+
type LlmOutput = LlmOutputItem[];
|
|
81
|
+
export interface LlmToolCall {
|
|
82
|
+
arguments: string;
|
|
83
|
+
call_id: string;
|
|
84
|
+
id: string;
|
|
85
|
+
name: string;
|
|
86
|
+
type: LlmMessageType.FunctionCall;
|
|
87
|
+
status: LlmResponseStatus;
|
|
88
|
+
}
|
|
89
|
+
export interface LlmToolResult {
|
|
90
|
+
call_id: string;
|
|
91
|
+
output: string;
|
|
92
|
+
status?: LlmResponseStatus;
|
|
93
|
+
type: LlmMessageType.FunctionCallOutput;
|
|
94
|
+
}
|
|
95
|
+
interface LlmItemReference {
|
|
96
|
+
type: LlmMessageType.ItemReference;
|
|
97
|
+
id: string;
|
|
98
|
+
}
|
|
99
|
+
export type LlmHistoryItem = LlmInputMessage | LlmItemReference | LlmOutputItem | LlmToolResult;
|
|
100
|
+
export type LlmHistory = LlmHistoryItem[];
|
|
101
|
+
export interface LlmMessageOptions {
|
|
102
|
+
data?: NaturalMap;
|
|
103
|
+
model?: string;
|
|
104
|
+
placeholders?: {
|
|
105
|
+
message?: boolean;
|
|
106
|
+
system?: boolean;
|
|
107
|
+
};
|
|
108
|
+
response?: NaturalSchema | z.ZodType;
|
|
109
|
+
system?: string;
|
|
110
|
+
}
|
|
111
|
+
export interface LlmOperateOptions {
|
|
112
|
+
data?: NaturalMap;
|
|
113
|
+
explain?: boolean;
|
|
114
|
+
format?: JsonObject | NaturalSchema | z.ZodType;
|
|
115
|
+
history?: LlmHistory;
|
|
116
|
+
hooks?: {
|
|
117
|
+
afterEachModelResponse?: ({ input, options, providerRequest, providerResponse, content, usage, }: {
|
|
118
|
+
input: string | LlmHistory | LlmInputMessage;
|
|
119
|
+
options?: LlmOperateOptions;
|
|
120
|
+
providerRequest: any;
|
|
121
|
+
providerResponse: any;
|
|
122
|
+
content: string | JsonObject;
|
|
123
|
+
usage: LlmUsage;
|
|
124
|
+
}) => unknown | Promise<unknown>;
|
|
125
|
+
afterEachTool?: ({ result, toolName, args, }: {
|
|
126
|
+
result: unknown;
|
|
127
|
+
toolName: string;
|
|
128
|
+
args: string;
|
|
129
|
+
}) => unknown | Promise<unknown>;
|
|
130
|
+
beforeEachModelRequest?: ({ input, options, providerRequest, }: {
|
|
131
|
+
input: string | LlmHistory | LlmInputMessage;
|
|
132
|
+
options?: LlmOperateOptions;
|
|
133
|
+
providerRequest: any;
|
|
134
|
+
}) => unknown | Promise<unknown>;
|
|
135
|
+
beforeEachTool?: ({ toolName, args, }: {
|
|
136
|
+
toolName: string;
|
|
137
|
+
args: string;
|
|
138
|
+
}) => unknown | Promise<unknown>;
|
|
139
|
+
onRetryableModelError?: ({ input, options, providerRequest, error, }: {
|
|
140
|
+
input: string | LlmHistory | LlmInputMessage;
|
|
141
|
+
options?: LlmOperateOptions;
|
|
142
|
+
providerRequest: any;
|
|
143
|
+
error: any;
|
|
144
|
+
}) => unknown | Promise<unknown>;
|
|
145
|
+
onToolError?: ({ error, toolName, args, }: {
|
|
146
|
+
error: Error;
|
|
147
|
+
toolName: string;
|
|
148
|
+
args: string;
|
|
149
|
+
}) => unknown | Promise<unknown>;
|
|
150
|
+
onUnrecoverableModelError?: ({ input, options, providerRequest, error, }: {
|
|
151
|
+
input: string | LlmHistory | LlmInputMessage;
|
|
152
|
+
options?: LlmOperateOptions;
|
|
153
|
+
providerRequest: any;
|
|
154
|
+
error: any;
|
|
155
|
+
}) => unknown | Promise<unknown>;
|
|
156
|
+
};
|
|
157
|
+
instructions?: string;
|
|
158
|
+
model?: string;
|
|
159
|
+
placeholders?: {
|
|
160
|
+
input?: boolean;
|
|
161
|
+
instructions?: boolean;
|
|
162
|
+
system?: boolean;
|
|
163
|
+
};
|
|
164
|
+
providerOptions?: JsonObject;
|
|
165
|
+
system?: string;
|
|
166
|
+
tools?: LlmTool[] | Toolkit;
|
|
167
|
+
turns?: boolean | number;
|
|
168
|
+
user?: string;
|
|
169
|
+
}
|
|
170
|
+
export interface LlmOptions {
|
|
171
|
+
apiKey?: string;
|
|
172
|
+
model?: string;
|
|
173
|
+
}
|
|
174
|
+
export interface LlmUsageItem {
|
|
175
|
+
input: number;
|
|
176
|
+
output: number;
|
|
177
|
+
reasoning: number;
|
|
178
|
+
total: number;
|
|
179
|
+
provider?: string;
|
|
180
|
+
model?: string;
|
|
181
|
+
}
|
|
182
|
+
export type LlmUsage = LlmUsageItem[];
|
|
183
|
+
export interface LlmOperateResponse {
|
|
184
|
+
content?: string | JsonObject;
|
|
185
|
+
error?: LlmError;
|
|
186
|
+
history: LlmHistory;
|
|
187
|
+
model?: string;
|
|
188
|
+
output: LlmOutput;
|
|
189
|
+
provider?: string;
|
|
190
|
+
responses: JsonReturn[];
|
|
191
|
+
status: LlmResponseStatus;
|
|
192
|
+
usage: LlmUsage;
|
|
193
|
+
}
|
|
194
|
+
export interface LlmProvider {
|
|
195
|
+
operate?(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
|
|
196
|
+
send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
|
|
197
|
+
}
|
|
198
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AnyValue, JsonObject } from "@jaypie/types";
|
|
2
|
+
export interface LlmTool {
|
|
3
|
+
description: string;
|
|
4
|
+
name: string;
|
|
5
|
+
parameters: JsonObject;
|
|
6
|
+
type: "function" | string;
|
|
7
|
+
call: (args?: JsonObject) => Promise<AnyValue> | AnyValue;
|
|
8
|
+
message?: string | ((args?: JsonObject, context?: {
|
|
9
|
+
name: string;
|
|
10
|
+
}) => Promise<string> | string);
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LlmHistory, LlmInputMessage, LlmMessageRole } from "../types/LlmProvider.interface.js";
|
|
2
|
+
import { NaturalMap } from "@jaypie/types";
|
|
3
|
+
/**
|
|
4
|
+
* Options for formatOperateInput function
|
|
5
|
+
*/
|
|
6
|
+
export interface FormatOperateInputOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Data to use for placeholder substitution
|
|
9
|
+
*/
|
|
10
|
+
data?: NaturalMap;
|
|
11
|
+
/**
|
|
12
|
+
* Role to use when converting a string to LlmInputMessage
|
|
13
|
+
*/
|
|
14
|
+
role?: LlmMessageRole;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts various input types to a standardized LlmHistory format
|
|
18
|
+
* @param input - String, LlmInputMessage, or LlmHistory to format
|
|
19
|
+
* @param options - Optional configuration
|
|
20
|
+
* @param options.data - Data to use for placeholder substitution
|
|
21
|
+
* @param options.role - Role to use when converting a string to LlmInputMessage (defaults to User)
|
|
22
|
+
* @returns Standardized LlmHistory array
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatOperateInput(input: string | LlmInputMessage | LlmHistory, options?: FormatOperateInputOptions): LlmHistory;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LlmInputMessage, LlmMessageRole } from "../types/LlmProvider.interface.js";
|
|
2
|
+
import { NaturalMap } from "@jaypie/types";
|
|
3
|
+
/**
|
|
4
|
+
* Options for formatOperateMessage function
|
|
5
|
+
*/
|
|
6
|
+
export interface FormatOperateMessageOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Data to use for placeholder substitution
|
|
9
|
+
*/
|
|
10
|
+
data?: NaturalMap;
|
|
11
|
+
/**
|
|
12
|
+
* Role to use for the message
|
|
13
|
+
*/
|
|
14
|
+
role?: LlmMessageRole;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts a string to a standardized LlmInputMessage
|
|
18
|
+
* @param input - String to format
|
|
19
|
+
* @param options - Optional configuration
|
|
20
|
+
* @param options.data - Data to use for placeholder substitution
|
|
21
|
+
* @param options.role - Role to use for the message (defaults to User)
|
|
22
|
+
* @returns LlmInputMessage
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatOperateMessage(input: string, options?: FormatOperateMessageOptions): LlmInputMessage;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./determineModelProvider.js";
|
|
2
|
+
export * from "./formatOperateInput.js";
|
|
3
|
+
export * from "./formatOperateMessage.js";
|
|
4
|
+
export * from "./logger.js";
|
|
5
|
+
export * from "./maxTurnsFromOptions.js";
|
|
6
|
+
export * from "./naturalZodSchema.js";
|
|
7
|
+
export * from "./random.js";
|
|
8
|
+
export * from "./tryParseNumber.js";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { log as defaultLog } from "@jaypie/core";
|
|
2
|
+
export declare const getLogger: () => {
|
|
3
|
+
debug: {
|
|
4
|
+
(...args: unknown[]): void;
|
|
5
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
6
|
+
};
|
|
7
|
+
error: {
|
|
8
|
+
(...args: unknown[]): void;
|
|
9
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
10
|
+
};
|
|
11
|
+
fatal: {
|
|
12
|
+
(...args: unknown[]): void;
|
|
13
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
14
|
+
};
|
|
15
|
+
info: {
|
|
16
|
+
(...args: unknown[]): void;
|
|
17
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
18
|
+
};
|
|
19
|
+
trace: {
|
|
20
|
+
(...args: unknown[]): void;
|
|
21
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
22
|
+
};
|
|
23
|
+
warn: {
|
|
24
|
+
(...args: unknown[]): void;
|
|
25
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
26
|
+
};
|
|
27
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
28
|
+
with(tags: Record<string, unknown>): typeof defaultLog;
|
|
29
|
+
tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
|
|
30
|
+
untag(tags: string | string[] | Record<string, unknown> | null): void;
|
|
31
|
+
lib(options: {
|
|
32
|
+
level?: string;
|
|
33
|
+
lib?: string;
|
|
34
|
+
tags?: Record<string, unknown>;
|
|
35
|
+
}): typeof defaultLog;
|
|
36
|
+
};
|
|
37
|
+
export declare const log: {
|
|
38
|
+
debug: {
|
|
39
|
+
(...args: unknown[]): void;
|
|
40
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
41
|
+
};
|
|
42
|
+
error: {
|
|
43
|
+
(...args: unknown[]): void;
|
|
44
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
45
|
+
};
|
|
46
|
+
fatal: {
|
|
47
|
+
(...args: unknown[]): void;
|
|
48
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
49
|
+
};
|
|
50
|
+
info: {
|
|
51
|
+
(...args: unknown[]): void;
|
|
52
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
53
|
+
};
|
|
54
|
+
trace: {
|
|
55
|
+
(...args: unknown[]): void;
|
|
56
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
57
|
+
};
|
|
58
|
+
warn: {
|
|
59
|
+
(...args: unknown[]): void;
|
|
60
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
61
|
+
};
|
|
62
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
63
|
+
with(tags: Record<string, unknown>): typeof defaultLog;
|
|
64
|
+
tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
|
|
65
|
+
untag(tags: string | string[] | Record<string, unknown> | null): void;
|
|
66
|
+
lib(options: {
|
|
67
|
+
level?: string;
|
|
68
|
+
lib?: string;
|
|
69
|
+
tags?: Record<string, unknown>;
|
|
70
|
+
}): typeof defaultLog;
|
|
71
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LlmOperateOptions } from "../types/LlmProvider.interface.js";
|
|
2
|
+
export declare const MAX_TURNS_ABSOLUTE_LIMIT = 72;
|
|
3
|
+
export declare const MAX_TURNS_DEFAULT_LIMIT = 12;
|
|
4
|
+
/**
|
|
5
|
+
* Determines the maximum number of turns based on the provided options
|
|
6
|
+
*
|
|
7
|
+
* @param options - The LLM operate options
|
|
8
|
+
* @returns The maximum number of turns
|
|
9
|
+
*/
|
|
10
|
+
export declare function maxTurnsFromOptions(options: LlmOperateOptions): number;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
interface RandomOptions {
|
|
2
|
+
min?: number;
|
|
3
|
+
max?: number;
|
|
4
|
+
mean?: number;
|
|
5
|
+
stddev?: number;
|
|
6
|
+
integer?: boolean;
|
|
7
|
+
start?: number;
|
|
8
|
+
seed?: string;
|
|
9
|
+
precision?: number;
|
|
10
|
+
currency?: boolean;
|
|
11
|
+
}
|
|
12
|
+
type RandomFunction = {
|
|
13
|
+
(options?: RandomOptions): number;
|
|
14
|
+
};
|
|
15
|
+
export declare const DEFAULT_MIN = 0;
|
|
16
|
+
export declare const DEFAULT_MAX = 1;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a random number generator with optional seeding
|
|
19
|
+
*
|
|
20
|
+
* @param defaultSeed - Seed string for the default RNG
|
|
21
|
+
* @returns A function that generates random numbers based on provided options
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const rng = random("default-seed");
|
|
25
|
+
*
|
|
26
|
+
* // Generate a random float between 0 and 1
|
|
27
|
+
* const basic = rng();
|
|
28
|
+
*
|
|
29
|
+
* // Generate an integer between 1 and 10
|
|
30
|
+
* const integer = rng({ min: 1, max: 10, integer: true });
|
|
31
|
+
*
|
|
32
|
+
* // Generate from normal distribution
|
|
33
|
+
* const normal = rng({ mean: 50, stddev: 10 });
|
|
34
|
+
*
|
|
35
|
+
* // Use consistent seeding
|
|
36
|
+
* const seeded = rng({ seed: "my-seed" });
|
|
37
|
+
*/
|
|
38
|
+
export declare function random(defaultSeed?: string): RandomFunction;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for tryParseNumber function
|
|
3
|
+
*/
|
|
4
|
+
export interface TryParseNumberOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Default value to return if parsing fails or results in NaN
|
|
7
|
+
*/
|
|
8
|
+
defaultValue?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Function to call with warning message if parsing fails or results in NaN
|
|
11
|
+
*/
|
|
12
|
+
warnFunction?: (message: string) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Attempts to parse a value as a number. Returns the original input if parsing fails or results in NaN.
|
|
16
|
+
* @param input - The value to attempt to parse as a number
|
|
17
|
+
* @param options - Optional configuration
|
|
18
|
+
* @param options.defaultValue - Default value to return if parsing fails or results in NaN
|
|
19
|
+
* @param options.warnFunction - Function to call with warning message if parsing fails or results in NaN
|
|
20
|
+
* @returns The parsed number, defaultValue (if specified and parsing fails), or the original input
|
|
21
|
+
*/
|
|
22
|
+
export declare function tryParseNumber(input: unknown, options?: TryParseNumberOptions): number | unknown;
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaypie/llm",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.27",
|
|
4
4
|
"description": "Large language model utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Finlayson Studio",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./dist/esm/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.cjs"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
|
-
"main": "dist/index.
|
|
15
|
-
"
|
|
15
|
+
"main": "./dist/cjs/index.cjs",
|
|
16
|
+
"module": "./dist/esm/index.js",
|
|
17
|
+
"types": "./dist/esm/index.d.ts",
|
|
16
18
|
"files": [
|
|
17
19
|
"dist"
|
|
18
20
|
],
|
|
@@ -41,5 +43,5 @@
|
|
|
41
43
|
"publishConfig": {
|
|
42
44
|
"access": "public"
|
|
43
45
|
},
|
|
44
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "0e8414490636bbda8f9f21bd2946d391500318a5"
|
|
45
47
|
}
|