AndyC commited on
Commit
c8f1234
·
1 Parent(s): 707a100

added tests for prompt selection

Browse files
Files changed (1) hide show
  1. tests/test_media.py +158 -2
tests/test_media.py CHANGED
@@ -5,7 +5,7 @@ from PIL import Image
5
  from pathlib import Path
6
  import tempfile
7
 
8
- from app import get_frames, process_video, process_user_input, process_history, extract_pdf_text
9
 
10
  # Get the project root directory
11
  ROOT_DIR = Path(__file__).parent.parent
@@ -542,4 +542,160 @@ def test_process_history_with_pdf():
542
  finally:
543
  # Clean up
544
  if os.path.exists(pdf_path):
545
- os.unlink(pdf_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  from pathlib import Path
6
  import tempfile
7
 
8
+ from app import get_frames, process_video, process_user_input, process_history, extract_pdf_text, update_custom_prompt
9
 
10
  # Get the project root directory
11
  ROOT_DIR = Path(__file__).parent.parent
 
542
  finally:
543
  # Clean up
544
  if os.path.exists(pdf_path):
545
+ os.unlink(pdf_path)
546
+
547
+
548
+ def test_update_custom_prompt_general_assistant():
549
+ """Test that selecting 'General Assistant' returns the correct prompt."""
550
+ result = update_custom_prompt("General Assistant")
551
+ expected = "You are a helpful AI assistant capable of analyzing images, videos, and PDF documents. Provide clear, accurate, and helpful responses to user queries."
552
+ assert result == expected
553
+
554
+
555
+ def test_update_custom_prompt_document_analyzer():
556
+ """Test that selecting 'Document Analyzer' returns the correct prompt."""
557
+ result = update_custom_prompt("Document Analyzer")
558
+ expected = "You are a specialized document analysis assistant. Focus on extracting key information, summarizing content, and answering specific questions about uploaded documents. For PDFs, provide structured analysis including main topics, key points, and relevant details. For images containing text, perform OCR-like analysis."
559
+ assert result == expected
560
+
561
+
562
+ def test_update_custom_prompt_visual_content_expert():
563
+ """Test that selecting 'Visual Content Expert' returns the correct prompt."""
564
+ result = update_custom_prompt("Visual Content Expert")
565
+ expected = "You are an expert in visual content analysis. When analyzing images, provide detailed descriptions of visual elements, composition, colors, objects, people, and scenes. For videos, describe the sequence of events, movements, and changes between frames. Identify artistic techniques, styles, and visual storytelling elements."
566
+ assert result == expected
567
+
568
+
569
+ def test_update_custom_prompt_educational_tutor():
570
+ """Test that selecting 'Educational Tutor' returns the correct prompt."""
571
+ result = update_custom_prompt("Educational Tutor")
572
+ expected = "You are a patient and encouraging educational tutor. Break down complex concepts into simple, understandable explanations. When analyzing educational materials (images, videos, or documents), focus on learning objectives, key concepts, and provide additional context or examples to enhance understanding."
573
+ assert result == expected
574
+
575
+
576
+ def test_update_custom_prompt_technical_reviewer():
577
+ """Test that selecting 'Technical Reviewer' returns the correct prompt."""
578
+ result = update_custom_prompt("Technical Reviewer")
579
+ expected = "You are a technical expert specializing in analyzing technical documents, diagrams, code screenshots, and instructional videos. Provide detailed technical insights, identify potential issues, suggest improvements, and explain technical concepts with precision and accuracy."
580
+ assert result == expected
581
+
582
+
583
+ def test_update_custom_prompt_creative_storyteller():
584
+ """Test that selecting 'Creative Storyteller' returns the correct prompt."""
585
+ result = update_custom_prompt("Creative Storyteller")
586
+ expected = "You are a creative storyteller who brings visual content to life through engaging narratives. When analyzing images or videos, create compelling stories, describe scenes with rich detail, and help users explore the creative and emotional aspects of visual content."
587
+ assert result == expected
588
+
589
+
590
+ def test_update_custom_prompt_custom():
591
+ """Test that selecting 'Custom' returns an empty string."""
592
+ result = update_custom_prompt("Custom")
593
+ assert result == ""
594
+
595
+
596
+ def test_update_custom_prompt_invalid_choice():
597
+ """Test that an invalid choice returns an empty string."""
598
+ result = update_custom_prompt("NonExistentChoice")
599
+ assert result == ""
600
+
601
+
602
+ def test_update_custom_prompt_case_sensitivity():
603
+ """Test that the function is case-sensitive."""
604
+ # Should not match lowercase
605
+ result = update_custom_prompt("general assistant")
606
+ assert result == ""
607
+
608
+ # Should match exact case
609
+ result = update_custom_prompt("General Assistant")
610
+ assert result != ""
611
+
612
+
613
+ def test_system_prompt_selection_logic():
614
+ """Test the system prompt selection logic from the run function."""
615
+ # Mock the preset prompts dictionary (same as in the run function)
616
+ preset_prompts = {
617
+ "General Assistant": "You are a helpful AI assistant capable of analyzing images, videos, and PDF documents. Provide clear, accurate, and helpful responses to user queries.",
618
+ "Document Analyzer": "You are a specialized document analysis assistant. Focus on extracting key information, summarizing content, and answering specific questions about uploaded documents. For PDFs, provide structured analysis including main topics, key points, and relevant details. For images containing text, perform OCR-like analysis.",
619
+ "Visual Content Expert": "You are an expert in visual content analysis. When analyzing images, provide detailed descriptions of visual elements, composition, colors, objects, people, and scenes. For videos, describe the sequence of events, movements, and changes between frames. Identify artistic techniques, styles, and visual storytelling elements.",
620
+ "Educational Tutor": "You are a patient and encouraging educational tutor. Break down complex concepts into simple, understandable explanations. When analyzing educational materials (images, videos, or documents), focus on learning objectives, key concepts, and provide additional context or examples to enhance understanding.",
621
+ "Technical Reviewer": "You are a technical expert specializing in analyzing technical documents, diagrams, code screenshots, and instructional videos. Provide detailed technical insights, identify potential issues, suggest improvements, and explain technical concepts with precision and accuracy.",
622
+ "Creative Storyteller": "You are a creative storyteller who brings visual content to life through engaging narratives. When analyzing images or videos, create compelling stories, describe scenes with rich detail, and help users explore the creative and emotional aspects of visual content.",
623
+ }
624
+
625
+ # Test preset selection
626
+ for preset_name, expected_prompt in preset_prompts.items():
627
+ custom_prompt = "This is a custom prompt"
628
+
629
+ # When preset is selected (not "Custom"), should use preset
630
+ if preset_name != "Custom":
631
+ selected_prompt = preset_prompts.get(preset_name, custom_prompt)
632
+ assert selected_prompt == expected_prompt
633
+ assert selected_prompt != custom_prompt
634
+
635
+ # Test custom selection
636
+ custom_prompt = "This is my custom system prompt"
637
+ system_prompt_preset = "Custom"
638
+
639
+ if system_prompt_preset == "Custom":
640
+ selected_prompt = custom_prompt
641
+ else:
642
+ selected_prompt = preset_prompts.get(system_prompt_preset, custom_prompt)
643
+
644
+ assert selected_prompt == custom_prompt
645
+
646
+
647
+ def test_system_prompt_preset_choices():
648
+ """Test that all expected preset choices are available."""
649
+ expected_choices = [
650
+ "General Assistant",
651
+ "Document Analyzer",
652
+ "Visual Content Expert",
653
+ "Educational Tutor",
654
+ "Technical Reviewer",
655
+ "Creative Storyteller",
656
+ "Custom"
657
+ ]
658
+
659
+ # Verify all choices exist in update_custom_prompt function
660
+ for choice in expected_choices[:-1]: # Exclude "Custom" as it returns empty string
661
+ result = update_custom_prompt(choice)
662
+ assert isinstance(result, str)
663
+ assert len(result) > 0 # Should return a non-empty prompt
664
+
665
+ # Test Custom specifically
666
+ custom_result = update_custom_prompt("Custom")
667
+ assert custom_result == ""
668
+
669
+
670
+ def test_system_prompt_content_quality():
671
+ """Test that system prompts contain expected keywords for their specialization."""
672
+
673
+ # General Assistant should mention general capabilities
674
+ general = update_custom_prompt("General Assistant")
675
+ assert "images" in general.lower()
676
+ assert "videos" in general.lower()
677
+ assert "pdf" in general.lower()
678
+
679
+ # Document Analyzer should focus on document analysis
680
+ document = update_custom_prompt("Document Analyzer")
681
+ assert "document" in document.lower()
682
+ assert "analysis" in document.lower()
683
+ assert "pdf" in document.lower()
684
+
685
+ # Visual Content Expert should focus on visual analysis
686
+ visual = update_custom_prompt("Visual Content Expert")
687
+ assert "visual" in visual.lower()
688
+ assert "images" in visual.lower()
689
+ assert "videos" in visual.lower()
690
+
691
+ # Educational Tutor should mention teaching/learning
692
+ educational = update_custom_prompt("Educational Tutor")
693
+ assert any(word in educational.lower() for word in ["educational", "tutor", "learning", "teaching", "concepts"])
694
+
695
+ # Technical Reviewer should mention technical aspects
696
+ technical = update_custom_prompt("Technical Reviewer")
697
+ assert "technical" in technical.lower()
698
+
699
+ # Creative Storyteller should mention creativity/stories
700
+ creative = update_custom_prompt("Creative Storyteller")
701
+ assert any(word in creative.lower() for word in ["creative", "story", "narrative", "storyteller"])