-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcomposition-utilities.ts
More file actions
74 lines (67 loc) · 1.79 KB
/
composition-utilities.ts
File metadata and controls
74 lines (67 loc) · 1.79 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
/**
* Composition Utilities Example
*
* This example demonstrates all the composition helpers:
* oneOf, times, between, and optional
*/
import {
generateDataset,
user,
assistant,
generatedUser,
generatedAssistant,
oneOf,
times,
between,
optional,
} from "@qforge/torque";
import type { IMessageSchemaGroup } from "@qforge/torque";
import { createOpenAI } from "@ai-sdk/openai";
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
console.error("❌ ERROR: OPENAI_API_KEY not found!");
console.log("\n📝 To add your API key:");
console.log(
"1. Add: OPENAI_API_KEY=your-key-here or change the apiKey variable above."
);
console.log("2. Run this script again\n");
process.exit(1);
}
const openai = createOpenAI({
apiKey,
});
await generateDataset(
() => [
// Random greeting
oneOf([
user({ content: "Hello" }),
user({ content: "Hi" }),
user({ content: "Hey there" }),
]),
assistant({ content: "Hello! How can I assist you?" }),
// Variable number of Q&A exchanges
times(between(2, 4), [
generatedUser({ prompt: "Ask a question about programming" }),
generatedAssistant({
prompt: "Provide a helpful answer with code examples",
}),
]),
// Optional closing
optional(user({ content: "Thank you!" })),
optional(
assistant({ content: "You're welcome! Feel free to ask anytime." })
),
/*
Variations:
- Swap in user({ content: "Hello" }) above for a deterministic opening.
- Replace the times(between(...)) block with `times(3, [...])` to fix the length.
- Keep only the optional(...) lines to spotlight optional() on its own.
*/
],
{
count: 5,
model: openai("gpt-5-mini"),
output: "data/combined-utilities.jsonl",
seed: 400,
}
);