@@ -2,10 +2,11 @@ import { strict as assert } from "node:assert";
2
2
import { Chat } from "../Chat" ;
3
3
import { system , user , assistant } from "../ChatHelpers" ;
4
4
import { Equal , Expect } from "./types.test" ;
5
+ import { ToolBuilder } from "../ToolBuilder" ;
5
6
6
7
describe ( "Chat" , ( ) => {
7
8
it ( "should allow empty array" , ( ) => {
8
- const chat = new Chat ( [ ] , { } ) . toArray ( ) ;
9
+ const chat = new Chat ( [ ] , { } , { } ) . toArray ( ) ;
9
10
type test = Expect < Equal < typeof chat , [ ] > > ;
10
11
assert . deepEqual ( chat , [ ] ) ;
11
12
} ) ;
@@ -54,16 +55,97 @@ describe("Chat", () => {
54
55
} ) ;
55
56
56
57
it ( "should allow chat of all diffent types with no args" , ( ) => {
57
- const chat = new Chat (
58
- [ user ( `Tell me a joke` ) , assistant ( `joke?` ) , system ( `joke?` ) ] ,
59
- { } ,
60
- ) . toArray ( ) ;
61
58
const usrMsg = user ( "Tell me a joke" ) ;
62
59
const astMsg = assistant ( "joke?" ) ;
63
60
const sysMsg = system ( "joke?" ) ;
61
+
62
+ const chat = new Chat ( [ usrMsg , astMsg , sysMsg ] , { } ) . toArray ( ) ;
64
63
type test = Expect <
65
64
Equal < typeof chat , [ typeof usrMsg , typeof astMsg , typeof sysMsg ] >
66
65
> ;
67
66
assert . deepEqual ( chat , [ usrMsg , astMsg , sysMsg ] ) ;
68
67
} ) ;
68
+
69
+ it ( "should allow me to pass in tools" , ( ) => {
70
+ const usrMsg = user ( "Tell me a joke" ) ;
71
+ const astMsg = assistant ( "joke?" ) ;
72
+ const sysMsg = system ( "joke?" ) ;
73
+ const tools = {
74
+ google : new ToolBuilder ( "google" )
75
+ . addInputValidation < { query : string } > ( )
76
+ . addOutputValidation < { results : string [ ] } > ( )
77
+ . query ( ( { query } ) => {
78
+ return {
79
+ results : [ "foo" , "bar" ] ,
80
+ } ;
81
+ } ) ,
82
+ wikipedia : new ToolBuilder ( "wikipedia" )
83
+ . addInputValidation < { page : string } > ( )
84
+ . addOutputValidation < { results : string [ ] } > ( )
85
+ . query ( ( { page } ) => {
86
+ return {
87
+ results : [ "foo" , "bar" ] ,
88
+ } ;
89
+ } ) ,
90
+ sendEmail : new ToolBuilder ( "sendEmail" )
91
+ . addInputValidation < { to : string ; subject : string ; body : string } > ( )
92
+ . addOutputValidation < { success : boolean } > ( )
93
+ . mutation ( ( { to, subject, body } ) => {
94
+ return {
95
+ success : true ,
96
+ } ;
97
+ } ) ,
98
+ } as const ;
99
+
100
+ const chat = new Chat ( [ usrMsg , astMsg , sysMsg ] , { } , tools ) ;
101
+
102
+ type tests = [
103
+ Expect <
104
+ Equal <
105
+ typeof chat ,
106
+ Chat <
107
+ keyof typeof tools ,
108
+ [ typeof usrMsg , typeof astMsg , typeof sysMsg ] ,
109
+ { }
110
+ >
111
+ >
112
+ > ,
113
+ Expect <
114
+ Equal <
115
+ typeof tools ,
116
+ {
117
+ readonly google : ToolBuilder <
118
+ "query" ,
119
+ {
120
+ query : string ;
121
+ } ,
122
+ {
123
+ results : string [ ] ;
124
+ }
125
+ > ;
126
+ readonly wikipedia : ToolBuilder <
127
+ "query" ,
128
+ {
129
+ page : string ;
130
+ } ,
131
+ {
132
+ results : string [ ] ;
133
+ }
134
+ > ;
135
+ readonly sendEmail : ToolBuilder <
136
+ "mutation" ,
137
+ {
138
+ to : string ;
139
+ subject : string ;
140
+ body : string ;
141
+ } ,
142
+ {
143
+ success : boolean ;
144
+ }
145
+ > ;
146
+ }
147
+ >
148
+ >
149
+ ] ;
150
+ } ) ;
69
151
} ) ;
0 commit comments