@nx-ddd/any-func 19.2.0 → 19.3.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/adapters/local-storage/index.d.ts +5 -0
- package/adapters/local-storage-browser/index.d.ts +8 -0
- package/adapters/local-storage-node/index.d.ts +5 -0
- package/adapters/validator/index.d.ts +10 -0
- package/adapters/validator-commonjs/index.d.ts +13 -0
- package/adapters/validator-esmodule/index.d.ts +15 -0
- package/browser/index.d.ts +6 -0
- package/fesm2022/nx-ddd-any-func-adapters-local-storage-browser.mjs +12 -0
- package/fesm2022/nx-ddd-any-func-adapters-local-storage-browser.mjs.map +1 -0
- package/fesm2022/nx-ddd-any-func-adapters-local-storage-node.mjs +16 -0
- package/fesm2022/nx-ddd-any-func-adapters-local-storage-node.mjs.map +1 -0
- package/fesm2022/nx-ddd-any-func-adapters-local-storage.mjs +10 -0
- package/fesm2022/nx-ddd-any-func-adapters-local-storage.mjs.map +1 -0
- package/fesm2022/nx-ddd-any-func-adapters-validator-commonjs.mjs +33 -0
- package/fesm2022/nx-ddd-any-func-adapters-validator-commonjs.mjs.map +1 -0
- package/fesm2022/nx-ddd-any-func-adapters-validator-esmodule.mjs +28 -0
- package/fesm2022/nx-ddd-any-func-adapters-validator-esmodule.mjs.map +1 -0
- package/fesm2022/nx-ddd-any-func-adapters-validator.mjs +17 -0
- package/fesm2022/nx-ddd-any-func-adapters-validator.mjs.map +1 -0
- package/fesm2022/nx-ddd-any-func-browser.mjs +19 -0
- package/fesm2022/nx-ddd-any-func-browser.mjs.map +1 -0
- package/fesm2022/nx-ddd-any-func-server.mjs +19 -0
- package/fesm2022/nx-ddd-any-func-server.mjs.map +1 -0
- package/fesm2022/nx-ddd-any-func.mjs +432 -0
- package/fesm2022/nx-ddd-any-func.mjs.map +1 -0
- package/index.d.ts +151 -1
- package/package.json +50 -13
- package/server/index.d.ts +6 -0
- package/README.md +0 -7
- package/index.js +0 -5
- package/index.js.map +0 -1
- package/lib/agent/agent.d.ts +0 -53
- package/lib/agent/agent.js +0 -103
- package/lib/agent/agent.js.map +0 -1
- package/lib/agent/index.d.ts +0 -1
- package/lib/agent/index.js +0 -5
- package/lib/agent/index.js.map +0 -1
- package/lib/any-func/any-func.service.d.ts +0 -4
- package/lib/any-func/any-func.service.impl.d.ts +0 -67
- package/lib/any-func/any-func.service.impl.js +0 -261
- package/lib/any-func/any-func.service.impl.js.map +0 -1
- package/lib/any-func/any-func.service.js +0 -11
- package/lib/any-func/any-func.service.js.map +0 -1
- package/lib/any-func/index.d.ts +0 -1
- package/lib/any-func/index.js +0 -5
- package/lib/any-func/index.js.map +0 -1
- package/lib/browser.d.ts +0 -3
- package/lib/browser.js +0 -15
- package/lib/browser.js.map +0 -1
- package/lib/impl/adapters/cache/cache.adapter.d.ts +0 -9
- package/lib/impl/adapters/cache/cache.adapter.js +0 -50
- package/lib/impl/adapters/cache/cache.adapter.js.map +0 -1
- package/lib/impl/adapters/cache/index.d.ts +0 -1
- package/lib/impl/adapters/cache/index.js +0 -5
- package/lib/impl/adapters/cache/index.js.map +0 -1
- package/lib/impl/adapters/local-storage/browser.d.ts +0 -4
- package/lib/impl/adapters/local-storage/browser.js +0 -8
- package/lib/impl/adapters/local-storage/browser.js.map +0 -1
- package/lib/impl/adapters/local-storage/index.d.ts +0 -1
- package/lib/impl/adapters/local-storage/index.js +0 -5
- package/lib/impl/adapters/local-storage/index.js.map +0 -1
- package/lib/impl/adapters/local-storage/node.d.ts +0 -2
- package/lib/impl/adapters/local-storage/node.js +0 -12
- package/lib/impl/adapters/local-storage/node.js.map +0 -1
- package/lib/impl/adapters/local-storage/token.d.ts +0 -1
- package/lib/impl/adapters/local-storage/token.js +0 -6
- package/lib/impl/adapters/local-storage/token.js.map +0 -1
- package/lib/impl/adapters/validator/commonjs.d.ts +0 -7
- package/lib/impl/adapters/validator/commonjs.js +0 -33
- package/lib/impl/adapters/validator/commonjs.js.map +0 -1
- package/lib/impl/adapters/validator/esmodule.d.ts +0 -9
- package/lib/impl/adapters/validator/esmodule.js +0 -25
- package/lib/impl/adapters/validator/esmodule.js.map +0 -1
- package/lib/impl/adapters/validator/validator.adapter.d.ts +0 -4
- package/lib/impl/adapters/validator/validator.adapter.js +0 -12
- package/lib/impl/adapters/validator/validator.adapter.js.map +0 -1
- package/lib/impl/index.d.ts +0 -2
- package/lib/impl/index.js +0 -6
- package/lib/impl/index.js.map +0 -1
- package/lib/impl/json-schema/default-metadata-storage.d.ts +0 -2
- package/lib/impl/json-schema/default-metadata-storage.js +0 -19
- package/lib/impl/json-schema/default-metadata-storage.js.map +0 -1
- package/lib/impl/json-schema/index.d.ts +0 -1
- package/lib/impl/json-schema/index.js +0 -5
- package/lib/impl/json-schema/index.js.map +0 -1
- package/lib/impl/json-schema/json-schema.d.ts +0 -3
- package/lib/impl/json-schema/json-schema.js +0 -49
- package/lib/impl/json-schema/json-schema.js.map +0 -1
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -7
- package/lib/index.js.map +0 -1
- package/lib/server.d.ts +0 -3
- package/lib/server.js +0 -15
- package/lib/server.js.map +0 -1
- package/lib/utils/debug-price.d.ts +0 -1
- package/lib/utils/debug-price.js +0 -42
- package/lib/utils/debug-price.js.map +0 -1
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -5
- package/lib/utils/index.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1 +1,151 @@
|
|
|
1
|
-
|
|
1
|
+
import * as openai_resources from 'openai/resources';
|
|
2
|
+
import { FunctionParameters, ChatCompletionMessageParam } from 'openai/resources';
|
|
3
|
+
import { FunctionTool } from 'openai/resources/beta/assistants';
|
|
4
|
+
import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions';
|
|
5
|
+
import * as _nx_ddd_common_infrastructure_externals_openai_impl from '@nx-ddd/common/infrastructure/externals/openai/impl';
|
|
6
|
+
import { OpenAiServiceImpl } from '@nx-ddd/common/infrastructure/externals/openai/impl';
|
|
7
|
+
import * as i0 from '@angular/core';
|
|
8
|
+
import { InjectionToken } from '@angular/core';
|
|
9
|
+
import { ClientOptions } from 'openai';
|
|
10
|
+
import { ZodSchema } from 'zod';
|
|
11
|
+
import { JsonSchema, JsonError } from 'json-schema-library';
|
|
12
|
+
import { IOptions } from 'class-validator-jsonschema/build/options';
|
|
13
|
+
import { JSONSchema7 } from 'json-schema';
|
|
14
|
+
|
|
15
|
+
declare const AI_TOOLS: "[ai-tools]";
|
|
16
|
+
declare const AI_SYSTEM: "[ai-system]";
|
|
17
|
+
declare function addTool(obj: {
|
|
18
|
+
[AI_TOOLS]: object[];
|
|
19
|
+
}, tool: object): {
|
|
20
|
+
"[ai-tools]": object[];
|
|
21
|
+
};
|
|
22
|
+
declare function getTools(obj: {
|
|
23
|
+
[AI_TOOLS]: object[];
|
|
24
|
+
}): any[];
|
|
25
|
+
declare function buildFunctionTool(params: {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
parameters: FunctionParameters;
|
|
29
|
+
}): FunctionTool;
|
|
30
|
+
declare function buildToolFromSchema(name: string, description: string, schema: Function): FunctionTool;
|
|
31
|
+
declare function AiFunction(params?: {
|
|
32
|
+
description?: string;
|
|
33
|
+
}): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
34
|
+
interface AiSystemConfig {
|
|
35
|
+
model?: ChatCompletionCreateParamsBase['model'];
|
|
36
|
+
instructions?: string;
|
|
37
|
+
shots?: {
|
|
38
|
+
input: string;
|
|
39
|
+
output: string;
|
|
40
|
+
}[];
|
|
41
|
+
}
|
|
42
|
+
declare function setAiSystemConfig(obj: {
|
|
43
|
+
[AI_SYSTEM]: AiSystemConfig;
|
|
44
|
+
}, config: AiSystemConfig): {
|
|
45
|
+
"[ai-system]": AiSystemConfig;
|
|
46
|
+
};
|
|
47
|
+
declare function getAiSystemConfig(obj: {
|
|
48
|
+
[AI_SYSTEM]: AiSystemConfig;
|
|
49
|
+
}): AiSystemConfig;
|
|
50
|
+
declare function AiSystem({ model, instructions, shots, }: AiSystemConfig): (target: any) => any;
|
|
51
|
+
declare class AiToolsAgent {
|
|
52
|
+
protected openai: OpenAiServiceImpl;
|
|
53
|
+
constructor(openai: OpenAiServiceImpl);
|
|
54
|
+
messages: ChatCompletionMessageParam[];
|
|
55
|
+
results: any[];
|
|
56
|
+
get tools(): any[];
|
|
57
|
+
get config(): AiSystemConfig;
|
|
58
|
+
completion(tools?: any[]): Promise<void>;
|
|
59
|
+
execute<T = any>(message: string, options?: {
|
|
60
|
+
tools?: any[];
|
|
61
|
+
}): Promise<T>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare class CacheAdapter {
|
|
65
|
+
protected localStorage: LocalStorage;
|
|
66
|
+
get<T>(keyOrObj: string | object): Promise<T | null>;
|
|
67
|
+
set(keyOrObj: string | object, value: any): Promise<void>;
|
|
68
|
+
call<P extends (string | object), T>(props: P, callback: (props: P) => Promise<T>): Promise<T>;
|
|
69
|
+
protected makeKey(keyOrObj: string | object): string;
|
|
70
|
+
protected makeJson(valueOrObj: any): string;
|
|
71
|
+
protected parseJson(value: string): any;
|
|
72
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CacheAdapter, never>;
|
|
73
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CacheAdapter>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare abstract class ValidatorAdapter {
|
|
77
|
+
abstract validate(schema: JsonSchema, data: any): Promise<JsonError[]>;
|
|
78
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ValidatorAdapter, never>;
|
|
79
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ValidatorAdapter>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface CallOptions<I, O, S extends {
|
|
83
|
+
input: I;
|
|
84
|
+
output: O;
|
|
85
|
+
} = {
|
|
86
|
+
input: I;
|
|
87
|
+
output: O;
|
|
88
|
+
}> {
|
|
89
|
+
instructions?: string;
|
|
90
|
+
model?: string;
|
|
91
|
+
specs?: S[];
|
|
92
|
+
embeddings?: false | ((spec: S) => string);
|
|
93
|
+
sample?: number;
|
|
94
|
+
temperature?: number;
|
|
95
|
+
maxRetry?: number;
|
|
96
|
+
validator?: (output: O) => Promise<any>;
|
|
97
|
+
}
|
|
98
|
+
interface AnyFuncConfig extends ClientOptions {
|
|
99
|
+
debug: boolean;
|
|
100
|
+
openaiApiKey: string;
|
|
101
|
+
}
|
|
102
|
+
declare function provideAnyFunc(useFactory?: () => AnyFuncConfig): (i0.Provider[] | {
|
|
103
|
+
provide: InjectionToken<AnyFuncService>;
|
|
104
|
+
useClass: typeof AnyFuncService;
|
|
105
|
+
useFactory?: undefined;
|
|
106
|
+
} | {
|
|
107
|
+
provide: InjectionToken<AnyFuncConfig>;
|
|
108
|
+
useFactory: () => AnyFuncConfig;
|
|
109
|
+
useClass?: undefined;
|
|
110
|
+
})[];
|
|
111
|
+
declare class AnyFuncService {
|
|
112
|
+
protected readonly openai: _nx_ddd_common_infrastructure_externals_openai_impl.OpenAiServiceImpl;
|
|
113
|
+
protected readonly config: AnyFuncConfig | {
|
|
114
|
+
debug: false;
|
|
115
|
+
};
|
|
116
|
+
protected cache: CacheAdapter;
|
|
117
|
+
protected validator: ValidatorAdapter;
|
|
118
|
+
/** @deprecated use callByJsonSchema instead */
|
|
119
|
+
jsonSchema(_input: any, jsonSchema: FunctionParameters, options?: CallOptions<any, any>): Promise<any>;
|
|
120
|
+
callByJsonSchema(_input: any, jsonSchema: FunctionParameters, { instructions, model, specs, embeddings, sample, temperature, maxRetry, validator, }?: CallOptions<any, any>): Promise<any>;
|
|
121
|
+
callByZod<I, O>(_input: I, zod: ZodSchema<O>, { instructions, model, specs, embeddings, sample, temperature, maxRetry, validator, }?: CallOptions<I, O>): Promise<O>;
|
|
122
|
+
callByClassValidator<I, O>(_input: I, args: {
|
|
123
|
+
new (): O;
|
|
124
|
+
}, { instructions, model, specs, embeddings, sample, temperature, maxRetry, validator, }?: CallOptions<I, O>): Promise<O>;
|
|
125
|
+
call<I, O>(_input: I, args: {
|
|
126
|
+
new (): O;
|
|
127
|
+
} | ZodSchema<O> | JsonSchema, params?: CallOptions<I, O>): Promise<O>;
|
|
128
|
+
protected complete<I, O>(_input: any, jsonSchema: FunctionParameters, messages: ChatCompletionMessageParam[], { model, temperature, }?: CallOptions<I, O> & {
|
|
129
|
+
functionOutput?: object;
|
|
130
|
+
}): Promise<openai_resources.ChatCompletionMessage>;
|
|
131
|
+
protected buildChatMessages(specs: {
|
|
132
|
+
input: any;
|
|
133
|
+
output: any;
|
|
134
|
+
}[]): Promise<{
|
|
135
|
+
role: 'assistant' | 'user';
|
|
136
|
+
content: string;
|
|
137
|
+
}[]>;
|
|
138
|
+
getEmbeddings<T>(item: T, accessor: (item: T) => string): Promise<number[]>;
|
|
139
|
+
sort<T>(items: T[], accessor: (item: T) => string, target: string): Promise<T[]>;
|
|
140
|
+
private parseInput;
|
|
141
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AnyFuncService, never>;
|
|
142
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<AnyFuncService>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
declare const ANY_FUNC_SERVICE: InjectionToken<AnyFuncService>;
|
|
146
|
+
declare function injectAnyFunc(): AnyFuncService;
|
|
147
|
+
|
|
148
|
+
declare function targetConstructorToSchema(target: Function, options?: Partial<IOptions>): JSONSchema7;
|
|
149
|
+
|
|
150
|
+
export { ANY_FUNC_SERVICE, AiFunction, AiSystem, AiToolsAgent, AnyFuncService, addTool, buildFunctionTool, buildToolFromSchema, getAiSystemConfig, getTools, injectAnyFunc, provideAnyFunc, setAiSystemConfig, targetConstructorToSchema };
|
|
151
|
+
export type { AiSystemConfig, AnyFuncConfig, CallOptions };
|
package/package.json
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx-ddd/any-func",
|
|
3
|
-
"version": "19.
|
|
4
|
-
"main": "./index.js",
|
|
5
|
-
"types": "./index.d.ts",
|
|
6
|
-
"homepage": "https://github.com/xx-machina/plaform/tree/main/packages/@nx-ddd/any-func",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/xx-machina/plaform.git"
|
|
10
|
-
},
|
|
3
|
+
"version": "19.3.0",
|
|
11
4
|
"peerDependencies": {
|
|
12
|
-
"@angular/core": "
|
|
13
|
-
"@nx-ddd/common": "19.
|
|
5
|
+
"@angular/core": ">=17.0.0",
|
|
6
|
+
"@nx-ddd/common": "19.3.0",
|
|
14
7
|
"class-transformer": "^0.5.1",
|
|
15
8
|
"class-validator": "^0.14.0",
|
|
16
9
|
"class-validator-jsonschema": "^5.0.0",
|
|
@@ -20,9 +13,53 @@
|
|
|
20
13
|
"openai": "^4.95.0",
|
|
21
14
|
"p-limit": "^6.1.0",
|
|
22
15
|
"rxjs": "^7.8.0",
|
|
23
|
-
"tslib": "^2.3.0",
|
|
24
16
|
"json-schema": "0.4.0"
|
|
25
17
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
18
|
+
"module": "fesm2022/nx-ddd-any-func.mjs",
|
|
19
|
+
"typings": "index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
"./package.json": {
|
|
22
|
+
"default": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./index.d.ts",
|
|
26
|
+
"default": "./fesm2022/nx-ddd-any-func.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./browser": {
|
|
29
|
+
"types": "./browser/index.d.ts",
|
|
30
|
+
"default": "./fesm2022/nx-ddd-any-func-browser.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./server": {
|
|
33
|
+
"types": "./server/index.d.ts",
|
|
34
|
+
"default": "./fesm2022/nx-ddd-any-func-server.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./adapters/local-storage": {
|
|
37
|
+
"types": "./adapters/local-storage/index.d.ts",
|
|
38
|
+
"default": "./fesm2022/nx-ddd-any-func-adapters-local-storage.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./adapters/local-storage-browser": {
|
|
41
|
+
"types": "./adapters/local-storage-browser/index.d.ts",
|
|
42
|
+
"default": "./fesm2022/nx-ddd-any-func-adapters-local-storage-browser.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./adapters/local-storage-node": {
|
|
45
|
+
"types": "./adapters/local-storage-node/index.d.ts",
|
|
46
|
+
"default": "./fesm2022/nx-ddd-any-func-adapters-local-storage-node.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./adapters/validator": {
|
|
49
|
+
"types": "./adapters/validator/index.d.ts",
|
|
50
|
+
"default": "./fesm2022/nx-ddd-any-func-adapters-validator.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./adapters/validator-commonjs": {
|
|
53
|
+
"types": "./adapters/validator-commonjs/index.d.ts",
|
|
54
|
+
"default": "./fesm2022/nx-ddd-any-func-adapters-validator-commonjs.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./adapters/validator-esmodule": {
|
|
57
|
+
"types": "./adapters/validator-esmodule/index.d.ts",
|
|
58
|
+
"default": "./fesm2022/nx-ddd-any-func-adapters-validator-esmodule.mjs"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"sideEffects": false,
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"tslib": "^2.3.0"
|
|
64
|
+
}
|
|
28
65
|
}
|
package/README.md
DELETED
package/index.js
DELETED
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/@nx-ddd/any-func/src/index.ts"],"names":[],"mappings":";;;AAAA,gDAAsB"}
|
package/lib/agent/agent.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ChatCompletionMessageParam, FunctionParameters } from "openai/resources";
|
|
2
|
-
import { FunctionTool } from "openai/resources/beta/assistants";
|
|
3
|
-
import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions";
|
|
4
|
-
import { OpenAiServiceImpl } from '@nx-ddd/common/infrastructure/externals/openai/impl';
|
|
5
|
-
declare const AI_TOOLS: "[ai-tools]";
|
|
6
|
-
declare const AI_SYSTEM: "[ai-system]";
|
|
7
|
-
export declare function addTool(obj: {
|
|
8
|
-
[AI_TOOLS]: object[];
|
|
9
|
-
}, tool: object): {
|
|
10
|
-
"[ai-tools]": object[];
|
|
11
|
-
};
|
|
12
|
-
export declare function getTools(obj: {
|
|
13
|
-
[AI_TOOLS]: object[];
|
|
14
|
-
}): any[];
|
|
15
|
-
export declare function buildFunctionTool(params: {
|
|
16
|
-
name: string;
|
|
17
|
-
description: string;
|
|
18
|
-
parameters: FunctionParameters;
|
|
19
|
-
}): FunctionTool;
|
|
20
|
-
export declare function buildToolFromSchema(name: string, description: string, schema: Function): FunctionTool;
|
|
21
|
-
export declare function AiFunction(params?: {
|
|
22
|
-
description?: string;
|
|
23
|
-
}): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
24
|
-
export interface AiSystemConfig {
|
|
25
|
-
model?: ChatCompletionCreateParamsBase['model'];
|
|
26
|
-
instructions?: string;
|
|
27
|
-
shots?: {
|
|
28
|
-
input: string;
|
|
29
|
-
output: string;
|
|
30
|
-
}[];
|
|
31
|
-
}
|
|
32
|
-
export declare function setAiSystemConfig(obj: {
|
|
33
|
-
[AI_SYSTEM]: AiSystemConfig;
|
|
34
|
-
}, config: AiSystemConfig): {
|
|
35
|
-
"[ai-system]": AiSystemConfig;
|
|
36
|
-
};
|
|
37
|
-
export declare function getAiSystemConfig(obj: {
|
|
38
|
-
[AI_SYSTEM]: AiSystemConfig;
|
|
39
|
-
}): AiSystemConfig;
|
|
40
|
-
export declare function AiSystem({ model, instructions, shots, }: AiSystemConfig): (target: any) => any;
|
|
41
|
-
export declare class AiToolsAgent {
|
|
42
|
-
protected openai: OpenAiServiceImpl;
|
|
43
|
-
constructor(openai: OpenAiServiceImpl);
|
|
44
|
-
messages: ChatCompletionMessageParam[];
|
|
45
|
-
results: any[];
|
|
46
|
-
get tools(): any[];
|
|
47
|
-
get config(): AiSystemConfig;
|
|
48
|
-
completion(tools?: any[]): Promise<void>;
|
|
49
|
-
execute<T = any>(message: string, options?: {
|
|
50
|
-
tools?: any[];
|
|
51
|
-
}): Promise<T>;
|
|
52
|
-
}
|
|
53
|
-
export {};
|
package/lib/agent/agent.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AiToolsAgent = void 0;
|
|
4
|
-
exports.addTool = addTool;
|
|
5
|
-
exports.getTools = getTools;
|
|
6
|
-
exports.buildFunctionTool = buildFunctionTool;
|
|
7
|
-
exports.buildToolFromSchema = buildToolFromSchema;
|
|
8
|
-
exports.AiFunction = AiFunction;
|
|
9
|
-
exports.setAiSystemConfig = setAiSystemConfig;
|
|
10
|
-
exports.getAiSystemConfig = getAiSystemConfig;
|
|
11
|
-
exports.AiSystem = AiSystem;
|
|
12
|
-
const tslib_1 = require("tslib");
|
|
13
|
-
const json_schema_1 = require("../impl/json-schema");
|
|
14
|
-
const AI_TOOLS = '[ai-tools]';
|
|
15
|
-
const AI_SYSTEM = '[ai-system]';
|
|
16
|
-
function addTool(obj, tool) {
|
|
17
|
-
var _a;
|
|
18
|
-
obj[AI_TOOLS] = (_a = obj[AI_TOOLS]) !== null && _a !== void 0 ? _a : [];
|
|
19
|
-
obj[AI_TOOLS].push(tool);
|
|
20
|
-
return obj;
|
|
21
|
-
}
|
|
22
|
-
function getTools(obj) {
|
|
23
|
-
var _a;
|
|
24
|
-
return (_a = obj[AI_TOOLS]) !== null && _a !== void 0 ? _a : [];
|
|
25
|
-
}
|
|
26
|
-
function buildFunctionTool(params) {
|
|
27
|
-
return {
|
|
28
|
-
type: 'function',
|
|
29
|
-
function: {
|
|
30
|
-
name: params.name,
|
|
31
|
-
description: params.description,
|
|
32
|
-
parameters: params.parameters,
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function buildToolFromSchema(name, description, schema) {
|
|
37
|
-
const parameters = (0, json_schema_1.targetConstructorToSchema)(schema);
|
|
38
|
-
return buildFunctionTool({ name, description, parameters });
|
|
39
|
-
}
|
|
40
|
-
function AiFunction(params) {
|
|
41
|
-
return function (target, propertyKey, descriptor) {
|
|
42
|
-
var _a;
|
|
43
|
-
// 引数の型を取得
|
|
44
|
-
const args = Reflect.getMetadata('design:paramtypes', target, propertyKey);
|
|
45
|
-
const tool = buildToolFromSchema(propertyKey, (_a = params === null || params === void 0 ? void 0 : params.description) !== null && _a !== void 0 ? _a : '', args[0]);
|
|
46
|
-
addTool(target, tool);
|
|
47
|
-
return descriptor;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function setAiSystemConfig(obj, config) {
|
|
51
|
-
obj[AI_SYSTEM] = config;
|
|
52
|
-
return obj;
|
|
53
|
-
}
|
|
54
|
-
function getAiSystemConfig(obj) {
|
|
55
|
-
return obj[AI_SYSTEM];
|
|
56
|
-
}
|
|
57
|
-
function AiSystem({ model = 'gpt-4-1106-preview', instructions = ``, shots = [], }) {
|
|
58
|
-
return function (target) {
|
|
59
|
-
setAiSystemConfig(target, { model, instructions, shots });
|
|
60
|
-
return target;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
class AiToolsAgent {
|
|
64
|
-
constructor(openai) {
|
|
65
|
-
this.openai = openai;
|
|
66
|
-
this.messages = [
|
|
67
|
-
{ role: 'system', content: '' },
|
|
68
|
-
];
|
|
69
|
-
this.results = [];
|
|
70
|
-
}
|
|
71
|
-
get tools() {
|
|
72
|
-
return getTools(this.constructor);
|
|
73
|
-
}
|
|
74
|
-
get config() {
|
|
75
|
-
return getAiSystemConfig(this.constructor);
|
|
76
|
-
}
|
|
77
|
-
completion() {
|
|
78
|
-
return tslib_1.__awaiter(this, arguments, void 0, function* (tools = this.tools) {
|
|
79
|
-
var _a, _b, _c, _d;
|
|
80
|
-
const message = yield this.openai.chat.completions.create({
|
|
81
|
-
model: this.config.model,
|
|
82
|
-
messages: this.messages,
|
|
83
|
-
tools,
|
|
84
|
-
});
|
|
85
|
-
for (const call of (_d = (_c = (_b = (_a = message.choices) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.tool_calls) !== null && _d !== void 0 ? _d : []) {
|
|
86
|
-
if (call.type === 'function') {
|
|
87
|
-
const func = this[call.function.name];
|
|
88
|
-
const result = func(JSON.parse(call.function.arguments));
|
|
89
|
-
this.results.push(result);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
execute(message_1) {
|
|
95
|
-
return tslib_1.__awaiter(this, arguments, void 0, function* (message, options = {}) {
|
|
96
|
-
this.messages.push({ role: 'user', content: message });
|
|
97
|
-
yield this.completion(options.tools);
|
|
98
|
-
return this.results.at(-1);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.AiToolsAgent = AiToolsAgent;
|
|
103
|
-
//# sourceMappingURL=agent.js.map
|
package/lib/agent/agent.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../../../../packages/@nx-ddd/any-func/src/lib/agent/agent.ts"],"names":[],"mappings":";;;AASA,0BAIC;AAED,4BAEC;AAED,8CAaC;AAED,kDAGC;AAED,gCAQC;AAQD,8CAGC;AAED,8CAEC;AAED,4BASC;;AArED,qDAAgE;AAEhE,MAAM,QAAQ,GAAG,YAAqB,CAAC;AACvC,MAAM,SAAS,GAAG,aAAsB,CAAC;AAEzC,SAAgB,OAAO,CAAC,GAA2B,EAAE,IAAY;;IAC/D,GAAG,CAAC,QAAQ,CAAC,GAAG,MAAA,GAAG,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAC;IAC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CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;oBACzD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAEK,OAAO;qEAAQ,OAAe,EAAE,UAA2B,EAAE;YACjE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAC,CAAC,CAAC;YACrD,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACrC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAQ,CAAC;QACpC,CAAC;KAAA;CACF;AArCD,oCAqCC"}
|
package/lib/agent/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './agent';
|
package/lib/agent/index.js
DELETED
package/lib/agent/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/@nx-ddd/any-func/src/lib/agent/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { InjectionToken } from '@angular/core';
|
|
2
|
-
import type { ChatCompletionMessageParam, FunctionParameters } from 'openai/resources';
|
|
3
|
-
import { ClientOptions } from 'openai';
|
|
4
|
-
import { ZodSchema } from 'zod';
|
|
5
|
-
import { CacheAdapter } from '../impl/adapters/cache';
|
|
6
|
-
import { ValidatorAdapter } from '../impl/adapters/validator/validator.adapter';
|
|
7
|
-
import { JsonSchema } from 'json-schema-library';
|
|
8
|
-
export interface CallOptions<I, O, S extends {
|
|
9
|
-
input: I;
|
|
10
|
-
output: O;
|
|
11
|
-
} = {
|
|
12
|
-
input: I;
|
|
13
|
-
output: O;
|
|
14
|
-
}> {
|
|
15
|
-
instructions?: string;
|
|
16
|
-
model?: string;
|
|
17
|
-
specs?: S[];
|
|
18
|
-
embeddings?: false | ((spec: S) => string);
|
|
19
|
-
sample?: number;
|
|
20
|
-
temperature?: number;
|
|
21
|
-
maxRetry?: number;
|
|
22
|
-
validator?: (output: O) => Promise<any>;
|
|
23
|
-
}
|
|
24
|
-
export interface AnyFuncConfig extends ClientOptions {
|
|
25
|
-
debug: boolean;
|
|
26
|
-
openaiApiKey: string;
|
|
27
|
-
}
|
|
28
|
-
export declare function provideAnyFunc(useFactory?: () => AnyFuncConfig): (import("@angular/core").Provider[] | {
|
|
29
|
-
provide: InjectionToken<AnyFuncService>;
|
|
30
|
-
useClass: typeof AnyFuncService;
|
|
31
|
-
useFactory?: undefined;
|
|
32
|
-
} | {
|
|
33
|
-
provide: InjectionToken<AnyFuncConfig>;
|
|
34
|
-
useFactory: () => AnyFuncConfig;
|
|
35
|
-
useClass?: undefined;
|
|
36
|
-
})[];
|
|
37
|
-
export declare class AnyFuncService {
|
|
38
|
-
protected readonly openai: import("@nx-ddd/common/infrastructure/externals/openai/impl").OpenAiServiceImpl;
|
|
39
|
-
protected readonly config: AnyFuncConfig | {
|
|
40
|
-
debug: false;
|
|
41
|
-
};
|
|
42
|
-
protected cache: CacheAdapter;
|
|
43
|
-
protected validator: ValidatorAdapter;
|
|
44
|
-
/** @deprecated use callByJsonSchema instead */
|
|
45
|
-
jsonSchema(_input: any, jsonSchema: FunctionParameters, options?: CallOptions<any, any>): Promise<any>;
|
|
46
|
-
callByJsonSchema(_input: any, jsonSchema: FunctionParameters, { instructions, model, specs, embeddings, sample, temperature, maxRetry, validator, }?: CallOptions<any, any>): Promise<any>;
|
|
47
|
-
callByZod<I, O>(_input: I, zod: ZodSchema<O>, { instructions, model, specs, embeddings, sample, temperature, maxRetry, validator, }?: CallOptions<I, O>): Promise<O>;
|
|
48
|
-
callByClassValidator<I, O>(_input: I, args: {
|
|
49
|
-
new (): O;
|
|
50
|
-
}, { instructions, model, specs, embeddings, sample, temperature, maxRetry, validator, }?: CallOptions<I, O>): Promise<O>;
|
|
51
|
-
call<I, O>(_input: I, args: {
|
|
52
|
-
new (): O;
|
|
53
|
-
} | ZodSchema<O> | JsonSchema, params?: CallOptions<I, O>): Promise<O>;
|
|
54
|
-
protected complete<I, O>(_input: any, jsonSchema: FunctionParameters, messages: ChatCompletionMessageParam[], { model, temperature, }?: CallOptions<I, O> & {
|
|
55
|
-
functionOutput?: object;
|
|
56
|
-
}): Promise<import("openai/resources").ChatCompletionMessage>;
|
|
57
|
-
protected buildChatMessages(specs: {
|
|
58
|
-
input: any;
|
|
59
|
-
output: any;
|
|
60
|
-
}[]): Promise<{
|
|
61
|
-
role: 'assistant' | 'user';
|
|
62
|
-
content: string;
|
|
63
|
-
}[]>;
|
|
64
|
-
getEmbeddings<T>(item: T, accessor: (item: T) => string): Promise<number[]>;
|
|
65
|
-
sort<T>(items: T[], accessor: (item: T) => string, target: string): Promise<T[]>;
|
|
66
|
-
private parseInput;
|
|
67
|
-
}
|