Skip to content

Commit ff1aeda

Browse files
authoredAug 27, 2024
Merge pull request #4 from copilot-extensions/list-format-improvements
List format improvements
2 parents 8719e5d + 3e78a41 commit ff1aeda

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed
 

‎src/functions/execute-model.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ Example Queries (IMPORTANT: Phrasing doesn't have to match):
2626
properties: {
2727
model: {
2828
type: "string",
29-
description:
30-
"The name of the model to execute. It is ONLY the name of the model, not the publisher or registry. For example: `gpt-4o`, or `cohere-command-r-plus`.",
29+
description: [
30+
"The name of the model to execute. It is ONLY the name of the model, not the publisher or registry.",
31+
"For example: `gpt-4o`, or `cohere-command-r-plus`.",
32+
"The list of models is available in the context window of the chat, in the `<-- LIST OF MODELS -->` section.",
33+
].join("\n"),
3134
},
3235
instruction: {
3336
type: "string",

‎src/functions/list-models.ts

+8-17
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,17 @@ export class listModels extends Tool {
2323
"The user is asking for a list of available models.",
2424
"Respond with a concise and readable list of the models, with a short description for each one.",
2525
"Use markdown formatting to make each description more readable.",
26-
"Begin each model's description with a header consisting of the model's registry and name",
27-
"The header must be formatted as `<registry>/<name>`.",
26+
"Begin each model's description with a header consisting of the model's name",
2827
"That list of models is as follows:",
28+
JSON.stringify(
29+
models.map((model) => ({
30+
name: model.friendly_name,
31+
publisher: model.publisher,
32+
description: model.summary,
33+
}))
34+
),
2935
];
3036

31-
for (const model of models) {
32-
systemMessage.push(
33-
[
34-
`\t- Model Name: ${model.name}`,
35-
`\t\tModel Version: ${model.model_version}`,
36-
`\t\tPublisher: ${model.publisher}`,
37-
`\t\tModel Family: ${model.model_family}`,
38-
`\t\tModel Registry: ${model.model_registry}`,
39-
`\t\tLicense: ${model.license}`,
40-
`\t\tTask: ${model.task}`,
41-
`\t\tSummary: ${model.summary}`,
42-
].join("\n")
43-
);
44-
}
45-
4637
return {
4738
model: defaultModel,
4839
messages: [

‎src/index.ts

+23-14
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ app.post("/", verifySignatureMiddleware, express.json(), async (req, res) => {
3737
"You are an extension of GitHub Copilot, built to interact with GitHub Models.",
3838
"GitHub Models is a language model playground, where you can experiment with different models and see how they respond to your prompts.",
3939
"Here is a list of some of the models available to the user:",
40+
"<-- LIST OF MODELS -->",
4041
JSON.stringify(
4142
models.map((model) => ({
43+
friendly_name: model.friendly_name,
4244
name: model.name,
4345
publisher: model.publisher,
4446
registry: model.model_registry,
4547
description: model.summary,
4648
}))
4749
),
50+
"<-- END OF LIST OF MODELS -->",
4851
].join("\n"),
4952
},
5053
...req.body.messages,
@@ -107,22 +110,28 @@ app.post("/", verifySignatureMiddleware, express.json(), async (req, res) => {
107110
}
108111
console.timeEnd("function-exec");
109112

110-
console.time("stream");
111-
const stream = await modelsAPI.inference.chat.completions.create({
112-
model: functionCallRes.model,
113-
messages: functionCallRes.messages,
114-
stream: true,
115-
});
116-
console.timeEnd("stream");
113+
try {
114+
const stream = await modelsAPI.inference.chat.completions.create({
115+
model: functionCallRes.model,
116+
messages: functionCallRes.messages,
117+
stream: true,
118+
stream_options: {
119+
include_usage: false,
120+
},
121+
});
117122

118-
console.time("streaming");
119-
for await (const chunk of stream) {
120-
const chunkStr = "data: " + JSON.stringify(chunk) + "\n\n";
121-
res.write(chunkStr);
123+
console.time("streaming");
124+
for await (const chunk of stream) {
125+
const chunkStr = "data: " + JSON.stringify(chunk) + "\n\n";
126+
res.write(chunkStr);
127+
}
128+
res.write("data: [DONE]\n\n");
129+
console.timeEnd("streaming");
130+
res.end();
131+
} catch (err) {
132+
console.error(err);
133+
res.status(500).end();
122134
}
123-
res.write("data: [DONE]\n\n");
124-
console.timeEnd("streaming");
125-
res.end();
126135
});
127136

128137
// Health check

0 commit comments

Comments
 (0)
Failed to load comments.