@@ -321,229 +321,3 @@ impl std::fmt::Display for ModelCard {
321321 write ! ( f, "{}" , self . name( ) )
322322 }
323323}
324-
325- #[ cfg( test) ]
326- mod tests {
327- use super :: * ;
328-
329- #[ test]
330- fn test_model_card_new ( ) {
331- let card = ModelCard :: new ( "llama-3.1-8b" ) ;
332- assert_eq ! ( card. id, "llama-3.1-8b" ) ;
333- assert_eq ! ( card. model_type, ModelType :: LLM ) ;
334- assert ! ( card. provider. is_none( ) ) ; // Native by default
335- assert ! ( card. aliases. is_empty( ) ) ;
336- }
337-
338- #[ test]
339- fn test_model_card_builder ( ) {
340- let card = ModelCard :: new ( "meta-llama/Llama-3.1-8B-Instruct" )
341- . with_display_name ( "Llama 3.1 8B" )
342- . with_alias ( "llama-3.1-8b" )
343- . with_alias ( "llama3.1" )
344- . with_model_type ( ModelType :: VISION_LLM )
345- . with_context_length ( 128_000 )
346- . with_tokenizer_path ( "meta-llama/Llama-3.1-8B-Instruct" )
347- . with_reasoning_parser ( "deepseek" )
348- . with_tool_parser ( "llama" ) ;
349-
350- assert_eq ! ( card. name( ) , "Llama 3.1 8B" ) ;
351- assert_eq ! ( card. aliases. len( ) , 2 ) ;
352- assert ! ( card. supports_vision( ) ) ;
353- assert_eq ! ( card. context_length, Some ( 128_000 ) ) ;
354- assert_eq ! (
355- card. tokenizer_path. as_deref( ) ,
356- Some ( "meta-llama/Llama-3.1-8B-Instruct" )
357- ) ;
358- assert_eq ! ( card. reasoning_parser. as_deref( ) , Some ( "deepseek" ) ) ;
359- assert_eq ! ( card. tool_parser. as_deref( ) , Some ( "llama" ) ) ;
360- assert ! ( card. is_native( ) ) ; // No provider set
361- }
362-
363- #[ test]
364- fn test_model_card_with_provider ( ) {
365- let card = ModelCard :: new ( "gpt-4o" ) . with_provider ( ProviderType :: OpenAI ) ;
366-
367- assert ! ( card. has_external_provider( ) ) ;
368- assert ! ( !card. is_native( ) ) ;
369- assert_eq ! ( card. provider, Some ( ProviderType :: OpenAI ) ) ;
370- }
371-
372- #[ test]
373- fn test_model_card_matches ( ) {
374- let card = ModelCard :: new ( "gpt-4o" )
375- . with_alias ( "gpt-4o-2024-08-06" )
376- . with_alias ( "gpt-4-turbo" ) ;
377-
378- assert ! ( card. matches( "gpt-4o" ) ) ;
379- assert ! ( card. matches( "gpt-4o-2024-08-06" ) ) ;
380- assert ! ( card. matches( "gpt-4-turbo" ) ) ;
381- assert ! ( !card. matches( "gpt-3.5" ) ) ;
382- }
383-
384- #[ test]
385- fn test_model_card_supports_endpoint ( ) {
386- let llm = ModelCard :: new ( "llama" ) . with_model_type ( ModelType :: LLM ) ;
387- assert ! ( llm. supports_endpoint( Endpoint :: Chat ) ) ;
388- assert ! ( llm. supports_endpoint( Endpoint :: Completions ) ) ;
389- assert ! ( !llm. supports_endpoint( Endpoint :: Embeddings ) ) ;
390-
391- let embed = ModelCard :: new ( "bge" ) . with_model_type ( ModelType :: EMBED_MODEL ) ;
392- assert ! ( embed. supports_endpoint( Endpoint :: Embeddings ) ) ;
393- assert ! ( !embed. supports_endpoint( Endpoint :: Chat ) ) ;
394- }
395-
396- #[ test]
397- fn test_model_card_name_fallback ( ) {
398- let card_with_name = ModelCard :: new ( "model-id" ) . with_display_name ( "Display Name" ) ;
399- assert_eq ! ( card_with_name. name( ) , "Display Name" ) ;
400-
401- let card_without_name = ModelCard :: new ( "model-id" ) ;
402- assert_eq ! ( card_without_name. name( ) , "model-id" ) ;
403- }
404-
405- #[ test]
406- fn test_model_card_is_llm ( ) {
407- let llm = ModelCard :: new ( "llama" ) . with_model_type ( ModelType :: LLM ) ;
408- assert ! ( llm. is_llm( ) ) ;
409-
410- let embed = ModelCard :: new ( "bge" ) . with_model_type ( ModelType :: EMBED_MODEL ) ;
411- assert ! ( !embed. is_llm( ) ) ;
412- }
413-
414- #[ test]
415- fn test_model_card_default ( ) {
416- let card = ModelCard :: default ( ) ;
417- assert_eq ! ( card. id, "default" ) ;
418- assert_eq ! ( card. model_type, ModelType :: LLM ) ;
419- assert ! ( card. provider. is_none( ) ) ;
420- }
421-
422- #[ test]
423- fn test_model_card_serialization ( ) {
424- let card = ModelCard :: new ( "gpt-4o" )
425- . with_display_name ( "GPT-4o" )
426- . with_alias ( "gpt4o" )
427- . with_provider ( ProviderType :: OpenAI )
428- . with_context_length ( 128_000 ) ;
429-
430- let json = serde_json:: to_string ( & card) . unwrap ( ) ;
431- let deserialized: ModelCard = serde_json:: from_str ( & json) . unwrap ( ) ;
432-
433- assert_eq ! ( deserialized. id, "gpt-4o" ) ;
434- assert_eq ! ( deserialized. display_name, Some ( "GPT-4o" . to_string( ) ) ) ;
435- assert_eq ! ( deserialized. aliases, vec![ "gpt4o" ] ) ;
436- assert_eq ! ( deserialized. provider, Some ( ProviderType :: OpenAI ) ) ;
437- assert_eq ! ( deserialized. context_length, Some ( 128_000 ) ) ;
438- }
439-
440- #[ test]
441- fn test_model_card_serialization_native ( ) {
442- // Native model (no provider) should not include provider in JSON
443- let card = ModelCard :: new ( "llama-3.1" ) ;
444- let json = serde_json:: to_string ( & card) . unwrap ( ) ;
445-
446- // Provider should be omitted from JSON when None
447- assert ! ( !json. contains( "provider" ) ) ;
448-
449- let deserialized: ModelCard = serde_json:: from_str ( & json) . unwrap ( ) ;
450- assert ! ( deserialized. provider. is_none( ) ) ;
451- }
452-
453- #[ test]
454- fn test_model_card_display ( ) {
455- let card = ModelCard :: new ( "model-id" ) . with_display_name ( "Display Name" ) ;
456- assert_eq ! ( format!( "{}" , card) , "Display Name" ) ;
457- }
458-
459- // === ProviderType tests ===
460-
461- #[ test]
462- fn test_provider_type_as_str ( ) {
463- assert_eq ! ( ProviderType :: OpenAI . as_str( ) , "openai" ) ;
464- assert_eq ! ( ProviderType :: XAI . as_str( ) , "xai" ) ;
465- assert_eq ! ( ProviderType :: Anthropic . as_str( ) , "anthropic" ) ;
466- assert_eq ! ( ProviderType :: Gemini . as_str( ) , "gemini" ) ;
467- assert_eq ! (
468- ProviderType :: Custom ( "my-provider" . to_string( ) ) . as_str( ) ,
469- "my-provider"
470- ) ;
471- }
472-
473- #[ test]
474- fn test_provider_type_from_model_name ( ) {
475- // External providers
476- assert_eq ! (
477- ProviderType :: from_model_name( "grok-beta" ) ,
478- Some ( ProviderType :: XAI )
479- ) ;
480- assert_eq ! (
481- ProviderType :: from_model_name( "Grok-2" ) ,
482- Some ( ProviderType :: XAI )
483- ) ;
484- assert_eq ! (
485- ProviderType :: from_model_name( "gemini-pro" ) ,
486- Some ( ProviderType :: Gemini )
487- ) ;
488- assert_eq ! (
489- ProviderType :: from_model_name( "claude-3-opus" ) ,
490- Some ( ProviderType :: Anthropic )
491- ) ;
492- assert_eq ! (
493- ProviderType :: from_model_name( "gpt-4o" ) ,
494- Some ( ProviderType :: OpenAI )
495- ) ;
496- assert_eq ! (
497- ProviderType :: from_model_name( "o1-preview" ) ,
498- Some ( ProviderType :: OpenAI )
499- ) ;
500- assert_eq ! (
501- ProviderType :: from_model_name( "o3-mini" ) ,
502- Some ( ProviderType :: OpenAI )
503- ) ;
504-
505- // Native/local models - no provider
506- assert_eq ! ( ProviderType :: from_model_name( "llama-3.1" ) , None ) ;
507- assert_eq ! ( ProviderType :: from_model_name( "mistral-7b" ) , None ) ;
508- assert_eq ! ( ProviderType :: from_model_name( "deepseek-r1" ) , None ) ;
509- assert_eq ! ( ProviderType :: from_model_name( "qwen-2.5" ) , None ) ;
510- }
511-
512- #[ test]
513- fn test_provider_type_serialization ( ) {
514- // Test standard variants
515- let openai = ProviderType :: OpenAI ;
516- let json = serde_json:: to_string ( & openai) . unwrap ( ) ;
517- assert_eq ! ( json, "\" openai\" " ) ;
518- let deserialized: ProviderType = serde_json:: from_str ( & json) . unwrap ( ) ;
519- assert_eq ! ( deserialized, ProviderType :: OpenAI ) ;
520-
521- // Test custom variant
522- let custom = ProviderType :: Custom ( "my-provider" . to_string ( ) ) ;
523- let json = serde_json:: to_string ( & custom) . unwrap ( ) ;
524- let deserialized: ProviderType = serde_json:: from_str ( & json) . unwrap ( ) ;
525- assert_eq ! (
526- deserialized,
527- ProviderType :: Custom ( "my-provider" . to_string( ) )
528- ) ;
529- }
530-
531- #[ test]
532- fn test_provider_type_aliases ( ) {
533- // Test serde aliases
534- let xai: ProviderType = serde_json:: from_str ( "\" grok\" " ) . unwrap ( ) ;
535- assert_eq ! ( xai, ProviderType :: XAI ) ;
536-
537- let anthropic: ProviderType = serde_json:: from_str ( "\" claude\" " ) . unwrap ( ) ;
538- assert_eq ! ( anthropic, ProviderType :: Anthropic ) ;
539-
540- let gemini: ProviderType = serde_json:: from_str ( "\" google\" " ) . unwrap ( ) ;
541- assert_eq ! ( gemini, ProviderType :: Gemini ) ;
542- }
543-
544- #[ test]
545- fn test_provider_type_display ( ) {
546- assert_eq ! ( format!( "{}" , ProviderType :: OpenAI ) , "openai" ) ;
547- assert_eq ! ( format!( "{}" , ProviderType :: XAI ) , "xai" ) ;
548- }
549- }
0 commit comments