promptgun 0.9.0 → 0.10.1

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 CHANGED
@@ -18,22 +18,20 @@ for await (const chunk of stream) {
18
18
 
19
19
  ### Data output - single
20
20
  ```typescript
21
- const count /* type: boolean */ = await ai
21
+ const count /* type: number */ = await ai
22
22
  .chat('How many countries are in the EU')
23
- .to(o => o.number())
23
+ .toNumber()
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
 
27
27
  You can do this for types of any complexity:
28
28
  ```typescript
29
- const restaurants /* type: {name: string, address: string}[] */ = await ai
29
+ const restaurants /* type: {name: string, address?: string}[] */ = await ai
30
30
  .chat('Give 5 top restaurants in London')
31
- .to(o => o
32
- .array(e => e
33
- .object(o => o
34
- .hasString('name')
35
- .hasString('address')
36
- )
31
+ .toArray(o => o
32
+ .object(o => o
33
+ .hasString('name')
34
+ .canHaveString('address')
37
35
  )
38
36
  )
39
37
  ```
@@ -41,12 +39,10 @@ const restaurants /* type: {name: string, address: string}[] */ = await ai
41
39
  You can also put instructions to the LLM in your type spec:
42
40
  ```typescript
43
41
  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
- )
42
+ .chat('Give the top restaurant in London')
43
+ .toObject(o => o
44
+ .hasString('name')
45
+ .hasString('description', 'A 50 character description')
50
46
  )
51
47
  ```
52
48
 
@@ -72,12 +68,10 @@ And iterating (not awaiting) any streamed json element simply gives the stream o
72
68
  ```typescript
73
69
  const parsedPartialJsonStream = ai
74
70
  .chat('What are the top 5 restaurants in New York City?')
75
- .json(d => d
76
- .canBeArray(el => el
77
- .canBeObject(obj => obj
78
- .hasString('name')
79
- .hasString('address')
80
- )
71
+ .toArray(o => o
72
+ .object(o => o
73
+ .hasString('name')
74
+ .hasString('address')
81
75
  )
82
76
  )
83
77
  for await (const parsedPartialJson of parsedPartialJsonStream) {
package/build/index.d.ts CHANGED
@@ -863,7 +863,12 @@ export declare class BasicPrompt<PSArgs> implements AsyncGenerator<string>, Prom
863
863
  finally(onfinally?: (() => void) | null | undefined): Promise<string>;
864
864
  get [Symbol.toStringTag](): string;
865
865
  to<Json extends AnyJson = AnyJson>(type: (value: EmptyTypeSpec<unknown>) => TypeSpec<Json>): JsonPrompt<PSArgs, Json>;
866
- toJson(): JsonPrompt<PSArgs, AnyJson>;
866
+ toBoolean(): JsonPrompt<PSArgs, boolean>;
867
+ toString(): JsonPrompt<PSArgs, string>;
868
+ toNumber(): JsonPrompt<PSArgs, number>;
869
+ toObject<T_obj extends {}>(properties: (arg: TypeMemberSpec<{}>) => TypeMemberSpec<T_obj>): JsonPrompt<PSArgs, T_obj>;
870
+ toArray<T_arr extends AnyJson>(element: (arg: EmptyTypeSpec<unknown>) => TypeSpec<T_arr>): JsonPrompt<PSArgs, T_arr[]>;
871
+ toAny(): JsonPrompt<PSArgs, AnyJson>;
867
872
  private getResponseAsString;
868
873
  }
869
874
 
@@ -908,6 +913,7 @@ export declare class EmptyTypeSpec<T> extends TypeSpec<T> {
908
913
  constant<Value extends (string | number | boolean)>(value: Value, ...otherValues: Value[]): FullPropTypeSpec<Combine<T, Value>>;
909
914
  null(): FullTypeSpec<Combine<T, null>>;
910
915
  undefined(): FullTypeSpec<Combine<T, undefined>>;
916
+ any(): FullTypeSpec<Combine<T, AnyJson>>;
911
917
  }
912
918
 
913
919
  export declare class FullPropTypeSpec<T> extends PropTypeSpec<T> {