@@ -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
} ) ;
@@ -43,7 +44,6 @@ describe("Chat", () => {
43
44
it ( "should allow chat of all diffent types" , ( ) => {
44
45
const chat = new Chat (
45
46
[
46
- // ^?
47
47
user ( `Tell me a {{jokeType1}} joke` ) ,
48
48
assistant ( `{{var2}} joke?` ) ,
49
49
system ( `joke? {{var3}}` ) ,
@@ -64,21 +64,97 @@ describe("Chat", () => {
64
64
} ) ;
65
65
66
66
it ( "should allow chat of all diffent types with no args" , ( ) => {
67
- const chat = new Chat (
68
- [
69
- // ^?
70
- user ( `Tell me a joke` ) ,
71
- assistant ( `joke?` ) ,
72
- system ( `joke?` ) ,
73
- ] ,
74
- { }
75
- ) . toArray ( ) ;
76
67
const usrMsg = user ( "Tell me a joke" ) ;
77
68
const astMsg = assistant ( "joke?" ) ;
78
69
const sysMsg = system ( "joke?" ) ;
70
+
71
+ const chat = new Chat ( [ usrMsg , astMsg , sysMsg ] , { } ) . toArray ( ) ;
79
72
type test = Expect <
80
73
Equal < typeof chat , [ typeof usrMsg , typeof astMsg , typeof sysMsg ] >
81
74
> ;
82
75
assert . deepEqual ( chat , [ usrMsg , astMsg , sysMsg ] ) ;
83
76
} ) ;
77
+
78
+ it ( "should allow me to pass in tools" , ( ) => {
79
+ const usrMsg = user ( "Tell me a joke" ) ;
80
+ const astMsg = assistant ( "joke?" ) ;
81
+ const sysMsg = system ( "joke?" ) ;
82
+ const tools = {
83
+ google : new ToolBuilder ( "google" )
84
+ . addInputValidation < { query : string } > ( )
85
+ . addOutputValidation < { results : string [ ] } > ( )
86
+ . query ( ( { query } ) => {
87
+ return {
88
+ results : [ "foo" , "bar" ] ,
89
+ } ;
90
+ } ) ,
91
+ wikipedia : new ToolBuilder ( "wikipedia" )
92
+ . addInputValidation < { page : string } > ( )
93
+ . addOutputValidation < { results : string [ ] } > ( )
94
+ . query ( ( { page } ) => {
95
+ return {
96
+ results : [ "foo" , "bar" ] ,
97
+ } ;
98
+ } ) ,
99
+ sendEmail : new ToolBuilder ( "sendEmail" )
100
+ . addInputValidation < { to : string ; subject : string ; body : string } > ( )
101
+ . addOutputValidation < { success : boolean } > ( )
102
+ . mutation ( ( { to, subject, body } ) => {
103
+ return {
104
+ success : true ,
105
+ } ;
106
+ } ) ,
107
+ } as const ;
108
+
109
+ const chat = new Chat ( [ usrMsg , astMsg , sysMsg ] , { } , tools ) ;
110
+
111
+ type tests = [
112
+ Expect <
113
+ Equal <
114
+ typeof chat ,
115
+ Chat <
116
+ keyof typeof tools ,
117
+ [ typeof usrMsg , typeof astMsg , typeof sysMsg ] ,
118
+ { }
119
+ >
120
+ >
121
+ > ,
122
+ Expect <
123
+ Equal <
124
+ typeof tools ,
125
+ {
126
+ readonly google : ToolBuilder <
127
+ "query" ,
128
+ {
129
+ query : string ;
130
+ } ,
131
+ {
132
+ results : string [ ] ;
133
+ }
134
+ > ;
135
+ readonly wikipedia : ToolBuilder <
136
+ "query" ,
137
+ {
138
+ page : string ;
139
+ } ,
140
+ {
141
+ results : string [ ] ;
142
+ }
143
+ > ;
144
+ readonly sendEmail : ToolBuilder <
145
+ "mutation" ,
146
+ {
147
+ to : string ;
148
+ subject : string ;
149
+ body : string ;
150
+ } ,
151
+ {
152
+ success : boolean ;
153
+ }
154
+ > ;
155
+ }
156
+ >
157
+ >
158
+ ] ;
159
+ } ) ;
84
160
} ) ;
0 commit comments