Skip to content

Commit 6b9f94d

Browse files
committedAug 16, 2024
Improve execute-model to include some client references, and improve function description
1 parent a33e6e6 commit 6b9f94d

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed
 

‎src/functions/execute-model.ts

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
import OpenAI from "openai";
22
import { RunnerResponse, Tool } from "../functions";
33

4+
type MessageWithReferences = OpenAI.ChatCompletionMessageParam & {
5+
copilot_references: Reference[];
6+
};
7+
8+
interface Reference {
9+
type: string;
10+
data: any;
11+
id: string;
12+
metadata: any;
13+
}
14+
415
export class executeModel extends Tool {
516
static definition = {
617
name: "execute_model",
7-
description:
8-
'Executes a model. This will often be used by saying something like "using <model>: <instruction>".',
18+
description: `This function sends the prompt from the user's message to the specified model.".
19+
Example Queries (IMPORTANT: Phrasing doesn't have to match):
20+
- using gpt-4o-mini: what is 1+1?
21+
- using Mistral-large: what is the capital of France?
22+
- using cohere-command-r-plus: explain this code.
23+
`,
924
parameters: {
1025
type: "object",
1126
properties: {
@@ -24,19 +39,36 @@ export class executeModel extends Tool {
2439
};
2540

2641
async execute(
27-
_: OpenAI.ChatCompletionMessageParam[],
42+
messages: MessageWithReferences[],
2843
args: {
2944
model: string;
3045
instruction: string;
3146
}
3247
): Promise<RunnerResponse> {
48+
// Check if the user included any code references in their last message
49+
const lastMessage = messages[messages.length - 1];
50+
const importantRefs = lastMessage.copilot_references.filter(
51+
(ref) => ref.type === "client.selection" || ref.type === "client.file"
52+
);
53+
54+
const content = [
55+
`The user has chosen to use the model named ${args.model}. Begin your response with the following phrase: "The model you've selected is ${args.model}".`,
56+
"Do not include any additional information about the selected model in this first sentence - ONLY the name.",
57+
];
58+
59+
if (importantRefs) {
60+
content.push(
61+
"The user included the following context - you may find information in this context useful for your response:",
62+
JSON.stringify(importantRefs)
63+
);
64+
}
65+
3366
return {
3467
model: args.model,
3568
messages: [
3669
{
3770
role: "system",
38-
content:
39-
"Begin your response by telling the user the name of your language model.",
71+
content: content.join("\n"),
4072
},
4173
{ role: "user", content: args.instruction },
4274
],

0 commit comments

Comments
 (0)
Failed to load comments.