2020import { createId as cuid2 } from '@paralleldrive/cuid2' ;
2121import { PassThrough } from 'stream' ;
2222import { APIError } from '../../../api/APIError.js' ;
23+ import { redisClient } from '../../../clients/redis/redisSingleton.js' ;
2324import { ErrorService } from '../../../modules/core/ErrorService.js' ;
2425import { Context } from '../../../util/context.js' ;
2526import BaseService from '../../BaseService.js' ;
@@ -45,7 +46,6 @@ import { OpenRouterProvider } from './providers/OpenRouterProvider/OpenRouterPro
4546import { TogetherAIProvider } from './providers/TogetherAiProvider/TogetherAIProvider.js' ;
4647import { IChatModel , IChatProvider , ICompleteArguments } from './providers/types.js' ;
4748import { XAIProvider } from './providers/XAIProvider/XAIProvider.js' ;
48- import { redisClient } from '../../../clients/redis/redisSingleton.js' ;
4949
5050// Maximum number of fallback attempts when a model fails, including the first attempt
5151const MAX_FALLBACKS = 3 + 1 ; // includes first attempt
@@ -150,14 +150,14 @@ export class AIChatService extends BaseService {
150150 if ( xaiConfig && xaiConfig . apiKey ) {
151151 this . #providers[ 'xai' ] = new XAIProvider ( xaiConfig , this . meteringService ) ;
152152 }
153- const togetherConfig = this . config . providers ?. [ 'together-ai' ] || this . global_config ?. services ?. [ 'together-ai' ] ;
154- if ( togetherConfig && togetherConfig . apiKey ) {
155- this . #providers[ 'together-ai' ] = new TogetherAIProvider ( togetherConfig , this . meteringService ) ;
156- }
157153 const openrouterConfig = this . config . providers ?. [ 'openrouter' ] || this . global_config ?. services ?. [ 'openrouter' ] ;
158154 if ( openrouterConfig && openrouterConfig . apiKey ) {
159155 this . #providers[ 'openrouter' ] = new OpenRouterProvider ( openrouterConfig , this . meteringService ) ;
160156 }
157+ const togetherConfig = this . config . providers ?. [ 'together-ai' ] || this . global_config ?. services ?. [ 'together-ai' ] ;
158+ if ( togetherConfig && togetherConfig . apiKey ) {
159+ this . #providers[ 'together-ai' ] = new TogetherAIProvider ( togetherConfig , this . meteringService ) ;
160+ }
161161
162162 // ollama if local instance detected
163163
@@ -221,6 +221,23 @@ export class AIChatService extends BaseService {
221221 model . aliases = [ model . puterId ] ;
222222 }
223223 }
224+
225+ let exists = false ;
226+ if ( model . aliases ) {
227+ for ( let alias of model . aliases ) {
228+ if ( this . #modelIdMap[ alias ] && this . #modelIdMap[ alias ] !== this . #modelIdMap[ model . id ] ) {
229+ if ( providerName === 'together-ai' || providerName === 'openrouter' ) {
230+ delete this . #modelIdMap[ model . id ] ;
231+ exists = true ;
232+ break ;
233+ }
234+ }
235+ }
236+ }
237+ if ( exists ) {
238+ continue ;
239+ }
240+
224241 if ( model . aliases ) {
225242 for ( let alias of model . aliases ) {
226243 alias = alias . trim ( ) . toLowerCase ( ) ;
@@ -674,7 +691,7 @@ export class AIChatService extends BaseService {
674691 if ( targetModel . id . startsWith ( 'openrouter:' ) || targetModel . id . startsWith ( 'togetherai:' ) ) {
675692 [ aiProvider , modelToSearch ] = targetModel . id . replace ( 'openrouter:' , '' ) . replace ( 'togetherai:' , '' ) . toLowerCase ( ) . split ( '/' ) ;
676693 } else {
677- [ aiProvider , modelToSearch ] = targetModel . provider ! . toLowerCase ( ) . replace ( 'gemini' , 'google' ) . replace ( 'openai-completion' , 'openai' ) . replace ( 'openai-responses' , 'openai' ) , targetModel . id . toLowerCase ( ) ;
694+ [ aiProvider , modelToSearch ] = [ targetModel . provider ! . toLowerCase ( ) . replace ( 'gemini' , 'google' ) . replace ( 'openai-completion' , 'openai' ) . replace ( 'openai-responses' , 'openai' ) , targetModel . id . toLowerCase ( ) ] ;
678695 }
679696
680697 const potentialMatches = models . filter ( model => {
0 commit comments