@@ -33,7 +33,7 @@ test("minimal usage", async (t) => {
33
33
content : "What is the capital of France?" ,
34
34
} ,
35
35
] ,
36
- model : "gpt-4o-mini " ,
36
+ model : "gpt-4 " ,
37
37
} ) ,
38
38
} )
39
39
. reply (
@@ -57,7 +57,82 @@ test("minimal usage", async (t) => {
57
57
58
58
const result = await prompt ( "What is the capital of France?" , {
59
59
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
+ ] ,
61
136
request : { fetch : fetchMock } ,
62
137
} ) ;
63
138
0 commit comments