1717from adalflow .core import Generator
1818from adalflow .components .model_client .openai_client import OpenAIClient
1919from adalflow .core .types import ModelType
20- import asyncio
21- import numpy as np
22- from dataclasses import dataclass
23- from typing import List
24- from numpy .linalg import norm
20+
2521
2622def test_basic_generation ():
2723 """Test basic text generation"""
2824 client = OpenAIClient () # Default model_type is LLM
2925 gen = Generator (
30- model_client = client ,
31- model_kwargs = {
32- "model" : "gpt-4o-mini" ,
33- "max_tokens" : 100
34- }
26+ model_client = client , model_kwargs = {"model" : "gpt-4o-mini" , "max_tokens" : 100 }
3527 )
36-
28+
3729 print ("\n === Testing Basic Generation ===" )
3830 response = gen ({"input_str" : "Hello, world!" })
3931 print (f"Response: { response } " )
4032
33+
4134def test_invalid_image_url ():
4235 """Test Generator output with invalid image URL"""
4336 client = OpenAIClient () # Default model_type is LLM
@@ -46,14 +39,15 @@ def test_invalid_image_url():
4639 model_kwargs = {
4740 "model" : "gpt-4o-mini" ,
4841 "images" : "https://invalid.url/nonexistent.jpg" ,
49- "max_tokens" : 300
50- }
42+ "max_tokens" : 300 ,
43+ },
5144 )
52-
45+
5346 print ("\n === Testing Invalid Image URL ===" )
5447 response = gen ({"input_str" : "What do you see in this image?" })
5548 print (f"Response with invalid image URL: { response } " )
5649
50+
5751def test_invalid_image_generation ():
5852 """Test DALL-E generation with invalid parameters"""
5953 client = OpenAIClient (model_type = ModelType .IMAGE_GENERATION )
@@ -63,14 +57,15 @@ def test_invalid_image_generation():
6357 "model" : "dall-e-3" ,
6458 "size" : "invalid_size" , # Invalid size parameter
6559 "quality" : "standard" ,
66- "n" : 1
67- }
60+ "n" : 1 ,
61+ },
6862 )
69-
63+
7064 print ("\n === Testing Invalid DALL-E Parameters ===" )
7165 response = gen ({"input_str" : "A cat" })
7266 print (f"Response with invalid DALL-E parameters: { response } " )
7367
68+
7469def test_vision_and_generation ():
7570 """Test both vision analysis and image generation"""
7671 # 1. Test Vision Analysis with LLM client
@@ -80,11 +75,13 @@ def test_vision_and_generation():
8075 model_kwargs = {
8176 "model" : "gpt-4o-mini" ,
8277 "images" : "https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png" ,
83- "max_tokens" : 300
84- }
78+ "max_tokens" : 300 ,
79+ },
80+ )
81+
82+ vision_response = vision_gen (
83+ {"input_str" : "What do you see in this image? Be detailed but concise." }
8584 )
86-
87- vision_response = vision_gen ({"input_str" : "What do you see in this image? Be detailed but concise." })
8885 print ("\n === Vision Analysis ===" )
8986 print (f"Description: { vision_response .raw_response } " )
9087
@@ -96,20 +93,23 @@ def test_vision_and_generation():
9693 "model" : "dall-e-3" ,
9794 "size" : "1024x1024" ,
9895 "quality" : "standard" ,
99- "n" : 1
100- }
96+ "n" : 1 ,
97+ },
10198 )
102-
99+
103100 # For image generation, input_str becomes the prompt
104- response = dalle_gen ({"input_str" : "A happy siamese cat playing with a red ball of yarn" })
101+ response = dalle_gen (
102+ {"input_str" : "A happy siamese cat playing with a red ball of yarn" }
103+ )
105104 print ("\n === DALL-E Generation ===" )
106105 print (f"Generated Image URL: { response .data } " )
107106
107+
108108if __name__ == "__main__" :
109109 print ("Starting OpenAI Vision and DALL-E test...\n " )
110-
110+
111111 # Run all tests - they will show errors if API key is invalid/empty
112112 test_basic_generation ()
113113 test_invalid_image_url ()
114114 test_invalid_image_generation ()
115- test_vision_and_generation ()
115+ test_vision_and_generation ()
0 commit comments