mirror of
https://github.com/ggml-org/llama.vscode.git
synced 2026-05-07 01:15:23 +00:00
Compare commits
1 commit
master
...
back_to_wo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
342d2511a9 |
2 changed files with 18 additions and 38 deletions
|
|
@ -2,7 +2,7 @@
|
|||
"name": "llama-vscode",
|
||||
"displayName": "llama-vscode",
|
||||
"description": "Local LLM-assisted text completion using llama.cpp",
|
||||
"version": "0.0.47",
|
||||
"version": "0.0.46",
|
||||
"publisher": "ggml-org",
|
||||
"repository": "https://github.com/ggml-org/llama.vscode",
|
||||
"engines": {
|
||||
|
|
|
|||
|
|
@ -44,13 +44,13 @@ export class OpenAiCompModelStrategy implements IAddStrategy {
|
|||
prompt: 'example: http://localhost:8080 or https://openrauter.ai/api'
|
||||
})??""
|
||||
isKeyRequired = await Utils.confirmAction(`Is API key required for this endpoint (${endpoint})?`, "");
|
||||
}
|
||||
}
|
||||
if (!endpoint){
|
||||
vscode.window.showWarningMessage("Endpoint is not provided!")
|
||||
return;
|
||||
}
|
||||
const providerModels: QuickPickItem[] = [];
|
||||
const models = await this.getModels(endpoint, isKeyRequired);
|
||||
const models = await this.getModels(endpoint);
|
||||
if (models.length == 0) {
|
||||
vscode.window.showInformationMessage("No models are found.")
|
||||
return
|
||||
|
|
@ -108,50 +108,30 @@ export class OpenAiCompModelStrategy implements IAddStrategy {
|
|||
}
|
||||
}
|
||||
|
||||
private async getModels(endpoint: string, isKeyRequired: boolean): Promise<OpenAiCompModel[]> {
|
||||
const hfEndpoint = Utils.trimTrailingSlash(endpoint) + "/v1/models";
|
||||
|
||||
// Create a request configuration
|
||||
let requestConfig: any = {};
|
||||
|
||||
if (isKeyRequired) {
|
||||
// We get the saved key for this specific endpoint
|
||||
const apiKey = this.app.persistence.getApiKey(endpoint);
|
||||
if (apiKey) {
|
||||
requestConfig = {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private async getModels(endpoint: string): Promise<OpenAiCompModel[]> {
|
||||
let hfEndpoint = Utils.trimTrailingSlash(endpoint) +"/v1/models";
|
||||
try {
|
||||
const result = await axios.default.get(
|
||||
`${Utils.trimTrailingSlash(hfEndpoint)}`,
|
||||
requestConfig
|
||||
let result = await axios.default.get(
|
||||
`${Utils.trimTrailingSlash(hfEndpoint)}`
|
||||
);
|
||||
|
||||
let models: OpenAiCompModel[] = [];
|
||||
let modelsList: OpenAiCompModel[] = [];
|
||||
|
||||
if (result && result.data && result.data.models) modelsList = result.data.models;
|
||||
else if (result && result.data && result.data.data) modelsList = result.data.data;
|
||||
|
||||
if (modelsList.length > 0) {
|
||||
for (let mdl of modelsList) {
|
||||
models.push(mdl);
|
||||
|
||||
let modelsList: OpenAiCompModel[] = []
|
||||
if (result && result.data && result.data.models) modelsList = result.data.models
|
||||
else if (result && result.data && result.data.data) modelsList = result.data.data
|
||||
if (modelsList.length > 0){
|
||||
for(let mdl of modelsList){
|
||||
models.push(mdl)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return models;
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage("Error getting provider models: " + error);
|
||||
} catch (error){
|
||||
vscode.window.showErrorMessage("Error getting provider models): " + error)
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private sanitizeInput(input: string): string {
|
||||
return input ? input.trim() : '';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue