@@ -33,7 +33,7 @@ test("minimal usage", async (t) => {
3333 content : "What is the capital of France?" ,
3434 } ,
3535 ] ,
36- model : "gpt-4o-mini " ,
36+ model : "gpt-4 " ,
3737 } ) ,
3838 } )
3939 . reply (
@@ -57,7 +57,82 @@ test("minimal usage", async (t) => {
5757
5858 const result = await prompt ( "What is the capital of France?" , {
5959 token : "secret" ,
60- model : "gpt-4o-mini" ,
60+ model : "gpt-4" ,
61+ request : { fetch : fetchMock } ,
62+ } ) ;
63+
64+ t . assert . deepEqual ( result , {
65+ requestId : "<request-id>" ,
66+ message : {
67+ content : "<response text>" ,
68+ } ,
69+ } ) ;
70+ } ) ;
71+
72+ test ( "function calling" , async ( t ) => {
73+ const mockAgent = new MockAgent ( ) ;
74+ function fetchMock ( url , opts ) {
75+ opts ||= { } ;
76+ opts . dispatcher = mockAgent ;
77+ return fetch ( url , opts ) ;
78+ }
79+
80+ mockAgent . disableNetConnect ( ) ;
81+ const mockPool = mockAgent . get ( "https://api.githubcopilot.com" ) ;
82+ mockPool
83+ . intercept ( {
84+ method : "post" ,
85+ path : `/chat/completions` ,
86+ body : JSON . stringify ( {
87+ messages : [
88+ {
89+ role : "system" ,
90+ content :
91+ "You are a helpful assistant. Use the supplied tools to assist the user." ,
92+ } ,
93+ { role : "user" , content : "Call the function" } ,
94+ ] ,
95+ model : "gpt-4" ,
96+ toolChoice : "auto" ,
97+ tools : [
98+ {
99+ type : "function" ,
100+ function : { name : "the_function" , description : "The function" } ,
101+ } ,
102+ ] ,
103+ } ) ,
104+ } )
105+ . reply (
106+ 200 ,
107+ {
108+ choices : [
109+ {
110+ message : {
111+ content : "<response text>" ,
112+ } ,
113+ } ,
114+ ] ,
115+ } ,
116+ {
117+ headers : {
118+ "content-type" : "application/json" ,
119+ "x-request-id" : "<request-id>" ,
120+ } ,
121+ }
122+ ) ;
123+
124+ const result = await prompt ( "Call the function" , {
125+ token : "secret" ,
126+ model : "gpt-4" ,
127+ tools : [
128+ {
129+ type : "function" ,
130+ function : {
131+ name : "the_function" ,
132+ description : "The function" ,
133+ } ,
134+ } ,
135+ ] ,
61136 request : { fetch : fetchMock } ,
62137 } ) ;
63138
0 commit comments