@@ -70,6 +70,129 @@ suite("prompt", () => {
7070 } ) ;
7171 } ) ;
7272
73+ test ( "options.messages" , async ( t ) => {
74+ const mockAgent = new MockAgent ( ) ;
75+ function fetchMock ( url , opts ) {
76+ opts ||= { } ;
77+ opts . dispatcher = mockAgent ;
78+ return fetch ( url , opts ) ;
79+ }
80+
81+ mockAgent . disableNetConnect ( ) ;
82+ const mockPool = mockAgent . get ( "https://api.githubcopilot.com" ) ;
83+ mockPool
84+ . intercept ( {
85+ method : "post" ,
86+ path : `/chat/completions` ,
87+ body : JSON . stringify ( {
88+ messages : [
89+ { role : "system" , content : "You are a helpful assistant." } ,
90+ { role : "user" , content : "What is the capital of France?" } ,
91+ { role : "assistant" , content : "The capital of France is Paris." } ,
92+ { role : "user" , content : "What about Spain?" } ,
93+ ] ,
94+ model : "gpt-4" ,
95+ } ) ,
96+ } )
97+ . reply (
98+ 200 ,
99+ {
100+ choices : [
101+ {
102+ message : {
103+ content : "<response text>" ,
104+ } ,
105+ } ,
106+ ] ,
107+ } ,
108+ {
109+ headers : {
110+ "content-type" : "application/json" ,
111+ "x-request-id" : "<request-id>" ,
112+ } ,
113+ }
114+ ) ;
115+
116+ const result = await prompt ( "What about Spain?" , {
117+ model : "gpt-4" ,
118+ token : "secret" ,
119+ messages : [
120+ { role : "user" , content : "What is the capital of France?" } ,
121+ { role : "assistant" , content : "The capital of France is Paris." } ,
122+ ] ,
123+ request : { fetch : fetchMock } ,
124+ } ) ;
125+
126+ t . assert . deepEqual ( result , {
127+ requestId : "<request-id>" ,
128+ message : {
129+ content : "<response text>" ,
130+ } ,
131+ } ) ;
132+ } ) ;
133+
134+ test ( "single options argument" , async ( t ) => {
135+ const mockAgent = new MockAgent ( ) ;
136+ function fetchMock ( url , opts ) {
137+ opts ||= { } ;
138+ opts . dispatcher = mockAgent ;
139+ return fetch ( url , opts ) ;
140+ }
141+
142+ mockAgent . disableNetConnect ( ) ;
143+ const mockPool = mockAgent . get ( "https://api.githubcopilot.com" ) ;
144+ mockPool
145+ . intercept ( {
146+ method : "post" ,
147+ path : `/chat/completions` ,
148+ body : JSON . stringify ( {
149+ messages : [
150+ { role : "system" , content : "You are a helpful assistant." } ,
151+ { role : "user" , content : "What is the capital of France?" } ,
152+ { role : "assistant" , content : "The capital of France is Paris." } ,
153+ { role : "user" , content : "What about Spain?" } ,
154+ ] ,
155+ model : "gpt-4" ,
156+ } ) ,
157+ } )
158+ . reply (
159+ 200 ,
160+ {
161+ choices : [
162+ {
163+ message : {
164+ content : "<response text>" ,
165+ } ,
166+ } ,
167+ ] ,
168+ } ,
169+ {
170+ headers : {
171+ "content-type" : "application/json" ,
172+ "x-request-id" : "<request-id>" ,
173+ } ,
174+ }
175+ ) ;
176+
177+ const result = await prompt ( {
178+ model : "gpt-4" ,
179+ token : "secret" ,
180+ messages : [
181+ { role : "user" , content : "What is the capital of France?" } ,
182+ { role : "assistant" , content : "The capital of France is Paris." } ,
183+ { role : "user" , content : "What about Spain?" } ,
184+ ] ,
185+ request : { fetch : fetchMock } ,
186+ } ) ;
187+
188+ t . assert . deepEqual ( result , {
189+ requestId : "<request-id>" ,
190+ message : {
191+ content : "<response text>" ,
192+ } ,
193+ } ) ;
194+ } ) ;
195+
73196 test ( "function calling" , async ( t ) => {
74197 const mockAgent = new MockAgent ( ) ;
75198 function fetchMock ( url , opts ) {
0 commit comments