@@ -4,7 +4,7 @@ import { getAtlasAiProvider } from './providers/atlas/atlas-ai-provider';
44import { getDocsAiProvider } from './providers/docs/docs-ai-provider' ;
55import { getAiSdkProvider , models } from './providers/generic/ai-sdk-provider' ;
66import { Config , ConfigSchema } from './config' ;
7- import { CliContext , wrapAllFunctions , formatHelpCommands } from './helpers' ;
7+ import { CliContext , wrapAllFunctions } from './helpers' ;
88import chalk from 'chalk' ;
99
1010class AI {
@@ -29,22 +29,29 @@ class AI {
2929 this . config = new Config ( this . replConfig ) ;
3030
3131 // Set up provider change listener
32- this . config . on ( 'change' , ( event ) => {
32+ this . config . on ( 'change' , async ( event ) => {
3333 switch ( event . key ) {
3434 case 'provider' :
3535 this . ai = this . getProvider ( event . value as ConfigSchema [ 'provider' ] ) ;
3636 break ;
3737 case 'model' :
38- if ( Object . keys ( models ) . includes ( event . value as string ) ) {
38+ if ( ! Object . keys ( models ) . includes ( this . config . get ( 'provider' ) as keyof typeof models ) ) {
39+ if ( event . value == 'default' ) {
40+ return ;
41+ }
42+ await this . config . set ( 'model' , 'default' ) ;
43+ throw new Error ( `${ this . config . get ( 'provider' ) } does not support custom models` ) ;
44+ }
45+ try {
3946 this . ai = getAiSdkProvider (
4047 models [ this . config . get ( 'provider' ) as keyof typeof models ] (
4148 event . value as string ,
4249 ) ,
4350 this . cliContext ,
4451 this . config ,
4552 ) ;
46- } else {
47- throw new Error ( `Invalid model: ${ event . value } ` ) ;
53+ } catch ( error ) {
54+ throw new Error ( `Invalid model, please ensure your name is correct : ${ error } ` ) ;
4855 }
4956 break ;
5057 default :
0 commit comments