Adds dynamic Claude model fetching and management #1
@@ -32,6 +32,11 @@ export class ModelService {
|
|||||||
return this.formatModels(this.modelCache.models);
|
return this.formatModels(this.modelCache.models);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no API key, quietly return fallback
|
||||||
|
if (!this.anthropicClient.validateApiKey()) {
|
||||||
|
return this.getFallbackModels();
|
||||||
|
}
|
||||||
|
|
||||||
// Try to fetch from API
|
// Try to fetch from API
|
||||||
try {
|
try {
|
||||||
const response = await this.anthropicClient.fetchModels();
|
const response = await this.anthropicClient.fetchModels();
|
||||||
@@ -49,6 +54,11 @@ export class ModelService {
|
|||||||
* Used when user changes API key
|
* Used when user changes API key
|
||||||
*/
|
*/
|
||||||
async refreshModels(): Promise<ModelOption[]> {
|
async refreshModels(): Promise<ModelOption[]> {
|
||||||
|
// If no API key, quietly return fallback
|
||||||
|
if (!this.anthropicClient.validateApiKey()) {
|
||||||
|
return this.getFallbackModels();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.anthropicClient.fetchModels();
|
const response = await this.anthropicClient.fetchModels();
|
||||||
this.updateCache(response.data);
|
this.updateCache(response.data);
|
||||||
@@ -114,7 +124,7 @@ export class ModelService {
|
|||||||
return models.map(model => ({
|
return models.map(model => ({
|
||||||
id: model.id,
|
id: model.id,
|
||||||
displayName: model.display_name || model.id
|
displayName: model.display_name || model.id
|
||||||
}));
|
})).sort((a, b) => a.displayName.localeCompare(b.displayName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,6 +134,6 @@ export class ModelService {
|
|||||||
return ANTHROPIC_MODELS.map(id => ({
|
return ANTHROPIC_MODELS.map(id => ({
|
||||||
id,
|
id,
|
||||||
displayName: id
|
displayName: id
|
||||||
}));
|
})).sort((a, b) => a.displayName.localeCompare(b.displayName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user