Skip to content

Commit c8b6a7d

Browse files
authoredSep 4, 2024
fix(prompt): parameters.model is now a string and is optional. It defaults to gpt-4 (copilot-extensions#53)
- **fix(types): `ModelName` is a string now** - **docs(README): `model` parameter is no longer required for `prompt()`. It defaults to `gpt-4`** - **fix: `model` parameter is now optional for `prompt()`. It defaults to `gpt-4`**
1 parent 9e65270 commit c8b6a7d

File tree

5 files changed

+69
-25
lines changed

5 files changed

+69
-25
lines changed
 

‎README.md

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import { prompt } from "@copilot-extensions/preview-sdk";
4545

4646
try {
4747
const { message } = await prompt("What is the capital of France?", {
48-
model: "gpt-4",
4948
token: process.env.TOKEN,
5049
});
5150

‎index.d.ts

+6-15
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,12 @@ export interface GetUserConfirmationInterface {
256256

257257
/**
258258
* model names supported by Copilot API
259-
*
260-
* Based on https://api.githubcopilot.com/models from 2024-09-02
259+
* A list of currently supported models can be retrieved at
260+
* https://api.githubcopilot.com/models. We set `ModelName` to `string`
261+
* instead of a union of the supported models as we cannot give
262+
* guarantees about the supported models in the future.
261263
*/
262-
export type ModelName =
263-
| "gpt-3.5-turbo"
264-
| "gpt-3.5-turbo-0613"
265-
| "gpt-4"
266-
| "gpt-4-0613"
267-
| "gpt-4-o-preview"
268-
| "gpt-4o"
269-
| "gpt-4o-2024-05-13"
270-
| "text-embedding-3-small"
271-
| "text-embedding-3-small-inference"
272-
| "text-embedding-ada-002"
273-
| "text-embedding-ada-002-index"
264+
export type ModelName = string
274265

275266
export interface PromptFunction {
276267
type: "function"
@@ -284,7 +275,7 @@ export interface PromptFunction {
284275
}
285276

286277
export type PromptOptions = {
287-
model: ModelName
278+
model?: ModelName
288279
token: string
289280
tools?: PromptFunction[]
290281
messages?: InteropMessage[]

‎index.test-d.ts

-3
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,6 @@ export async function promptTest() {
291291
// @ts-expect-error - 2nd argument is required
292292
prompt("What is the capital of France?")
293293

294-
// @ts-expect-error - model argument is required
295-
prompt("What is the capital of France?", { token: "" })
296-
297294
// @ts-expect-error - token argument is required
298295
prompt("What is the capital of France?", { model: "" })
299296
}

‎lib/prompt.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export async function prompt(userPrompt, promptOptions) {
55
const options = typeof userPrompt === "string" ? promptOptions : userPrompt;
66

77
const promptFetch = options.request?.fetch || fetch;
8+
const modelName = options.model || "gpt-4";
89

910
const systemMessage = options.tools
1011
? "You are a helpful assistant. Use the supplied tools to assist the user."
@@ -40,7 +41,7 @@ export async function prompt(userPrompt, promptOptions) {
4041
},
4142
body: JSON.stringify({
4243
messages: messages,
43-
model: options.model,
44+
model: modelName,
4445
toolChoice: options.tools ? "auto" : undefined,
4546
tools: options.tools,
4647
}),

‎test/prompt.test.js

+61-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,67 @@ suite("prompt", () => {
5858

5959
const result = await prompt("What is the capital of France?", {
6060
token: "secret",
61-
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("options.prompt", 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+
{ role: "system", content: "You are a helpful assistant." },
89+
{ role: "user", content: "What is the capital of France?" },
90+
{ role: "assistant", content: "The capital of France is Paris." },
91+
{ role: "user", content: "What about Spain?" },
92+
],
93+
model: "<custom-model>",
94+
}),
95+
})
96+
.reply(
97+
200,
98+
{
99+
choices: [
100+
{
101+
message: {
102+
content: "<response text>",
103+
},
104+
},
105+
],
106+
},
107+
{
108+
headers: {
109+
"content-type": "application/json",
110+
"x-request-id": "<request-id>",
111+
},
112+
}
113+
);
114+
115+
const result = await prompt("What about Spain?", {
116+
model: "<custom-model>",
117+
token: "secret",
118+
messages: [
119+
{ role: "user", content: "What is the capital of France?" },
120+
{ role: "assistant", content: "The capital of France is Paris." },
121+
],
62122
request: { fetch: fetchMock },
63123
});
64124

@@ -114,7 +174,6 @@ suite("prompt", () => {
114174
);
115175

116176
const result = await prompt("What about Spain?", {
117-
model: "gpt-4",
118177
token: "secret",
119178
messages: [
120179
{ role: "user", content: "What is the capital of France?" },
@@ -175,7 +234,6 @@ suite("prompt", () => {
175234
);
176235

177236
const result = await prompt({
178-
model: "gpt-4",
179237
token: "secret",
180238
messages: [
181239
{ role: "user", content: "What is the capital of France?" },
@@ -247,7 +305,6 @@ suite("prompt", () => {
247305

248306
const result = await prompt("Call the function", {
249307
token: "secret",
250-
model: "gpt-4",
251308
tools: [
252309
{
253310
type: "function",
@@ -305,7 +362,6 @@ suite("prompt", () => {
305362

306363
const result = await prompt("What is the capital of France?", {
307364
token: "secret",
308-
model: "gpt-4",
309365
request: { fetch: fetchMock },
310366
});
311367

0 commit comments

Comments
 (0)
Failed to load comments.