promptgun 0.8.2 → 0.8.3
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/README.md +18 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,24 +18,38 @@ for await (const chunk of stream) {
|
|
|
18
18
|
|
|
19
19
|
### Data output - single
|
|
20
20
|
```typescript
|
|
21
|
-
const count /* type
|
|
21
|
+
const count /* type: boolean */ = await ai
|
|
22
22
|
.chat('How many countries are in the EU')
|
|
23
23
|
.to(o => o.number())
|
|
24
24
|
```
|
|
25
|
-
|
|
25
|
+
Promptgun will both tell the LLM what shape its output data should be, parse that data to JS types and –if you use Typescript– return the matching Typescript type.
|
|
26
|
+
|
|
27
|
+
You can do this for types of any complexity:
|
|
26
28
|
```typescript
|
|
27
|
-
const restaurants /* type
|
|
29
|
+
const restaurants /* type: {name: string, address: string}[] */ = await ai
|
|
28
30
|
.chat('Give 5 top restaurants in London')
|
|
29
31
|
.to(o => o
|
|
30
32
|
.array(e => e
|
|
31
33
|
.object(o => o
|
|
32
34
|
.hasString('name')
|
|
33
35
|
.hasString('address')
|
|
34
|
-
.hasString('styleOfFood')
|
|
35
36
|
)
|
|
36
37
|
)
|
|
37
38
|
)
|
|
38
39
|
```
|
|
40
|
+
|
|
41
|
+
You can also put instructions to the LLM in your type spec:
|
|
42
|
+
```typescript
|
|
43
|
+
const restaurants /* type: {name: string, address: string}[] */ = await ai
|
|
44
|
+
.chat('Give 5 top restaurants in London')
|
|
45
|
+
.to(o => o
|
|
46
|
+
.object(o => o
|
|
47
|
+
.hasString('name')
|
|
48
|
+
.hasString('description', 'A 50 character description')
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
39
53
|
### Data output - stream data-aware
|
|
40
54
|
You can put callbacks on elements of the result data, which get called as they come in:
|
|
41
55
|
```typescript
|
|
@@ -46,7 +60,6 @@ await ai
|
|
|
46
60
|
.object(obj => obj
|
|
47
61
|
.hasString('name')
|
|
48
62
|
.hasString('address')
|
|
49
|
-
.hasString('styleOfFood')
|
|
50
63
|
)
|
|
51
64
|
)
|
|
52
65
|
)
|
|
@@ -66,7 +79,6 @@ const parsedPartialJsonStream = ai
|
|
|
66
79
|
.canBeObject(obj => obj
|
|
67
80
|
.hasString('name')
|
|
68
81
|
.hasString('address')
|
|
69
|
-
.hasString('styleOfFood')
|
|
70
82
|
)
|
|
71
83
|
)
|
|
72
84
|
)
|