Skip to content

Commit 884c406

Browse files
committed
test: options.messages for prompt() and prompt(options)
1 parent 2938e55 commit 884c406

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

test/prompt.test.js

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

0 commit comments

Comments
 (0)