Skip to content

Commit 4e5453e

Browse files
committed
fixing tests
1 parent 604f954 commit 4e5453e

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Runtime
3+
sidebar:
4+
order: 1.2
5+
description: Learn how to run GenAIScript scripts in a Node.JS environment, including configuration
6+
---
7+
8+
Scripts using the `.genai.mts` (or any `.genai.*` extension) are meant to be run through the [command line interfanece](/genaiscript/reference/cli).
9+
10+
This page describes how to use the runtime in a Node.JS script without using the CLI.
11+
12+
## Import and configuration
13+
14+
```js
15+
import { initialize } from "@genaiscript/runtime";
16+
17+
// runs this before using any global ty\pes
18+
await initialize();
19+
```
20+
21+
## globals
22+
23+
The runtime installs global parsers and inline prompt types. However, the global `$`, `def`, etc... is not available, online inline prompts.
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import "@genaiscript/runtime";
22

33
export async function writePoem() {
4-
const res = await prompt`write a poem`;
4+
const res = await prompt`write a poem`.options({ model: "echo" });
55
return res.text;
66
}
7-
8-
await writePoem()
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import { describe, test, assert, beforeEach } from "vitest";
4+
import { describe, test } from "vitest";
55
import { writePoem } from "../src/poem-function";
6-
import "@genaiscript/runtime";
6+
import { initialize } from "@genaiscript/runtime";
77

8-
describe(`runtime`, () => {
9-
test(`dynamic import`, async () => {
10-
const res = await prompt`write a poem`;
8+
describe(`runtime`, async () => {
9+
await initialize();
10+
await test(`dynamic import`, async () => {
11+
const res = await prompt`write a poem`.options({ model: "echo" });
1112
console.log(res.text);
1213
// Add assertions if needed
1314
});
1415

15-
test(`poem function`, async () => {
16+
await test(`poem function`, async () => {
1617
await writePoem();
1718
});
1819
});

0 commit comments

Comments
 (0)