@nx-ddd/any-func 19.0.0-preview-remove-post-build-scripts.2 → 19.0.0-preview-test-remove-tsconfig-lib-prod.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.
Files changed (100) hide show
  1. package/adapters/local-storage/index.d.ts +5 -0
  2. package/adapters/local-storage-browser/index.d.ts +8 -0
  3. package/adapters/local-storage-node/index.d.ts +5 -0
  4. package/adapters/validator/index.d.ts +10 -0
  5. package/adapters/validator-commonjs/index.d.ts +13 -0
  6. package/adapters/validator-esmodule/index.d.ts +15 -0
  7. package/browser/index.d.ts +6 -0
  8. package/fesm2022/nx-ddd-any-func-adapters-local-storage-browser.mjs +12 -0
  9. package/fesm2022/nx-ddd-any-func-adapters-local-storage-browser.mjs.map +1 -0
  10. package/fesm2022/nx-ddd-any-func-adapters-local-storage-node.mjs +16 -0
  11. package/fesm2022/nx-ddd-any-func-adapters-local-storage-node.mjs.map +1 -0
  12. package/fesm2022/nx-ddd-any-func-adapters-local-storage.mjs +10 -0
  13. package/fesm2022/nx-ddd-any-func-adapters-local-storage.mjs.map +1 -0
  14. package/fesm2022/nx-ddd-any-func-adapters-validator-commonjs.mjs +33 -0
  15. package/fesm2022/nx-ddd-any-func-adapters-validator-commonjs.mjs.map +1 -0
  16. package/fesm2022/nx-ddd-any-func-adapters-validator-esmodule.mjs +28 -0
  17. package/fesm2022/nx-ddd-any-func-adapters-validator-esmodule.mjs.map +1 -0
  18. package/fesm2022/nx-ddd-any-func-adapters-validator.mjs +17 -0
  19. package/fesm2022/nx-ddd-any-func-adapters-validator.mjs.map +1 -0
  20. package/fesm2022/nx-ddd-any-func-browser.mjs +19 -0
  21. package/fesm2022/nx-ddd-any-func-browser.mjs.map +1 -0
  22. package/fesm2022/nx-ddd-any-func-server.mjs +19 -0
  23. package/fesm2022/nx-ddd-any-func-server.mjs.map +1 -0
  24. package/fesm2022/nx-ddd-any-func.mjs +432 -0
  25. package/fesm2022/nx-ddd-any-func.mjs.map +1 -0
  26. package/index.d.ts +151 -1
  27. package/package.json +50 -38
  28. package/server/index.d.ts +6 -0
  29. package/README.md +0 -7
  30. package/index.js +0 -2
  31. package/index.js.map +0 -1
  32. package/lib/agent/agent.d.ts +0 -53
  33. package/lib/agent/agent.js +0 -91
  34. package/lib/agent/agent.js.map +0 -1
  35. package/lib/agent/index.d.ts +0 -1
  36. package/lib/agent/index.js +0 -2
  37. package/lib/agent/index.js.map +0 -1
  38. package/lib/any-func/any-func.service.d.ts +0 -4
  39. package/lib/any-func/any-func.service.impl.d.ts +0 -67
  40. package/lib/any-func/any-func.service.impl.js +0 -257
  41. package/lib/any-func/any-func.service.impl.js.map +0 -1
  42. package/lib/any-func/any-func.service.js +0 -7
  43. package/lib/any-func/any-func.service.js.map +0 -1
  44. package/lib/any-func/index.d.ts +0 -1
  45. package/lib/any-func/index.js +0 -2
  46. package/lib/any-func/index.js.map +0 -1
  47. package/lib/browser.d.ts +0 -3
  48. package/lib/browser.js +0 -12
  49. package/lib/browser.js.map +0 -1
  50. package/lib/impl/adapters/cache/cache.adapter.d.ts +0 -9
  51. package/lib/impl/adapters/cache/cache.adapter.js +0 -47
  52. package/lib/impl/adapters/cache/cache.adapter.js.map +0 -1
  53. package/lib/impl/adapters/cache/index.d.ts +0 -1
  54. package/lib/impl/adapters/cache/index.js +0 -2
  55. package/lib/impl/adapters/cache/index.js.map +0 -1
  56. package/lib/impl/adapters/local-storage/browser.d.ts +0 -4
  57. package/lib/impl/adapters/local-storage/browser.js +0 -5
  58. package/lib/impl/adapters/local-storage/browser.js.map +0 -1
  59. package/lib/impl/adapters/local-storage/index.d.ts +0 -1
  60. package/lib/impl/adapters/local-storage/index.js +0 -2
  61. package/lib/impl/adapters/local-storage/index.js.map +0 -1
  62. package/lib/impl/adapters/local-storage/node.d.ts +0 -2
  63. package/lib/impl/adapters/local-storage/node.js +0 -9
  64. package/lib/impl/adapters/local-storage/node.js.map +0 -1
  65. package/lib/impl/adapters/local-storage/token.d.ts +0 -1
  66. package/lib/impl/adapters/local-storage/token.js +0 -3
  67. package/lib/impl/adapters/local-storage/token.js.map +0 -1
  68. package/lib/impl/adapters/validator/commonjs.d.ts +0 -7
  69. package/lib/impl/adapters/validator/commonjs.js +0 -29
  70. package/lib/impl/adapters/validator/commonjs.js.map +0 -1
  71. package/lib/impl/adapters/validator/esmodule.d.ts +0 -9
  72. package/lib/impl/adapters/validator/esmodule.js +0 -21
  73. package/lib/impl/adapters/validator/esmodule.js.map +0 -1
  74. package/lib/impl/adapters/validator/validator.adapter.d.ts +0 -4
  75. package/lib/impl/adapters/validator/validator.adapter.js +0 -9
  76. package/lib/impl/adapters/validator/validator.adapter.js.map +0 -1
  77. package/lib/impl/index.d.ts +0 -2
  78. package/lib/impl/index.js +0 -3
  79. package/lib/impl/index.js.map +0 -1
  80. package/lib/impl/json-schema/default-metadata-storage.d.ts +0 -2
  81. package/lib/impl/json-schema/default-metadata-storage.js +0 -15
  82. package/lib/impl/json-schema/default-metadata-storage.js.map +0 -1
  83. package/lib/impl/json-schema/index.d.ts +0 -1
  84. package/lib/impl/json-schema/index.js +0 -2
  85. package/lib/impl/json-schema/index.js.map +0 -1
  86. package/lib/impl/json-schema/json-schema.d.ts +0 -3
  87. package/lib/impl/json-schema/json-schema.js +0 -46
  88. package/lib/impl/json-schema/json-schema.js.map +0 -1
  89. package/lib/index.d.ts +0 -3
  90. package/lib/index.js +0 -4
  91. package/lib/index.js.map +0 -1
  92. package/lib/server.d.ts +0 -3
  93. package/lib/server.js +0 -12
  94. package/lib/server.js.map +0 -1
  95. package/lib/utils/debug-price.d.ts +0 -1
  96. package/lib/utils/debug-price.js +0 -39
  97. package/lib/utils/debug-price.js.map +0 -1
  98. package/lib/utils/index.d.ts +0 -1
  99. package/lib/utils/index.js +0 -2
  100. package/lib/utils/index.js.map +0 -1
package/index.d.ts CHANGED
@@ -1 +1,151 @@
1
- export * from './lib';
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,41 +1,9 @@
1
1
  {
2
2
  "name": "@nx-ddd/any-func",
3
- "version": "19.0.0-preview-remove-post-build-scripts.2",
4
- "type": "module",
5
- "main": "./index.js",
6
- "types": "./index.d.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./index.d.ts",
10
- "default": "./index.js"
11
- },
12
- "./browser": {
13
- "types": "./lib/browser.d.ts",
14
- "default": "./lib/browser.js"
15
- },
16
- "./server": {
17
- "types": "./lib/server.d.ts",
18
- "default": "./lib/server.js"
19
- }
20
- },
21
- "typesVersions": {
22
- "*": {
23
- "browser": [
24
- "lib/browser.d.ts"
25
- ],
26
- "server": [
27
- "lib/server.d.ts"
28
- ]
29
- }
30
- },
31
- "homepage": "https://github.com/xx-machina/plaform/tree/main/packages/@nx-ddd/any-func",
32
- "repository": {
33
- "type": "git",
34
- "url": "https://github.com/xx-machina/plaform.git"
35
- },
3
+ "version": "19.0.0-preview-test-remove-tsconfig-lib-prod.1",
36
4
  "peerDependencies": {
37
- "@angular/core": "19.1.4",
38
- "@nx-ddd/common": "19.0.0-preview-remove-post-build-scripts.2",
5
+ "@angular/core": ">=17.0.0",
6
+ "@nx-ddd/common": "19.0.0-preview-test-remove-tsconfig-lib-prod.1",
39
7
  "class-transformer": "^0.5.1",
40
8
  "class-validator": "^0.14.0",
41
9
  "class-validator-jsonschema": "^5.0.0",
@@ -45,9 +13,53 @@
45
13
  "openai": "^4.95.0",
46
14
  "p-limit": "^6.1.0",
47
15
  "rxjs": "^7.8.0",
48
- "tslib": "^2.3.0",
49
16
  "json-schema": "0.4.0"
50
17
  },
51
- "dependencies": {},
52
- "module": "./index.js"
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
+ }
53
65
  }
@@ -0,0 +1,6 @@
1
+ import { EnvironmentProviders } from '@angular/core';
2
+ import { AnyFuncConfig } from '@nx-ddd/any-func';
3
+
4
+ declare function provideAnyFuncForServer(configFactory?: () => AnyFuncConfig): EnvironmentProviders;
5
+
6
+ export { provideAnyFuncForServer };
package/README.md DELETED
@@ -1,7 +0,0 @@
1
- # @nx-ddd/any-func
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Running unit tests
6
-
7
- Run `nx test @nx-ddd/any-func` to execute the unit tests.
package/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './lib';
2
- //# sourceMappingURL=index.js.map
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,cAAc,OAAO,CAAC"}
@@ -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 {};
@@ -1,91 +0,0 @@
1
- import { __awaiter } from "tslib";
2
- import { targetConstructorToSchema } from '../impl/json-schema';
3
- const AI_TOOLS = '[ai-tools]';
4
- const AI_SYSTEM = '[ai-system]';
5
- export function addTool(obj, tool) {
6
- var _a;
7
- obj[AI_TOOLS] = (_a = obj[AI_TOOLS]) !== null && _a !== void 0 ? _a : [];
8
- obj[AI_TOOLS].push(tool);
9
- return obj;
10
- }
11
- export function getTools(obj) {
12
- var _a;
13
- return (_a = obj[AI_TOOLS]) !== null && _a !== void 0 ? _a : [];
14
- }
15
- export function buildFunctionTool(params) {
16
- return {
17
- type: 'function',
18
- function: {
19
- name: params.name,
20
- description: params.description,
21
- parameters: params.parameters,
22
- },
23
- };
24
- }
25
- export function buildToolFromSchema(name, description, schema) {
26
- const parameters = targetConstructorToSchema(schema);
27
- return buildFunctionTool({ name, description, parameters });
28
- }
29
- export function AiFunction(params) {
30
- return function (target, propertyKey, descriptor) {
31
- var _a;
32
- // 引数の型を取得
33
- const args = Reflect.getMetadata('design:paramtypes', target, propertyKey);
34
- const tool = buildToolFromSchema(propertyKey, (_a = params === null || params === void 0 ? void 0 : params.description) !== null && _a !== void 0 ? _a : '', args[0]);
35
- addTool(target, tool);
36
- return descriptor;
37
- };
38
- }
39
- export function setAiSystemConfig(obj, config) {
40
- obj[AI_SYSTEM] = config;
41
- return obj;
42
- }
43
- export function getAiSystemConfig(obj) {
44
- return obj[AI_SYSTEM];
45
- }
46
- export function AiSystem({ model = 'gpt-4-1106-preview', instructions = ``, shots = [], }) {
47
- return function (target) {
48
- setAiSystemConfig(target, { model, instructions, shots });
49
- return target;
50
- };
51
- }
52
- export class AiToolsAgent {
53
- constructor(openai) {
54
- this.openai = openai;
55
- this.messages = [
56
- { role: 'system', content: '' },
57
- ];
58
- this.results = [];
59
- }
60
- get tools() {
61
- return getTools(this.constructor);
62
- }
63
- get config() {
64
- return getAiSystemConfig(this.constructor);
65
- }
66
- completion() {
67
- return __awaiter(this, arguments, void 0, function* (tools = this.tools) {
68
- var _a, _b, _c, _d;
69
- const message = yield this.openai.chat.completions.create({
70
- model: this.config.model,
71
- messages: this.messages,
72
- tools,
73
- });
74
- 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 : []) {
75
- if (call.type === 'function') {
76
- const func = this[call.function.name];
77
- const result = func(JSON.parse(call.function.arguments));
78
- this.results.push(result);
79
- }
80
- }
81
- });
82
- }
83
- execute(message_1) {
84
- return __awaiter(this, arguments, void 0, function* (message, options = {}) {
85
- this.messages.push({ role: 'user', content: message });
86
- yield this.completion(options.tools);
87
- return this.results.at(-1);
88
- });
89
- }
90
- }
91
- //# sourceMappingURL=agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../../../../packages/@nx-ddd/any-func/src/lib/agent/agent.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,MAAM,QAAQ,GAAG,YAAqB,CAAC;AACvC,MAAM,SAAS,GAAG,aAAsB,CAAC;AAEzC,MAAM,UAAU,OAAO,CAAC,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,OAAO,0CAAE,UAAU,mCAAI,EAAE,EAAE,CAAC;gBACnE,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBAC7B,MAAM,IAAI,GAAI,IAAY,CAAC,IAAI,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;6DAAQ,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"}
@@ -1 +0,0 @@
1
- export * from './agent';
@@ -1,2 +0,0 @@
1
- export * from './agent';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/@nx-ddd/any-func/src/lib/agent/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -1,4 +0,0 @@
1
- import { InjectionToken } from '@angular/core';
2
- import { AnyFuncService } from './any-func.service.impl';
3
- export declare const ANY_FUNC_SERVICE: InjectionToken<AnyFuncService>;
4
- export declare function injectAnyFunc(): AnyFuncService;
@@ -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
- }