@@ -2,10 +2,11 @@ import { strict as assert } from "node:assert";
22import { Chat } from "../Chat" ;
33import { system , user , assistant } from "../ChatHelpers" ;
44import { Equal , Expect } from "./types.test" ;
5+ import { ToolBuilder } from "../ToolBuilder" ;
56
67describe ( "Chat" , ( ) => {
78 it ( "should allow empty array" , ( ) => {
8- const chat = new Chat ( [ ] , { } ) . toArray ( ) ;
9+ const chat = new Chat ( [ ] , { } , { } ) . toArray ( ) ;
910 type test = Expect < Equal < typeof chat , [ ] > > ;
1011 assert . deepEqual ( chat , [ ] ) ;
1112 } ) ;
@@ -54,16 +55,97 @@ describe("Chat", () => {
5455 } ) ;
5556
5657 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 ( ) ;
6158 const usrMsg = user ( "Tell me a joke" ) ;
6259 const astMsg = assistant ( "joke?" ) ;
6360 const sysMsg = system ( "joke?" ) ;
61+
62+ const chat = new Chat ( [ usrMsg , astMsg , sysMsg ] , { } ) . toArray ( ) ;
6463 type test = Expect <
6564 Equal < typeof chat , [ typeof usrMsg , typeof astMsg , typeof sysMsg ] >
6665 > ;
6766 assert . deepEqual ( chat , [ usrMsg , astMsg , sysMsg ] ) ;
6867 } ) ;
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+ } ) ;
69151} ) ;
0 commit comments