File tree 1 file changed +15
-11
lines changed
python/example-pytest-selfie/tests
1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change 1
- import random
2
1
import os
3
- import requests
4
-
5
- from selfie_lib import cache_selfie , cache_selfie_binary , cache_selfie_json
2
+ import random
6
3
4
+ import requests
7
5
from openai import OpenAI
6
+ from selfie_lib import cache_selfie , cache_selfie_binary , cache_selfie_json
8
7
9
8
10
9
def test_cache_selfie ():
11
10
cache_selfie (lambda : str (random .random ())).to_be ("0.06699295946441819" )
12
11
13
12
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" ))
17
15
16
+
17
+ def test_gen_ai ():
18
18
# Fetch the chat response with caching
19
19
chat = cache_selfie_json (
20
- lambda : openai .chat .completions .create (
20
+ lambda : openai ()
21
+ .chat .completions .create (
21
22
model = "gpt-4o" ,
22
23
messages = [
23
24
{
24
25
"role" : "user" ,
25
26
"content" : "Expressive but brief language describing a robot creating a self portrait." ,
26
27
}
27
28
],
28
- ).to_dict ()
29
+ )
30
+ .to_dict ()
29
31
).to_be ("""{
30
32
"id": "chatcmpl-Af1Nf34netAfGW7ZIQArEHavfuYtg",
31
33
"choices": [
@@ -62,9 +64,11 @@ def test_gen_ai():
62
64
}""" )
63
65
# raise ValueError(f"KEYS={chat.keys()} TYPE={type(chat)}")
64
66
image_url = cache_selfie_json (
65
- lambda : openai .images .generate (
67
+ lambda : openai ()
68
+ .images .generate (
66
69
model = "dall-e-3" , prompt = chat ["choices" ][0 ]["message" ]["content" ]
67
- ).to_dict ()
70
+ )
71
+ .to_dict ()
68
72
).to_be ("""{
69
73
"created": 1734340142,
70
74
"data": [
You can’t perform that action at this time.
0 commit comments