Skip to content

Commit 4e3d99c

Browse files
authored
Fix OAuth Implementation (#29)
## Pull Request Overview This PR fixes OAuth implementation for the AI Chat feature by improving model validation, enhancing OAuth flow robustness, and adding comprehensive test coverage. - Updates the default nano model for OpenRouter provider - Adds comprehensive model validation logic with automatic fallbacks - Enhances OAuth implementation with better error handling and deduplication - Includes comprehensive test coverage for model validation functionality
1 parent ad6f7e7 commit 4e3d99c

File tree

4 files changed

+761
-148
lines changed

4 files changed

+761
-148
lines changed

front_end/panels/ai_chat/LLM/OpenRouterProvider.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export class OpenRouterProvider extends LLMBaseProvider {
7070
return `${OpenRouterProvider.API_BASE_URL}${OpenRouterProvider.MODELS_PATH}`;
7171
}
7272

73+
/**
74+
* Get the models endpoint URL with tool support filter
75+
*/
76+
private getToolSupportingModelsEndpoint(): string {
77+
return `${OpenRouterProvider.API_BASE_URL}${OpenRouterProvider.MODELS_PATH}?supported_parameters=tools`;
78+
}
79+
7380
/**
7481
* Converts LLMMessage format to OpenRouter/OpenAI format
7582
*/
@@ -266,13 +273,13 @@ export class OpenRouterProvider extends LLMBaseProvider {
266273
}
267274

268275
/**
269-
* Fetch available models from OpenRouter API
276+
* Fetch available models from OpenRouter API that support tool calls
270277
*/
271278
async fetchModels(): Promise<OpenRouterModel[]> {
272-
logger.debug('Fetching available OpenRouter models...');
279+
logger.debug('Fetching available OpenRouter models that support tool calls...');
273280

274281
try {
275-
const response = await fetch(this.getModelsEndpoint(), {
282+
const response = await fetch(this.getToolSupportingModelsEndpoint(), {
276283
method: 'GET',
277284
headers: {
278285
'Authorization': `Bearer ${this.apiKey}`,
@@ -330,17 +337,9 @@ export class OpenRouterProvider extends LLMBaseProvider {
330337
* Check if a model supports function calling based on its metadata
331338
*/
332339
private modelSupportsFunctionCalling(model: OpenRouterModel): boolean {
333-
// Most modern models on OpenRouter support function calling
334-
// We can be more specific based on known models
335-
const functionCallingModels = [
336-
'gpt-4', 'gpt-3.5-turbo', 'claude-3', 'claude-2',
337-
'mistral', 'mixtral', 'llama-3', 'gemini'
338-
];
339-
340-
return functionCallingModels.some(modelType =>
341-
model.id.toLowerCase().includes(modelType) ||
342-
model.name?.toLowerCase().includes(modelType)
343-
);
340+
// Since we now fetch models with supported_parameters=tools filter,
341+
// all returned models support function calling
342+
return true;
344343
}
345344

346345
/**

0 commit comments

Comments
 (0)