File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed
python/example-pytest-selfie/tests Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change 1- import random
21import os
3- import requests
4-
5- from selfie_lib import cache_selfie , cache_selfie_binary , cache_selfie_json
2+ import random
63
4+ import requests
75from openai import OpenAI
6+ from selfie_lib import cache_selfie , cache_selfie_binary , cache_selfie_json
87
98
109def test_cache_selfie ():
1110 cache_selfie (lambda : str (random .random ())).to_be ("0.06699295946441819" )
1211
1312
14- def test_gen_ai ():
15- # Initialize OpenAI API client
16- openai = OpenAI (api_key = os .environ .get ("OPENAI_API_KEY" ))
13+ def openai ():
14+ return OpenAI (api_key = os .environ .get ("OPENAI_API_KEY" ))
1715
16+
17+ def test_gen_ai ():
1818 # Fetch the chat response with caching
1919 chat = cache_selfie_json (
20- lambda : openai .chat .completions .create (
20+ lambda : openai ()
21+ .chat .completions .create (
2122 model = "gpt-4o" ,
2223 messages = [
2324 {
2425 "role" : "user" ,
2526 "content" : "Expressive but brief language describing a robot creating a self portrait." ,
2627 }
2728 ],
28- ).to_dict ()
29+ )
30+ .to_dict ()
2931 ).to_be ("""{
3032 "id": "chatcmpl-Af1Nf34netAfGW7ZIQArEHavfuYtg",
3133 "choices": [
@@ -62,9 +64,11 @@ def test_gen_ai():
6264}""" )
6365 # raise ValueError(f"KEYS={chat.keys()} TYPE={type(chat)}")
6466 image_url = cache_selfie_json (
65- lambda : openai .images .generate (
67+ lambda : openai ()
68+ .images .generate (
6669 model = "dall-e-3" , prompt = chat ["choices" ][0 ]["message" ]["content" ]
67- ).to_dict ()
70+ )
71+ .to_dict ()
6872 ).to_be ("""{
6973 "created": 1734340142,
7074 "data": [
You can’t perform that action at this time.
0 commit comments