Skip to content

Commit

Permalink
Improve execute-model to include some client references, and improve …
Browse files Browse the repository at this point in the history
…function description
  • Loading branch information
JasonEtco committed Aug 16, 2024
1 parent a33e6e6 commit 6b9f94d
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/functions/execute-model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import OpenAI from "openai";
import { RunnerResponse, Tool } from "../functions";

type MessageWithReferences = OpenAI.ChatCompletionMessageParam & {
copilot_references: Reference[];
};

interface Reference {
type: string;
data: any;
id: string;
metadata: any;
}

export class executeModel extends Tool {
static definition = {
name: "execute_model",
description:
'Executes a model. This will often be used by saying something like "using <model>: <instruction>".',
description: `This function sends the prompt from the user's message to the specified model.".
Example Queries (IMPORTANT: Phrasing doesn't have to match):
- using gpt-4o-mini: what is 1+1?
- using Mistral-large: what is the capital of France?
- using cohere-command-r-plus: explain this code.
`,
parameters: {
type: "object",
properties: {
Expand All @@ -24,19 +39,36 @@ export class executeModel extends Tool {
};

async execute(
_: OpenAI.ChatCompletionMessageParam[],
messages: MessageWithReferences[],
args: {
model: string;
instruction: string;
}
): Promise<RunnerResponse> {
// Check if the user included any code references in their last message
const lastMessage = messages[messages.length - 1];
const importantRefs = lastMessage.copilot_references.filter(
(ref) => ref.type === "client.selection" || ref.type === "client.file"
);

const content = [
`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}".`,
"Do not include any additional information about the selected model in this first sentence - ONLY the name.",
];

if (importantRefs) {
content.push(
"The user included the following context - you may find information in this context useful for your response:",
JSON.stringify(importantRefs)
);
}

return {
model: args.model,
messages: [
{
role: "system",
content:
"Begin your response by telling the user the name of your language model.",
content: content.join("\n"),
},
{ role: "user", content: args.instruction },
],
Expand Down

0 comments on commit 6b9f94d

Please sign in to comment.