| 583 | } |
| 584 | |
| 585 | async completePrompt(prompt: string): Promise<string> { |
| 586 | try { |
| 587 | const client = await this.getClient() |
| 588 | const response = await client.sendRequest( |
| 589 | [vscode.LanguageModelChatMessage.User(prompt)], |
| 590 | {}, |
| 591 | new vscode.CancellationTokenSource().token, |
| 592 | ) |
| 593 | let result = "" |
| 594 | for await (const chunk of response.stream) { |
| 595 | if (chunk instanceof vscode.LanguageModelTextPart) { |
| 596 | result += chunk.value |
| 597 | } |
| 598 | } |
| 599 | return result |
| 600 | } catch (error) { |
| 601 | if (error instanceof Error) { |
| 602 | throw new Error(`VSCode LM completion error: ${error.message}`) |
| 603 | } |
| 604 | throw error |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | // Static blacklist of VS Code Language Model IDs that should be excluded from the model list e.g. because they will never work |