@@ -59,7 +59,7 @@ import CloseIcon from '@mui/icons-material/Close';
5959import SyntaxHighlighter from 'react-syntax-highlighter' ;
6060import { docco , dracula } from 'react-syntax-highlighter/dist/esm/styles/hljs' ;
6161import NodeVisualization from './NodeVisualization' ;
62- import api , { getAvailableModels } from '../services/api' ;
62+ import api , { getAvailableModels , getFreeModels } from '../services/api' ;
6363import axios from 'axios' ;
6464import Fuse from 'fuse.js' ;
6565import { loadSuggestions } from '../utils/loadSuggestions' ;
@@ -149,6 +149,7 @@ function ChatLayout({
149149 const [ apiKeysStatus , setApiKeysStatus ] = useState ( { } ) ;
150150 const [ apiKeysLoaded , setApiKeysLoaded ] = useState ( false ) ;
151151 const [ modelChoices , setModelChoices ] = useState ( { } ) ;
152+ const [ freeModels , setFreeModels ] = useState ( [ ] ) ;
152153 const [ modelsLoaded , setModelsLoaded ] = useState ( false ) ;
153154
154155 // Expanded sections in right panel
@@ -247,10 +248,13 @@ function ChatLayout({
247248 try {
248249 const models = await getAvailableModels ( ) ;
249250 setModelChoices ( models ) ;
251+ const freeModelNames = await getFreeModels ( ) ;
252+ setFreeModels ( freeModelNames ) ;
250253 setModelsLoaded ( true ) ;
251254 } catch ( error ) {
252- console . error ( 'Error fetching available models:' , error ) ;
255+ console . error ( 'Error fetching available/free models:' , error ) ;
253256 setModelChoices ( { } ) ;
257+ setFreeModels ( [ ] ) ;
254258 setModelsLoaded ( true ) ;
255259 }
256260 } ;
@@ -265,9 +269,6 @@ function ChatLayout({
265269 if ( response . data ) {
266270 setApiKeysStatus ( response . data ) ;
267271 setApiKeysLoaded ( true ) ;
268- if ( provider && response . data [ provider ] ) {
269- setApiKey ( 'env' ) ;
270- }
271272 }
272273 } catch ( error ) {
273274 console . error ( 'Error fetching API keys status:' , error ) ;
@@ -276,16 +277,17 @@ function ChatLayout({
276277 fetchApiKeysStatus ( ) ;
277278 } , [ provider , setApiKey ] ) ;
278279
279- // When provider changes, update API key
280+ // When provider/model changes, default to server key only for free models
280281 useEffect ( ( ) => {
281282 if ( apiKeysLoaded && provider ) {
282- if ( apiKeysStatus [ provider ] ) {
283+ const selectedModelIsFree = ! ! llmType && freeModels . includes ( llmType ) ;
284+ if ( apiKeysStatus [ provider ] && selectedModelIsFree ) {
283285 setApiKey ( 'env' ) ;
284- } else {
286+ } else if ( apiKey === 'env' ) {
285287 setApiKey ( '' ) ;
286288 }
287289 }
288- } , [ provider , apiKeysStatus , apiKeysLoaded , setApiKey ] ) ;
290+ } , [ provider , llmType , freeModels , apiKeysStatus , apiKeysLoaded , apiKey , setApiKey ] ) ;
289291
290292 // Scroll to bottom when messages update
291293 useEffect ( ( ) => {
@@ -494,9 +496,11 @@ function ChatLayout({
494496 const isSettingsValid = useCallback ( ( ) => {
495497 if ( ! provider ) return false ;
496498 if ( ! llmType ) return false ;
497- if ( ! apiKeysStatus [ provider ] && ! apiKey ) return false ;
499+ const selectedModelIsFree = freeModels . includes ( llmType ) ;
500+ const canUseServerKeyForSelection = apiKeysStatus [ provider ] && selectedModelIsFree ;
501+ if ( ! canUseServerKeyForSelection && ! apiKey ) return false ;
498502 return true ;
499- } , [ provider , llmType , apiKeysStatus , apiKey ] ) ;
503+ } , [ provider , llmType , apiKeysStatus , freeModels , apiKey ] ) ;
500504
501505 // Check if semantic search settings are valid (only when enabled)
502506 const isSemanticSearchValid = useCallback ( ( ) => {
@@ -550,7 +554,9 @@ function ChatLayout({
550554 abortControllerRef . current = new AbortController ( ) ;
551555 const signal = abortControllerRef . current . signal ;
552556
553- const effectiveApiKey = ( apiKeysStatus [ provider ] && apiKey === 'env' ) ? 'env' : apiKey ;
557+ const selectedModelIsFree = freeModels . includes ( llmType ) ;
558+ const canUseServerKeyForSelection = apiKeysStatus [ provider ] && selectedModelIsFree ;
559+ const effectiveApiKey = ( canUseServerKeyForSelection && ( apiKey === 'env' || ! apiKey ) ) ? 'env' : apiKey ;
554560
555561 try {
556562 // Build request data
@@ -636,7 +642,9 @@ function ChatLayout({
636642 abortControllerRef . current = new AbortController ( ) ;
637643 const signal = abortControllerRef . current . signal ;
638644
639- const effectiveApiKey = ( apiKeysStatus [ provider ] && apiKey === 'env' ) ? 'env' : apiKey ;
645+ const selectedModelIsFree = freeModels . includes ( llmType ) ;
646+ const canUseServerKeyForSelection = apiKeysStatus [ provider ] && selectedModelIsFree ;
647+ const effectiveApiKey = ( canUseServerKeyForSelection && ( apiKey === 'env' || ! apiKey ) ) ? 'env' : apiKey ;
640648
641649 try {
642650 const runResponse = await api . post ( '/run_query/' , {
@@ -883,7 +891,9 @@ function ChatLayout({
883891 abortControllerRef . current = new AbortController ( ) ;
884892 const signal = abortControllerRef . current . signal ;
885893
886- const effectiveApiKey = ( apiKeysStatus [ provider ] && apiKey === 'env' ) ? 'env' : apiKey ;
894+ const selectedModelIsFree = freeModels . includes ( llmType ) ;
895+ const canUseServerKeyForSelection = apiKeysStatus [ provider ] && selectedModelIsFree ;
896+ const effectiveApiKey = ( canUseServerKeyForSelection && ( apiKey === 'env' || ! apiKey ) ) ? 'env' : apiKey ;
887897
888898 try {
889899 // Build request data
@@ -2230,6 +2240,7 @@ function ChatLayout({
22302240 return < MenuItem key = { `label-${ idx } ` } disabled sx = { { opacity : 0.7 , fontWeight : 'bold' , fontSize : '0.85rem' } } > { m . label } </ MenuItem > ;
22312241 }
22322242 const isSupported = supportedModels . includes ( m ) ;
2243+ const isFreeModel = freeModels . includes ( m ) ;
22332244 return (
22342245 < MenuItem
22352246 key = { m }
@@ -2256,15 +2267,15 @@ function ChatLayout({
22562267 fontWeight : 700 ,
22572268 } } > ★</ Box >
22582269 ) }
2259- { m }
2270+ { m } { isFreeModel ? ' (Free)' : '' }
22602271 </ MenuItem >
22612272 ) ;
22622273 } ) }
22632274 </ Select >
22642275 </ FormControl >
22652276
22662277 { /* API Key Section */ }
2267- { apiKeysLoaded && apiKeysStatus [ provider ] ? (
2278+ { apiKeysLoaded && apiKeysStatus [ provider ] && freeModels . includes ( llmType ) ? (
22682279 < Paper
22692280 variant = "outlined"
22702281 sx = { {
0 commit comments