@agentica/core 0.12.0 → 0.12.2-dev.20250314
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/LICENSE +21 -21
- package/README.md +461 -461
- package/lib/Agentica.js +3 -1
- package/lib/Agentica.js.map +1 -1
- package/lib/context/internal/AgenticaTokenUsageAggregator.js +1 -1
- package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
- package/lib/index.mjs +5 -2
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/prompts/cancel.md +4 -4
- package/prompts/common.md +2 -2
- package/prompts/describe.md +6 -6
- package/prompts/execute.md +6 -6
- package/prompts/initialize.md +2 -2
- package/prompts/select.md +6 -6
- package/src/Agentica.ts +359 -356
- package/src/chatgpt/ChatGptAgent.ts +76 -76
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +466 -466
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +280 -280
- package/src/chatgpt/ChatGptCompletionMessageUtil.ts +166 -166
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +122 -122
- package/src/chatgpt/ChatGptHistoryDecoder.ts +88 -88
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +96 -96
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +311 -311
- package/src/chatgpt/ChatGptUsageAggregator.ts +62 -62
- package/src/context/AgenticaCancelPrompt.ts +32 -32
- package/src/context/AgenticaClassOperation.ts +23 -23
- package/src/context/AgenticaContext.ts +130 -130
- package/src/context/AgenticaHttpOperation.ts +27 -27
- package/src/context/AgenticaOperation.ts +66 -66
- package/src/context/AgenticaOperationBase.ts +57 -57
- package/src/context/AgenticaOperationCollection.ts +52 -52
- package/src/context/AgenticaOperationSelection.ts +27 -27
- package/src/context/AgenticaTokenUsage.ts +170 -170
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +66 -66
- package/src/context/internal/__IChatCancelFunctionsApplication.ts +23 -23
- package/src/context/internal/__IChatFunctionReference.ts +21 -21
- package/src/context/internal/__IChatInitialApplication.ts +15 -15
- package/src/context/internal/__IChatSelectFunctionsApplication.ts +24 -24
- package/src/events/AgenticaCallEvent.ts +36 -36
- package/src/events/AgenticaCancelEvent.ts +28 -28
- package/src/events/AgenticaDescribeEvent.ts +66 -66
- package/src/events/AgenticaEvent.ts +36 -36
- package/src/events/AgenticaEventBase.ts +7 -7
- package/src/events/AgenticaEventSource.ts +6 -6
- package/src/events/AgenticaExecuteEvent.ts +50 -50
- package/src/events/AgenticaInitializeEvent.ts +14 -14
- package/src/events/AgenticaRequestEvent.ts +45 -45
- package/src/events/AgenticaResponseEvent.ts +48 -48
- package/src/events/AgenticaSelectEvent.ts +37 -37
- package/src/events/AgenticaTextEvent.ts +62 -62
- package/src/functional/assertHttpLlmApplication.ts +55 -55
- package/src/functional/validateHttpLlmApplication.ts +66 -66
- package/src/index.ts +44 -44
- package/src/internal/AgenticaConstant.ts +4 -4
- package/src/internal/AgenticaDefaultPrompt.ts +43 -43
- package/src/internal/AgenticaOperationComposer.ts +96 -96
- package/src/internal/ByteArrayUtil.ts +5 -5
- package/src/internal/MPSCUtil.ts +111 -111
- package/src/internal/MathUtil.ts +3 -3
- package/src/internal/Singleton.ts +22 -22
- package/src/internal/StreamUtil.ts +64 -64
- package/src/internal/__map_take.ts +15 -15
- package/src/json/IAgenticaEventJson.ts +178 -178
- package/src/json/IAgenticaOperationJson.ts +36 -36
- package/src/json/IAgenticaOperationSelectionJson.ts +19 -19
- package/src/json/IAgenticaPromptJson.ts +130 -130
- package/src/json/IAgenticaTokenUsageJson.ts +107 -107
- package/src/prompts/AgenticaCancelPrompt.ts +32 -32
- package/src/prompts/AgenticaDescribePrompt.ts +41 -41
- package/src/prompts/AgenticaExecutePrompt.ts +52 -52
- package/src/prompts/AgenticaPrompt.ts +14 -14
- package/src/prompts/AgenticaPromptBase.ts +27 -27
- package/src/prompts/AgenticaSelectPrompt.ts +32 -32
- package/src/prompts/AgenticaTextPrompt.ts +31 -31
- package/src/structures/IAgenticaConfig.ts +123 -123
- package/src/structures/IAgenticaController.ts +133 -133
- package/src/structures/IAgenticaExecutor.ts +157 -157
- package/src/structures/IAgenticaProps.ts +69 -69
- package/src/structures/IAgenticaSystemPrompt.ts +125 -125
- package/src/structures/IAgenticaVendor.ts +39 -39
- package/src/transformers/AgenticaEventTransformer.ts +165 -165
- package/src/transformers/AgenticaPromptTransformer.ts +134 -134
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
2
|
-
|
|
3
|
-
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
-
import { AgenticaEventSource } from "./AgenticaEventSource";
|
|
5
|
-
|
|
6
|
-
export class AgenticaResponseEvent extends AgenticaEventBase<"response"> {
|
|
7
|
-
public readonly source: AgenticaEventSource;
|
|
8
|
-
public readonly body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
9
|
-
public readonly stream: ReadableStream<OpenAI.ChatCompletionChunk>;
|
|
10
|
-
public readonly options?: OpenAI.RequestOptions | undefined;
|
|
11
|
-
public readonly join: () => Promise<OpenAI.ChatCompletion>;
|
|
12
|
-
|
|
13
|
-
public constructor(props: AgenticaResponseEvent.IProps) {
|
|
14
|
-
super("response");
|
|
15
|
-
this.source = props.source;
|
|
16
|
-
this.body = props.body;
|
|
17
|
-
this.stream = props.stream;
|
|
18
|
-
this.options = props.options;
|
|
19
|
-
this.join = props.join;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export namespace AgenticaResponseEvent {
|
|
23
|
-
export interface IProps {
|
|
24
|
-
/**
|
|
25
|
-
* The source agent of the response.
|
|
26
|
-
*/
|
|
27
|
-
source: AgenticaEventSource;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Request body.
|
|
31
|
-
*/
|
|
32
|
-
body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Options for the request.
|
|
36
|
-
*/
|
|
37
|
-
options?: OpenAI.RequestOptions | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* The text content stream.
|
|
40
|
-
*/
|
|
41
|
-
stream: ReadableStream<OpenAI.ChatCompletionChunk>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Get the description text.
|
|
45
|
-
*/
|
|
46
|
-
join: () => Promise<OpenAI.ChatCompletion>;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
|
|
3
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
+
import { AgenticaEventSource } from "./AgenticaEventSource";
|
|
5
|
+
|
|
6
|
+
export class AgenticaResponseEvent extends AgenticaEventBase<"response"> {
|
|
7
|
+
public readonly source: AgenticaEventSource;
|
|
8
|
+
public readonly body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
9
|
+
public readonly stream: ReadableStream<OpenAI.ChatCompletionChunk>;
|
|
10
|
+
public readonly options?: OpenAI.RequestOptions | undefined;
|
|
11
|
+
public readonly join: () => Promise<OpenAI.ChatCompletion>;
|
|
12
|
+
|
|
13
|
+
public constructor(props: AgenticaResponseEvent.IProps) {
|
|
14
|
+
super("response");
|
|
15
|
+
this.source = props.source;
|
|
16
|
+
this.body = props.body;
|
|
17
|
+
this.stream = props.stream;
|
|
18
|
+
this.options = props.options;
|
|
19
|
+
this.join = props.join;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export namespace AgenticaResponseEvent {
|
|
23
|
+
export interface IProps {
|
|
24
|
+
/**
|
|
25
|
+
* The source agent of the response.
|
|
26
|
+
*/
|
|
27
|
+
source: AgenticaEventSource;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Request body.
|
|
31
|
+
*/
|
|
32
|
+
body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Options for the request.
|
|
36
|
+
*/
|
|
37
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The text content stream.
|
|
40
|
+
*/
|
|
41
|
+
stream: ReadableStream<OpenAI.ChatCompletionChunk>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get the description text.
|
|
45
|
+
*/
|
|
46
|
+
join: () => Promise<OpenAI.ChatCompletion>;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { v4 } from "uuid";
|
|
3
|
-
|
|
4
|
-
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
5
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
6
|
-
import { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
7
|
-
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
8
|
-
|
|
9
|
-
export class AgenticaSelectEvent<
|
|
10
|
-
Model extends ILlmSchema.Model,
|
|
11
|
-
> extends AgenticaEventBase<"select"> {
|
|
12
|
-
public readonly selection: AgenticaOperationSelection<Model>;
|
|
13
|
-
|
|
14
|
-
public constructor(props: AgenticaSelectEvent.IProps<Model>) {
|
|
15
|
-
super("select");
|
|
16
|
-
this.selection = props.selection;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public toJSON(): IAgenticaEventJson.ISelect {
|
|
20
|
-
return {
|
|
21
|
-
type: "select",
|
|
22
|
-
selection: this.selection.toJSON(),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public toPrompt(): AgenticaSelectPrompt<Model> {
|
|
27
|
-
return new AgenticaSelectPrompt({
|
|
28
|
-
id: v4(),
|
|
29
|
-
selections: [this.selection],
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export namespace AgenticaSelectEvent {
|
|
34
|
-
export interface IProps<Model extends ILlmSchema.Model> {
|
|
35
|
-
selection: AgenticaOperationSelection<Model>;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
|
|
4
|
+
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
5
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
6
|
+
import { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
7
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
8
|
+
|
|
9
|
+
export class AgenticaSelectEvent<
|
|
10
|
+
Model extends ILlmSchema.Model,
|
|
11
|
+
> extends AgenticaEventBase<"select"> {
|
|
12
|
+
public readonly selection: AgenticaOperationSelection<Model>;
|
|
13
|
+
|
|
14
|
+
public constructor(props: AgenticaSelectEvent.IProps<Model>) {
|
|
15
|
+
super("select");
|
|
16
|
+
this.selection = props.selection;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public toJSON(): IAgenticaEventJson.ISelect {
|
|
20
|
+
return {
|
|
21
|
+
type: "select",
|
|
22
|
+
selection: this.selection.toJSON(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public toPrompt(): AgenticaSelectPrompt<Model> {
|
|
27
|
+
return new AgenticaSelectPrompt({
|
|
28
|
+
id: v4(),
|
|
29
|
+
selections: [this.selection],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export namespace AgenticaSelectEvent {
|
|
34
|
+
export interface IProps<Model extends ILlmSchema.Model> {
|
|
35
|
+
selection: AgenticaOperationSelection<Model>;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
2
|
-
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
3
|
-
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
-
|
|
5
|
-
export class AgenticaTextEvent extends AgenticaEventBase<"text"> {
|
|
6
|
-
public readonly role: "assistant" | "user";
|
|
7
|
-
public readonly stream: ReadableStream<string>;
|
|
8
|
-
public get text(): string {
|
|
9
|
-
return this.get_();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Check if the join method can return a response immediately.
|
|
14
|
-
* Returns true if the response is ready to be returned by the join method.
|
|
15
|
-
*/
|
|
16
|
-
public get done(): boolean {
|
|
17
|
-
return this.done_();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public constructor(props: AgenticaTextEvent.IProps) {
|
|
21
|
-
super("text");
|
|
22
|
-
this.role = props.role;
|
|
23
|
-
this.stream = props.stream;
|
|
24
|
-
|
|
25
|
-
this.done_ = props.done;
|
|
26
|
-
this.get_ = props.get;
|
|
27
|
-
this.join_ = props.join;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public join(): Promise<string> {
|
|
31
|
-
return this.join_();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public toJSON(): IAgenticaEventJson.IText {
|
|
35
|
-
return {
|
|
36
|
-
type: "text",
|
|
37
|
-
role: this.role,
|
|
38
|
-
text: this.text,
|
|
39
|
-
done: this.done,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public toPrompt(): AgenticaTextPrompt {
|
|
44
|
-
return new AgenticaTextPrompt({
|
|
45
|
-
role: this.role,
|
|
46
|
-
text: this.text,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private readonly done_: () => boolean;
|
|
51
|
-
private readonly get_: () => string;
|
|
52
|
-
private readonly join_: () => Promise<string>;
|
|
53
|
-
}
|
|
54
|
-
export namespace AgenticaTextEvent {
|
|
55
|
-
export interface IProps {
|
|
56
|
-
role: "assistant" | "user";
|
|
57
|
-
stream: ReadableStream<string>;
|
|
58
|
-
done: () => boolean;
|
|
59
|
-
get: () => string;
|
|
60
|
-
join: () => Promise<string>;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
2
|
+
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
3
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
+
|
|
5
|
+
export class AgenticaTextEvent extends AgenticaEventBase<"text"> {
|
|
6
|
+
public readonly role: "assistant" | "user";
|
|
7
|
+
public readonly stream: ReadableStream<string>;
|
|
8
|
+
public get text(): string {
|
|
9
|
+
return this.get_();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if the join method can return a response immediately.
|
|
14
|
+
* Returns true if the response is ready to be returned by the join method.
|
|
15
|
+
*/
|
|
16
|
+
public get done(): boolean {
|
|
17
|
+
return this.done_();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public constructor(props: AgenticaTextEvent.IProps) {
|
|
21
|
+
super("text");
|
|
22
|
+
this.role = props.role;
|
|
23
|
+
this.stream = props.stream;
|
|
24
|
+
|
|
25
|
+
this.done_ = props.done;
|
|
26
|
+
this.get_ = props.get;
|
|
27
|
+
this.join_ = props.join;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public join(): Promise<string> {
|
|
31
|
+
return this.join_();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public toJSON(): IAgenticaEventJson.IText {
|
|
35
|
+
return {
|
|
36
|
+
type: "text",
|
|
37
|
+
role: this.role,
|
|
38
|
+
text: this.text,
|
|
39
|
+
done: this.done,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public toPrompt(): AgenticaTextPrompt {
|
|
44
|
+
return new AgenticaTextPrompt({
|
|
45
|
+
role: this.role,
|
|
46
|
+
text: this.text,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private readonly done_: () => boolean;
|
|
51
|
+
private readonly get_: () => string;
|
|
52
|
+
private readonly join_: () => Promise<string>;
|
|
53
|
+
}
|
|
54
|
+
export namespace AgenticaTextEvent {
|
|
55
|
+
export interface IProps {
|
|
56
|
+
role: "assistant" | "user";
|
|
57
|
+
stream: ReadableStream<string>;
|
|
58
|
+
done: () => boolean;
|
|
59
|
+
get: () => string;
|
|
60
|
+
join: () => Promise<string>;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HttpLlm,
|
|
3
|
-
IHttpLlmApplication,
|
|
4
|
-
ILlmSchema,
|
|
5
|
-
OpenApi,
|
|
6
|
-
OpenApiV3,
|
|
7
|
-
OpenApiV3_1,
|
|
8
|
-
SwaggerV2,
|
|
9
|
-
} from "@samchon/openapi";
|
|
10
|
-
import typia from "typia";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Create an HTTP LLM application instance with type assertion.
|
|
14
|
-
*
|
|
15
|
-
* Create an {@link IHttpLlmApplication} instance which represents
|
|
16
|
-
* the LLM (Large Language Model) function calling application schema
|
|
17
|
-
* from the given Swagger/OpenAPI document and the target LLM model.
|
|
18
|
-
*
|
|
19
|
-
* By the way, even though this `assertHttpLlmApplication` function
|
|
20
|
-
* supports every version of Swagger/OpenAPI specification, there can
|
|
21
|
-
* be a type error in the given document. In that case, the function
|
|
22
|
-
* will throw an error with detailed type error tracing information.
|
|
23
|
-
*
|
|
24
|
-
* @param props Properties to create the HTTP LLM application instance
|
|
25
|
-
* @returns HTTP LLM application instance
|
|
26
|
-
* @throws {@link TypeGuardError} when the given document is invalid
|
|
27
|
-
* @author Samchon
|
|
28
|
-
*/
|
|
29
|
-
export const assertHttpLlmApplication = <
|
|
30
|
-
Model extends ILlmSchema.Model,
|
|
31
|
-
>(props: {
|
|
32
|
-
/**
|
|
33
|
-
* Target LLM model.
|
|
34
|
-
*/
|
|
35
|
-
model: Model;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Swagger/OpenAPI document.
|
|
39
|
-
*/
|
|
40
|
-
document:
|
|
41
|
-
| SwaggerV2.IDocument
|
|
42
|
-
| OpenApiV3.IDocument
|
|
43
|
-
| OpenApiV3_1.IDocument
|
|
44
|
-
| OpenApi.IDocument;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Options for the LLM function calling schema composition.
|
|
48
|
-
*/
|
|
49
|
-
options?: Partial<IHttpLlmApplication.IOptions<Model>>;
|
|
50
|
-
}): IHttpLlmApplication<Model> =>
|
|
51
|
-
HttpLlm.application({
|
|
52
|
-
model: props.model,
|
|
53
|
-
document: OpenApi.convert(typia.assert(props.document)),
|
|
54
|
-
options: props.options,
|
|
55
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
HttpLlm,
|
|
3
|
+
IHttpLlmApplication,
|
|
4
|
+
ILlmSchema,
|
|
5
|
+
OpenApi,
|
|
6
|
+
OpenApiV3,
|
|
7
|
+
OpenApiV3_1,
|
|
8
|
+
SwaggerV2,
|
|
9
|
+
} from "@samchon/openapi";
|
|
10
|
+
import typia from "typia";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create an HTTP LLM application instance with type assertion.
|
|
14
|
+
*
|
|
15
|
+
* Create an {@link IHttpLlmApplication} instance which represents
|
|
16
|
+
* the LLM (Large Language Model) function calling application schema
|
|
17
|
+
* from the given Swagger/OpenAPI document and the target LLM model.
|
|
18
|
+
*
|
|
19
|
+
* By the way, even though this `assertHttpLlmApplication` function
|
|
20
|
+
* supports every version of Swagger/OpenAPI specification, there can
|
|
21
|
+
* be a type error in the given document. In that case, the function
|
|
22
|
+
* will throw an error with detailed type error tracing information.
|
|
23
|
+
*
|
|
24
|
+
* @param props Properties to create the HTTP LLM application instance
|
|
25
|
+
* @returns HTTP LLM application instance
|
|
26
|
+
* @throws {@link TypeGuardError} when the given document is invalid
|
|
27
|
+
* @author Samchon
|
|
28
|
+
*/
|
|
29
|
+
export const assertHttpLlmApplication = <
|
|
30
|
+
Model extends ILlmSchema.Model,
|
|
31
|
+
>(props: {
|
|
32
|
+
/**
|
|
33
|
+
* Target LLM model.
|
|
34
|
+
*/
|
|
35
|
+
model: Model;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Swagger/OpenAPI document.
|
|
39
|
+
*/
|
|
40
|
+
document:
|
|
41
|
+
| SwaggerV2.IDocument
|
|
42
|
+
| OpenApiV3.IDocument
|
|
43
|
+
| OpenApiV3_1.IDocument
|
|
44
|
+
| OpenApi.IDocument;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Options for the LLM function calling schema composition.
|
|
48
|
+
*/
|
|
49
|
+
options?: Partial<IHttpLlmApplication.IOptions<Model>>;
|
|
50
|
+
}): IHttpLlmApplication<Model> =>
|
|
51
|
+
HttpLlm.application({
|
|
52
|
+
model: props.model,
|
|
53
|
+
document: OpenApi.convert(typia.assert(props.document)),
|
|
54
|
+
options: props.options,
|
|
55
|
+
});
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HttpLlm,
|
|
3
|
-
IHttpLlmApplication,
|
|
4
|
-
ILlmSchema,
|
|
5
|
-
OpenApi,
|
|
6
|
-
OpenApiV3,
|
|
7
|
-
OpenApiV3_1,
|
|
8
|
-
SwaggerV2,
|
|
9
|
-
} from "@samchon/openapi";
|
|
10
|
-
import typia, { IValidation } from "typia";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Create an HTTP LLM application instance with type validation.
|
|
14
|
-
*
|
|
15
|
-
* Create an {@link IHttpLlmApplication} instance which represents
|
|
16
|
-
* the LLM (Large Language Model) function calling application schema
|
|
17
|
-
* from the given Swagger/OpenAPI document and the target LLM model.
|
|
18
|
-
*
|
|
19
|
-
* By the way, even though this `validateHttpLlmApplication` function
|
|
20
|
-
* supports every version of Swagger/OpenAPI specification, there can
|
|
21
|
-
* be a type error in the given document. In that case, the function
|
|
22
|
-
* will return {@link IValidation.IFailure} instance with detailed
|
|
23
|
-
* type error tracing information.
|
|
24
|
-
*
|
|
25
|
-
* @param props Properties to create the HTTP LLM application instance
|
|
26
|
-
* @returns Validation result of the HTTP LLM application composition
|
|
27
|
-
* @author Samchon
|
|
28
|
-
*/
|
|
29
|
-
export const validateHttpLlmApplication = <
|
|
30
|
-
Model extends ILlmSchema.Model,
|
|
31
|
-
>(props: {
|
|
32
|
-
/**
|
|
33
|
-
* Target LLM model.
|
|
34
|
-
*/
|
|
35
|
-
model: Model;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Swagger/OpenAPI document.
|
|
39
|
-
*/
|
|
40
|
-
document:
|
|
41
|
-
| SwaggerV2.IDocument
|
|
42
|
-
| OpenApiV3.IDocument
|
|
43
|
-
| OpenApiV3_1.IDocument
|
|
44
|
-
| OpenApi.IDocument;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Options for the LLM function calling schema composition.
|
|
48
|
-
*/
|
|
49
|
-
options?: Partial<IHttpLlmApplication.IOptions<Model>>;
|
|
50
|
-
}): IValidation<IHttpLlmApplication<Model>> => {
|
|
51
|
-
const inspect: IValidation<
|
|
52
|
-
| SwaggerV2.IDocument
|
|
53
|
-
| OpenApiV3.IDocument
|
|
54
|
-
| OpenApiV3_1.IDocument
|
|
55
|
-
| OpenApi.IDocument
|
|
56
|
-
> = typia.validate(props.document);
|
|
57
|
-
if (inspect.success === false) return inspect;
|
|
58
|
-
return {
|
|
59
|
-
success: true,
|
|
60
|
-
data: HttpLlm.application({
|
|
61
|
-
model: props.model,
|
|
62
|
-
document: OpenApi.convert(props.document),
|
|
63
|
-
options: props.options,
|
|
64
|
-
}),
|
|
65
|
-
};
|
|
66
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
HttpLlm,
|
|
3
|
+
IHttpLlmApplication,
|
|
4
|
+
ILlmSchema,
|
|
5
|
+
OpenApi,
|
|
6
|
+
OpenApiV3,
|
|
7
|
+
OpenApiV3_1,
|
|
8
|
+
SwaggerV2,
|
|
9
|
+
} from "@samchon/openapi";
|
|
10
|
+
import typia, { IValidation } from "typia";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create an HTTP LLM application instance with type validation.
|
|
14
|
+
*
|
|
15
|
+
* Create an {@link IHttpLlmApplication} instance which represents
|
|
16
|
+
* the LLM (Large Language Model) function calling application schema
|
|
17
|
+
* from the given Swagger/OpenAPI document and the target LLM model.
|
|
18
|
+
*
|
|
19
|
+
* By the way, even though this `validateHttpLlmApplication` function
|
|
20
|
+
* supports every version of Swagger/OpenAPI specification, there can
|
|
21
|
+
* be a type error in the given document. In that case, the function
|
|
22
|
+
* will return {@link IValidation.IFailure} instance with detailed
|
|
23
|
+
* type error tracing information.
|
|
24
|
+
*
|
|
25
|
+
* @param props Properties to create the HTTP LLM application instance
|
|
26
|
+
* @returns Validation result of the HTTP LLM application composition
|
|
27
|
+
* @author Samchon
|
|
28
|
+
*/
|
|
29
|
+
export const validateHttpLlmApplication = <
|
|
30
|
+
Model extends ILlmSchema.Model,
|
|
31
|
+
>(props: {
|
|
32
|
+
/**
|
|
33
|
+
* Target LLM model.
|
|
34
|
+
*/
|
|
35
|
+
model: Model;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Swagger/OpenAPI document.
|
|
39
|
+
*/
|
|
40
|
+
document:
|
|
41
|
+
| SwaggerV2.IDocument
|
|
42
|
+
| OpenApiV3.IDocument
|
|
43
|
+
| OpenApiV3_1.IDocument
|
|
44
|
+
| OpenApi.IDocument;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Options for the LLM function calling schema composition.
|
|
48
|
+
*/
|
|
49
|
+
options?: Partial<IHttpLlmApplication.IOptions<Model>>;
|
|
50
|
+
}): IValidation<IHttpLlmApplication<Model>> => {
|
|
51
|
+
const inspect: IValidation<
|
|
52
|
+
| SwaggerV2.IDocument
|
|
53
|
+
| OpenApiV3.IDocument
|
|
54
|
+
| OpenApiV3_1.IDocument
|
|
55
|
+
| OpenApi.IDocument
|
|
56
|
+
> = typia.validate(props.document);
|
|
57
|
+
if (inspect.success === false) return inspect;
|
|
58
|
+
return {
|
|
59
|
+
success: true,
|
|
60
|
+
data: HttpLlm.application({
|
|
61
|
+
model: props.model,
|
|
62
|
+
document: OpenApi.convert(props.document),
|
|
63
|
+
options: props.options,
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
66
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
// STRUCTURES
|
|
2
|
-
export * from "./structures/IAgenticaConfig";
|
|
3
|
-
export * from "./structures/IAgenticaController";
|
|
4
|
-
export * from "./structures/IAgenticaExecutor";
|
|
5
|
-
export * from "./structures/IAgenticaProps";
|
|
6
|
-
export * from "./structures/IAgenticaVendor";
|
|
7
|
-
export * from "./structures/IAgenticaSystemPrompt";
|
|
8
|
-
|
|
9
|
-
export * from "./json/IAgenticaEventJson";
|
|
10
|
-
export * from "./json/IAgenticaOperationJson";
|
|
11
|
-
export * from "./json/IAgenticaOperationSelectionJson";
|
|
12
|
-
export * from "./json/IAgenticaPromptJson";
|
|
13
|
-
export * from "./json/IAgenticaTokenUsageJson";
|
|
14
|
-
|
|
15
|
-
// CONTEXT
|
|
16
|
-
export * from "./context/AgenticaContext";
|
|
17
|
-
export * from "./context/AgenticaOperation";
|
|
18
|
-
export * from "./context/AgenticaOperationCollection";
|
|
19
|
-
export * from "./context/AgenticaOperationSelection";
|
|
20
|
-
export * from "./context/AgenticaTokenUsage";
|
|
21
|
-
|
|
22
|
-
export * from "./prompts/AgenticaPrompt";
|
|
23
|
-
export * from "./prompts/AgenticaCancelPrompt";
|
|
24
|
-
export * from "./prompts/AgenticaDescribePrompt";
|
|
25
|
-
export * from "./prompts/AgenticaExecutePrompt";
|
|
26
|
-
export * from "./prompts/AgenticaSelectPrompt";
|
|
27
|
-
export * from "./prompts/AgenticaTextPrompt";
|
|
28
|
-
|
|
29
|
-
// EVENTS
|
|
30
|
-
export * from "./events/AgenticaEvent";
|
|
31
|
-
export * from "./events/AgenticaCallEvent";
|
|
32
|
-
export * from "./events/AgenticaCancelEvent";
|
|
33
|
-
export * from "./events/AgenticaDescribeEvent";
|
|
34
|
-
export * from "./events/AgenticaEventSource";
|
|
35
|
-
export * from "./events/AgenticaExecuteEvent";
|
|
36
|
-
export * from "./events/AgenticaRequestEvent";
|
|
37
|
-
export * from "./events/AgenticaResponseEvent";
|
|
38
|
-
export * from "./events/AgenticaSelectEvent";
|
|
39
|
-
export * from "./events/AgenticaTextEvent";
|
|
40
|
-
|
|
41
|
-
// FACADE CLASS
|
|
42
|
-
export * from "./functional/assertHttpLlmApplication";
|
|
43
|
-
export * from "./functional/validateHttpLlmApplication";
|
|
44
|
-
export * from "./Agentica";
|
|
1
|
+
// STRUCTURES
|
|
2
|
+
export * from "./structures/IAgenticaConfig";
|
|
3
|
+
export * from "./structures/IAgenticaController";
|
|
4
|
+
export * from "./structures/IAgenticaExecutor";
|
|
5
|
+
export * from "./structures/IAgenticaProps";
|
|
6
|
+
export * from "./structures/IAgenticaVendor";
|
|
7
|
+
export * from "./structures/IAgenticaSystemPrompt";
|
|
8
|
+
|
|
9
|
+
export * from "./json/IAgenticaEventJson";
|
|
10
|
+
export * from "./json/IAgenticaOperationJson";
|
|
11
|
+
export * from "./json/IAgenticaOperationSelectionJson";
|
|
12
|
+
export * from "./json/IAgenticaPromptJson";
|
|
13
|
+
export * from "./json/IAgenticaTokenUsageJson";
|
|
14
|
+
|
|
15
|
+
// CONTEXT
|
|
16
|
+
export * from "./context/AgenticaContext";
|
|
17
|
+
export * from "./context/AgenticaOperation";
|
|
18
|
+
export * from "./context/AgenticaOperationCollection";
|
|
19
|
+
export * from "./context/AgenticaOperationSelection";
|
|
20
|
+
export * from "./context/AgenticaTokenUsage";
|
|
21
|
+
|
|
22
|
+
export * from "./prompts/AgenticaPrompt";
|
|
23
|
+
export * from "./prompts/AgenticaCancelPrompt";
|
|
24
|
+
export * from "./prompts/AgenticaDescribePrompt";
|
|
25
|
+
export * from "./prompts/AgenticaExecutePrompt";
|
|
26
|
+
export * from "./prompts/AgenticaSelectPrompt";
|
|
27
|
+
export * from "./prompts/AgenticaTextPrompt";
|
|
28
|
+
|
|
29
|
+
// EVENTS
|
|
30
|
+
export * from "./events/AgenticaEvent";
|
|
31
|
+
export * from "./events/AgenticaCallEvent";
|
|
32
|
+
export * from "./events/AgenticaCancelEvent";
|
|
33
|
+
export * from "./events/AgenticaDescribeEvent";
|
|
34
|
+
export * from "./events/AgenticaEventSource";
|
|
35
|
+
export * from "./events/AgenticaExecuteEvent";
|
|
36
|
+
export * from "./events/AgenticaRequestEvent";
|
|
37
|
+
export * from "./events/AgenticaResponseEvent";
|
|
38
|
+
export * from "./events/AgenticaSelectEvent";
|
|
39
|
+
export * from "./events/AgenticaTextEvent";
|
|
40
|
+
|
|
41
|
+
// FACADE CLASS
|
|
42
|
+
export * from "./functional/assertHttpLlmApplication";
|
|
43
|
+
export * from "./functional/validateHttpLlmApplication";
|
|
44
|
+
export * from "./Agentica";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export namespace AgenticaConstant {
|
|
2
|
-
export const RETRY = 3;
|
|
3
|
-
export const ELITICISM = true;
|
|
4
|
-
}
|
|
1
|
+
export namespace AgenticaConstant {
|
|
2
|
+
export const RETRY = 3;
|
|
3
|
+
export const ELITICISM = true;
|
|
4
|
+
}
|