promptgun 0.10.1 → 0.11.0
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 +8 -10
- package/build/index.d.ts +7 -7
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ for await (const chunk of stream) {
|
|
|
20
20
|
```typescript
|
|
21
21
|
const count /* type: number */ = await ai
|
|
22
22
|
.chat('How many countries are in the EU')
|
|
23
|
-
.
|
|
23
|
+
.getNumber()
|
|
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
26
|
|
|
@@ -28,7 +28,7 @@ You can do this for types of any complexity:
|
|
|
28
28
|
```typescript
|
|
29
29
|
const restaurants /* type: {name: string, address?: string}[] */ = await ai
|
|
30
30
|
.chat('Give 5 top restaurants in London')
|
|
31
|
-
.
|
|
31
|
+
.getArray(o => o
|
|
32
32
|
.object(o => o
|
|
33
33
|
.hasString('name')
|
|
34
34
|
.canHaveString('address')
|
|
@@ -40,7 +40,7 @@ You can also put instructions to the LLM in your type spec:
|
|
|
40
40
|
```typescript
|
|
41
41
|
const restaurants /* type: {name: string, address: string}[] */ = await ai
|
|
42
42
|
.chat('Give the top restaurant in London')
|
|
43
|
-
.
|
|
43
|
+
.getObject(o => o
|
|
44
44
|
.hasString('name')
|
|
45
45
|
.hasString('description', 'A 50 character description')
|
|
46
46
|
)
|
|
@@ -51,12 +51,10 @@ You can put callbacks on elements of the result data, which get called as they c
|
|
|
51
51
|
```typescript
|
|
52
52
|
await ai
|
|
53
53
|
.chat('Give 5 top restaurants in London')
|
|
54
|
-
.
|
|
55
|
-
.
|
|
56
|
-
.
|
|
57
|
-
|
|
58
|
-
.hasString('address')
|
|
59
|
-
)
|
|
54
|
+
.getArray(d => d
|
|
55
|
+
.object(obj => obj
|
|
56
|
+
.hasString('name')
|
|
57
|
+
.hasString('address')
|
|
60
58
|
)
|
|
61
59
|
)
|
|
62
60
|
.onElement(restaurantStream /* type safe */ => {
|
|
@@ -68,7 +66,7 @@ And iterating (not awaiting) any streamed json element simply gives the stream o
|
|
|
68
66
|
```typescript
|
|
69
67
|
const parsedPartialJsonStream = ai
|
|
70
68
|
.chat('What are the top 5 restaurants in New York City?')
|
|
71
|
-
.
|
|
69
|
+
.getArray(o => o
|
|
72
70
|
.object(o => o
|
|
73
71
|
.hasString('name')
|
|
74
72
|
.hasString('address')
|
package/build/index.d.ts
CHANGED
|
@@ -862,13 +862,13 @@ export declare class BasicPrompt<PSArgs> implements AsyncGenerator<string>, Prom
|
|
|
862
862
|
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<string | TResult>;
|
|
863
863
|
finally(onfinally?: (() => void) | null | undefined): Promise<string>;
|
|
864
864
|
get [Symbol.toStringTag](): string;
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
865
|
+
get<Json extends AnyJson = AnyJson>(type: (value: EmptyTypeSpec<unknown>) => TypeSpec<Json>): JsonPrompt<PSArgs, Json>;
|
|
866
|
+
getBoolean(): JsonPrompt<PSArgs, boolean>;
|
|
867
|
+
getString(): JsonPrompt<PSArgs, string>;
|
|
868
|
+
getNumber(): JsonPrompt<PSArgs, number>;
|
|
869
|
+
getObject<T_obj extends {}>(properties: (arg: TypeMemberSpec<{}>) => TypeMemberSpec<T_obj>): JsonPrompt<PSArgs, T_obj>;
|
|
870
|
+
getArray<T_arr extends AnyJson>(element: (arg: EmptyTypeSpec<unknown>) => TypeSpec<T_arr>): JsonPrompt<PSArgs, T_arr[]>;
|
|
871
|
+
getAny(): JsonPrompt<PSArgs, AnyJson>;
|
|
872
872
|
private getResponseAsString;
|
|
873
873
|
}
|
|
874
874
|
|