@jaypie/llm 1.1.5 → 1.1.7
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/Llm.d.ts +12 -3
- package/dist/constants.d.ts +14 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1063 -54
- package/dist/index.js.map +1 -1
- package/dist/providers/AnthropicProvider.class.d.ts +4 -1
- package/dist/providers/openai/OpenAiProvider.class.d.ts +21 -0
- package/dist/providers/openai/index.d.ts +1 -0
- package/dist/providers/openai/operate.d.ts +26 -0
- package/dist/providers/openai/types.d.ts +92 -0
- package/dist/providers/openai/utils.d.ts +59 -0
- package/dist/tools/Toolkit.class.d.ts +15 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/random.d.ts +2 -0
- package/dist/tools/roll.d.ts +2 -0
- package/dist/tools/time.d.ts +2 -0
- package/dist/tools/weather.d.ts +2 -0
- package/dist/types/LlmProvider.interface.d.ts +128 -2
- package/dist/types/LlmTool.interface.d.ts +8 -0
- package/dist/util/formatOperateInput.d.ts +24 -0
- package/dist/util/formatOperateMessage.d.ts +24 -0
- package/dist/util/index.d.ts +7 -0
- package/dist/util/logger.d.ts +71 -0
- package/dist/util/maxTurnsFromOptions.d.ts +10 -0
- package/dist/util/naturalZodSchema.d.ts +1 -1
- package/dist/util/random.d.ts +39 -0
- package/dist/util/tryParseNumber.d.ts +22 -0
- package/package.json +7 -5
- package/dist/__tests__/Llm.class.spec.d.ts +0 -1
- package/dist/__tests__/constants.spec.d.ts +0 -1
- package/dist/__tests__/index.spec.d.ts +0 -1
- package/dist/providers/OpenAiProvider.class.d.ts +0 -13
- package/dist/providers/__tests__/OpenAiProvider.spec.d.ts +0 -1
- package/dist/util/__tests__/naturalZodSchema.spec.d.ts +0 -1
|
@@ -1,7 +1,96 @@
|
|
|
1
|
-
import { JsonObject, NaturalSchema } from "@jaypie/types";
|
|
1
|
+
import { AnyValue, JsonObject, JsonReturn, NaturalMap, NaturalSchema } from "@jaypie/types";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { LlmTool } from "./LlmTool.interface.js";
|
|
4
|
+
export declare enum LlmMessageRole {
|
|
5
|
+
Assistant = "assistant",
|
|
6
|
+
Developer = "developer",
|
|
7
|
+
System = "system",
|
|
8
|
+
User = "user"
|
|
9
|
+
}
|
|
10
|
+
export declare enum LlmMessageType {
|
|
11
|
+
FunctionCall = "function_call",
|
|
12
|
+
FunctionCallOutput = "function_call_output",
|
|
13
|
+
InputFile = "input_file",
|
|
14
|
+
InputImage = "input_image",
|
|
15
|
+
InputText = "input_text",
|
|
16
|
+
ItemReference = "item_reference",
|
|
17
|
+
Message = "message",
|
|
18
|
+
OutputText = "output_text",
|
|
19
|
+
Refusal = "refusal"
|
|
20
|
+
}
|
|
21
|
+
export declare enum LlmResponseStatus {
|
|
22
|
+
Completed = "completed",
|
|
23
|
+
Incomplete = "incomplete",
|
|
24
|
+
InProgress = "in_progress"
|
|
25
|
+
}
|
|
26
|
+
interface LlmError {
|
|
27
|
+
detail?: string;
|
|
28
|
+
status: number | string;
|
|
29
|
+
title: string;
|
|
30
|
+
}
|
|
31
|
+
interface LlmInputContentFile {
|
|
32
|
+
type: LlmMessageType.InputFile;
|
|
33
|
+
file_data: File;
|
|
34
|
+
file_id?: string;
|
|
35
|
+
filename?: string;
|
|
36
|
+
}
|
|
37
|
+
interface LlmInputContentImage {
|
|
38
|
+
type: LlmMessageType.InputImage;
|
|
39
|
+
detail: File;
|
|
40
|
+
file_id?: string;
|
|
41
|
+
image_url?: string;
|
|
42
|
+
}
|
|
43
|
+
interface LlmInputContentText {
|
|
44
|
+
type: LlmMessageType.InputText;
|
|
45
|
+
text: string;
|
|
46
|
+
}
|
|
47
|
+
type LlmInputContent = LlmInputContentFile | LlmInputContentImage | LlmInputContentText;
|
|
48
|
+
export interface LlmInputMessage {
|
|
49
|
+
content: string | Array<LlmInputContent>;
|
|
50
|
+
role: LlmMessageRole;
|
|
51
|
+
type: LlmMessageType.Message;
|
|
52
|
+
}
|
|
53
|
+
export interface LlmOutputContentText {
|
|
54
|
+
annotations?: AnyValue[];
|
|
55
|
+
text: string;
|
|
56
|
+
type: LlmMessageType.OutputText;
|
|
57
|
+
}
|
|
58
|
+
interface LlmOutputRefusal {
|
|
59
|
+
refusal: string;
|
|
60
|
+
type: LlmMessageType.Refusal;
|
|
61
|
+
}
|
|
62
|
+
type LlmOutputContent = LlmOutputContentText | LlmOutputRefusal;
|
|
63
|
+
export interface LlmOutputMessage {
|
|
64
|
+
content: Array<LlmOutputContent>;
|
|
65
|
+
id?: string;
|
|
66
|
+
role: LlmMessageRole.Assistant;
|
|
67
|
+
status: LlmResponseStatus;
|
|
68
|
+
type: LlmMessageType.Message;
|
|
69
|
+
}
|
|
70
|
+
type LlmOutputItem = LlmToolCall | LlmToolResult | LlmOutputMessage;
|
|
71
|
+
type LlmOutput = LlmOutputItem[];
|
|
72
|
+
export interface LlmToolCall {
|
|
73
|
+
arguments: string;
|
|
74
|
+
call_id: string;
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
type: LlmMessageType.FunctionCall;
|
|
78
|
+
status: LlmResponseStatus;
|
|
79
|
+
}
|
|
80
|
+
export interface LlmToolResult {
|
|
81
|
+
call_id: string;
|
|
82
|
+
output: string;
|
|
83
|
+
status?: LlmResponseStatus;
|
|
84
|
+
type: LlmMessageType.FunctionCallOutput;
|
|
85
|
+
}
|
|
86
|
+
interface LlmItemReference {
|
|
87
|
+
type: LlmMessageType.ItemReference;
|
|
88
|
+
id: string;
|
|
89
|
+
}
|
|
90
|
+
export type LlmHistoryItem = LlmInputMessage | LlmItemReference | LlmOutputItem | LlmToolResult;
|
|
91
|
+
export type LlmHistory = LlmHistoryItem[];
|
|
3
92
|
export interface LlmMessageOptions {
|
|
4
|
-
data?:
|
|
93
|
+
data?: NaturalMap;
|
|
5
94
|
model?: string;
|
|
6
95
|
placeholders?: {
|
|
7
96
|
message?: boolean;
|
|
@@ -10,6 +99,43 @@ export interface LlmMessageOptions {
|
|
|
10
99
|
response?: NaturalSchema | z.ZodType;
|
|
11
100
|
system?: string;
|
|
12
101
|
}
|
|
102
|
+
export interface LlmOperateOptions {
|
|
103
|
+
data?: NaturalMap;
|
|
104
|
+
explain?: boolean;
|
|
105
|
+
format?: JsonObject | NaturalSchema | z.ZodType;
|
|
106
|
+
history?: LlmHistory;
|
|
107
|
+
instructions?: string;
|
|
108
|
+
model?: string;
|
|
109
|
+
placeholders?: {
|
|
110
|
+
input?: boolean;
|
|
111
|
+
instructions?: boolean;
|
|
112
|
+
};
|
|
113
|
+
providerOptions?: Record<string, AnyValue>;
|
|
114
|
+
tools?: LlmTool[];
|
|
115
|
+
turns?: boolean | number;
|
|
116
|
+
user?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface LlmOptions {
|
|
119
|
+
apiKey?: string;
|
|
120
|
+
model?: string;
|
|
121
|
+
}
|
|
122
|
+
interface LlmUsage {
|
|
123
|
+
input: number;
|
|
124
|
+
output: number;
|
|
125
|
+
reasoning: number;
|
|
126
|
+
total: number;
|
|
127
|
+
}
|
|
128
|
+
export interface LlmOperateResponse {
|
|
129
|
+
content?: string;
|
|
130
|
+
error?: LlmError;
|
|
131
|
+
history: LlmHistory;
|
|
132
|
+
output: LlmOutput;
|
|
133
|
+
responses: JsonReturn[];
|
|
134
|
+
status: LlmResponseStatus;
|
|
135
|
+
usage: LlmUsage;
|
|
136
|
+
}
|
|
13
137
|
export interface LlmProvider {
|
|
138
|
+
operate?(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
|
|
14
139
|
send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
|
|
15
140
|
}
|
|
141
|
+
export {};
|
|
@@ -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,7 @@
|
|
|
1
|
+
export * from "./formatOperateInput.js";
|
|
2
|
+
export * from "./formatOperateMessage.js";
|
|
3
|
+
export * from "./logger.js";
|
|
4
|
+
export * from "./maxTurnsFromOptions.js";
|
|
5
|
+
export * from "./naturalZodSchema.js";
|
|
6
|
+
export * from "./random.js";
|
|
7
|
+
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaypie/llm",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Large language model utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Finlayson Studio",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "rollup --config",
|
|
20
|
+
"build:manual": "rollup --config",
|
|
21
21
|
"format": "eslint . --fix",
|
|
22
22
|
"lint": "eslint .",
|
|
23
23
|
"test": "vitest run .",
|
|
@@ -26,14 +26,16 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@jaypie/aws": "^1.1.15",
|
|
28
28
|
"@jaypie/core": "^1.1.2",
|
|
29
|
-
"openai": "^4.
|
|
29
|
+
"openai": "^4.87.3",
|
|
30
|
+
"openmeteo": "^1.2.0",
|
|
31
|
+
"random": "^5.3.0",
|
|
30
32
|
"zod": "^3.24.1"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@jaypie/types": "^0.1.
|
|
35
|
+
"@jaypie/types": "^0.1.3"
|
|
34
36
|
},
|
|
35
37
|
"publishConfig": {
|
|
36
38
|
"access": "public"
|
|
37
39
|
},
|
|
38
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "8afa77184376db70544710e7414de80ed3a0f60a"
|
|
39
41
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { JsonObject } from "@jaypie/types";
|
|
2
|
-
import { LlmProvider, LlmMessageOptions } from "../types/LlmProvider.interface.js";
|
|
3
|
-
export declare class OpenAiProvider implements LlmProvider {
|
|
4
|
-
private model;
|
|
5
|
-
private _client?;
|
|
6
|
-
private apiKey?;
|
|
7
|
-
private log;
|
|
8
|
-
constructor(model?: string, { apiKey }?: {
|
|
9
|
-
apiKey?: string;
|
|
10
|
-
});
|
|
11
|
-
private getClient;
|
|
12
|
-
send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|