mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Merge pull request #1035 from microsoft/isidorn/annoyed-pelican
gracefully handle if model is not there
This commit is contained in:
@ -26,9 +26,11 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
vscode.LanguageModelChatMessage.User(topic)
|
||||
];
|
||||
const [model] = await vscode.lm.selectChatModels(MODEL_SELECTOR);
|
||||
const chatResponse = await model.sendRequest(messages, {}, token);
|
||||
for await (const fragment of chatResponse.text) {
|
||||
stream.markdown(fragment);
|
||||
if (model) {
|
||||
const chatResponse = await model.sendRequest(messages, {}, token);
|
||||
for await (const fragment of chatResponse.text) {
|
||||
stream.markdown(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
stream.button({
|
||||
@ -44,10 +46,13 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
vscode.LanguageModelChatMessage.User('Give a small random python code samples (that have cat names for variables). ' + request.prompt)
|
||||
];
|
||||
const [model] = await vscode.lm.selectChatModels(MODEL_SELECTOR);
|
||||
const chatResponse = await model.sendRequest(messages, {}, token);
|
||||
for await (const fragment of chatResponse.text) {
|
||||
stream.markdown(fragment);
|
||||
if (model) {
|
||||
const chatResponse = await model.sendRequest(messages, {}, token);
|
||||
for await (const fragment of chatResponse.text) {
|
||||
stream.markdown(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
return { metadata: { command: 'play' } };
|
||||
} else {
|
||||
const messages = [
|
||||
@ -56,12 +61,14 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
vscode.LanguageModelChatMessage.User(request.prompt)
|
||||
];
|
||||
const [model] = await vscode.lm.selectChatModels(MODEL_SELECTOR);
|
||||
const chatResponse = await model.sendRequest(messages, {}, token);
|
||||
for await (const fragment of chatResponse.text) {
|
||||
// Process the output from the language model
|
||||
// Replace all python function definitions with cat sounds to make the user stop looking at the code and start playing with the cat
|
||||
const catFragment = fragment.replaceAll('def', 'meow');
|
||||
stream.markdown(catFragment);
|
||||
if (model) {
|
||||
const chatResponse = await model.sendRequest(messages, {}, token);
|
||||
for await (const fragment of chatResponse.text) {
|
||||
// Process the output from the language model
|
||||
// Replace all python function definitions with cat sounds to make the user stop looking at the code and start playing with the cat
|
||||
const catFragment = fragment.replaceAll('def', 'meow');
|
||||
stream.markdown(catFragment);
|
||||
}
|
||||
}
|
||||
|
||||
return { metadata: { command: '' } };
|
||||
@ -98,6 +105,11 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
let chatResponse: vscode.LanguageModelChatResponse | undefined;
|
||||
try {
|
||||
const [model] = await vscode.lm.selectChatModels({ vendor: 'copilot', family: 'gpt-3.5-turbo' });
|
||||
if (!model) {
|
||||
console.log('Model not found. Please make sure the GitHub Copilot Chat extension is installed and enabled.')
|
||||
return;
|
||||
}
|
||||
|
||||
chatResponse = await model.sendRequest(messages, {}, new vscode.CancellationTokenSource().token);
|
||||
|
||||
} catch (err) {
|
||||
@ -108,7 +120,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
if (err instanceof vscode.LanguageModelError) {
|
||||
console.log(err.message, err.code, err.cause)
|
||||
}
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear the editor content before inserting new content
|
||||
|
||||
Reference in New Issue
Block a user