Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add model copilot_reference and update base catalog url #13

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/functions/execute-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ Example Queries (IMPORTANT: Phrasing doesn't have to match):
);

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.",
`The user has chosen to use the model named ${args.model}.`,
];

if (importantRefs.length > 0) {
Expand Down
28 changes: 27 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const server = createServer(async (request, response) => {
return;
}

// A tool has been called, so we need to execute the tool's function
const functionToCall = toolCaller.choices[0].message.tool_calls[0].function;
const args = JSON.parse(functionToCall.arguments);

Expand All @@ -164,8 +165,33 @@ const server = createServer(async (request, response) => {
}
console.timeEnd("function-exec");

// Now that we have a tool result, let's use it to call the model. Note that we're calling the model
// via the Models API, instead of the Copilot Chat API, so that if we're in the execute-model tool we
// can switch out the default model name for the requested model. We could change this in the future
// if we want to handle rate-limited users more gracefully or the model difference becomes a problem.
try {
// We should keep all optional parameters out of this call, so it can work for any model.
if (functionToCall.name == executeModel.definition.name) {
sgoedecke marked this conversation as resolved.
Show resolved Hide resolved
// fetch the model data from the index (already in-memory) so we have all the information we need
// to build out the reference URLs
const modelData = await modelsAPI.getModelFromIndex(functionCallRes.model);
const sseData = {
type: "models.reference",
id: `models.reference.${modelData.name}`,
data: {
model: functionCallRes.model
},
is_implicit: false,
metadata: {
display_name: `Model: ${modelData.name}`,
display_icon: "icon",
display_url: `https://github.com/marketplace/models/${modelData.registryName}/${modelData.name}`,
}
};
response.write(`event: copilot_references\ndata: ${JSON.stringify([sseData])}\n\n`);
}
JasonEtco marked this conversation as resolved.
Show resolved Hide resolved

// We should keep all optional parameters out of this call, so it can work for any model (in case we've
// just run the execute-model tool).
const stream = await modelsAPI.inference.chat.completions.create({
model: functionCallRes.model,
messages: functionCallRes.messages,
Expand Down
4 changes: 2 additions & 2 deletions src/models-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ModelsAPI {
const modelFromIndex = await this.getModelFromIndex(modelName);

const modelRes = await fetch(
`https://eastus.api.azureml.ms/asset-gallery/v1.0/${modelFromIndex.registryName}/models/${modelFromIndex.name}/version/${modelFromIndex.version}`,
`https://api.catalog.azureml.ms/asset-gallery/v1.0/${modelFromIndex.registryName}/models/${modelFromIndex.name}/version/${modelFromIndex.version}`,
);
if (!modelRes.ok) {
throw new Error(`Failed to fetch ${modelName} details from the model catalog.`);
Expand Down Expand Up @@ -75,7 +75,7 @@ export class ModelsAPI {
}

const modelsRes = await fetch(
"https://eastus.api.azureml.ms/asset-gallery/v1.0/models",
"https://api.catalog.azureml.ms/asset-gallery/v1.0/models",
{
method: "POST",
headers: {
Expand Down
Loading