forked from wrtnlabs/agentica
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
110 lines (103 loc) · 2.95 KB
/
index.ts
File metadata and controls
110 lines (103 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { DynamicExecutor } from "@nestia/e2e";
import {
HttpLlm,
IHttpConnection,
IHttpLlmApplication,
OpenApi,
OpenApiV3,
OpenApiV3_1,
SwaggerV2,
} from "@samchon/openapi";
import ShoppingApi from "@samchon/shopping-api";
import { WrtnAgent } from "@wrtnlabs/agent";
import chalk from "chalk";
import OpenAI from "openai";
import typia from "typia";
import { TestGlobal } from "./TestGlobal";
const main = async (): Promise<void> => {
if (!TestGlobal.env.CHATGPT_API_KEY?.length) return;
// COMPOSE LLM APPLICATION SCHEMA
const swagger:
| SwaggerV2.IDocument
| OpenApiV3.IDocument
| OpenApiV3_1.IDocument = await fetch(
"https://shopping-be.wrtn.ai/editor/swagger.json",
).then((r) => r.json());
const document: OpenApi.IDocument = OpenApi.convert(typia.assert(swagger));
const application: IHttpLlmApplication<"chatgpt"> = HttpLlm.application({
model: "chatgpt",
document,
});
application.functions = application.functions.filter((f) =>
f.path.startsWith("/shoppings/customers"),
);
// HANDSHAKE WITH SHOPPING BACKEND
const connection: IHttpConnection = {
host: "https://shopping-be.wrtn.ai",
};
await ShoppingApi.functional.shoppings.customers.authenticate.create(
connection,
{
channel_code: "samchon",
external_user: null,
href: "htts://127.0.0.1/NodeJS",
referrer: null,
},
);
await ShoppingApi.functional.shoppings.customers.authenticate.activate(
connection,
{
mobile: "821012345678",
name: "John Doe",
},
);
// COMPOSE CHAT AGENT
const agent: WrtnAgent = new WrtnAgent({
provider: {
type: "chatgpt",
api: new OpenAI({
apiKey: TestGlobal.env.CHATGPT_API_KEY,
}),
model: "gpt-4o",
},
controllers: [
{
protocol: "http",
name: "shopping",
application,
connection,
},
],
});
const report: DynamicExecutor.IReport = await DynamicExecutor.validate({
prefix: "test_",
location: __dirname + "/features",
parameters: () => [agent],
onComplete: (exec) => {
const trace = (str: string) =>
console.log(` - ${chalk.green(exec.name)}: ${str}`);
if (exec.error === null) {
const elapsed: number =
new Date(exec.completed_at).getTime() -
new Date(exec.started_at).getTime();
trace(`${chalk.yellow(elapsed.toLocaleString())} ms`);
} else trace(chalk.red(exec.error.name));
},
});
const exceptions: Error[] = report.executions
.filter((exec) => exec.error !== null)
.map((exec) => exec.error!);
if (exceptions.length === 0) {
console.log("Success");
console.log("Elapsed time", report.time.toLocaleString(), `ms`);
} else {
for (const exp of exceptions) console.log(exp);
console.log("Failed");
console.log("Elapsed time", report.time.toLocaleString(), `ms`);
process.exit(-1);
}
};
main().catch((error) => {
console.error(error);
process.exit(-1);
});