@@ -19,7 +19,7 @@ use crate::openai::ChatClient;
1919pub struct Model {
2020 alias : String ,
2121 core : Arc < CoreInterop > ,
22- variants : Vec < ModelVariant > ,
22+ variants : Vec < Arc < ModelVariant > > ,
2323 selected_index : AtomicUsize ,
2424}
2525
@@ -57,7 +57,7 @@ impl Model {
5757
5858 /// Add a variant. If the new variant is cached and the current selection
5959 /// is not, the new variant becomes the selected one.
60- pub ( crate ) fn add_variant ( & mut self , variant : ModelVariant ) {
60+ pub ( crate ) fn add_variant ( & mut self , variant : Arc < ModelVariant > ) {
6161 self . variants . push ( variant) ;
6262 let new_idx = self . variants . len ( ) - 1 ;
6363 let current = self . selected_index . load ( Relaxed ) ;
@@ -70,17 +70,21 @@ impl Model {
7070
7171 /// Select a variant by its unique id.
7272 pub fn select_variant ( & self , id : & str ) -> Result < ( ) > {
73- if let Some ( pos) = self . variants . iter ( ) . position ( |v| v. id ( ) == id) {
74- self . selected_index . store ( pos, Relaxed ) ;
75- return Ok ( ( ) ) ;
73+ match self . variants . iter ( ) . position ( |v| v. id ( ) == id) {
74+ Some ( pos) => {
75+ self . selected_index . store ( pos, Relaxed ) ;
76+ Ok ( ( ) )
77+ }
78+ None => {
79+ let available: Vec < & str > = self . variants . iter ( ) . map ( |v| v. id ( ) ) . collect ( ) ;
80+ Err ( FoundryLocalError :: ModelOperation {
81+ reason : format ! (
82+ "Variant '{id}' not found for model '{}'. Available: {available:?}" ,
83+ self . alias
84+ ) ,
85+ } )
86+ }
7687 }
77- let available: Vec < String > = self . variants . iter ( ) . map ( |v| v. id ( ) . to_string ( ) ) . collect ( ) ;
78- Err ( FoundryLocalError :: ModelOperation {
79- reason : format ! (
80- "Variant '{id}' not found for model '{}'. Available: {available:?}" ,
81- self . alias
82- ) ,
83- } )
8488 }
8589
8690 /// Returns a reference to the currently selected variant.
@@ -89,7 +93,7 @@ impl Model {
8993 }
9094
9195 /// Returns all variants that belong to this model.
92- pub fn variants ( & self ) -> & [ ModelVariant ] {
96+ pub fn variants ( & self ) -> & [ Arc < ModelVariant > ] {
9397 & self . variants
9498 }
9599
@@ -169,11 +173,11 @@ impl Model {
169173
170174 /// Create a [`ChatClient`] bound to the selected variant.
171175 pub fn create_chat_client ( & self ) -> ChatClient {
172- ChatClient :: new ( self . id ( ) . to_string ( ) , Arc :: clone ( & self . core ) )
176+ ChatClient :: new ( self . id ( ) , Arc :: clone ( & self . core ) )
173177 }
174178
175179 /// Create an [`AudioClient`] bound to the selected variant.
176180 pub fn create_audio_client ( & self ) -> AudioClient {
177- AudioClient :: new ( self . id ( ) . to_string ( ) , Arc :: clone ( & self . core ) )
181+ AudioClient :: new ( self . id ( ) , Arc :: clone ( & self . core ) )
178182 }
179183}
0 commit comments