forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_config.py
64 lines (46 loc) · 2.25 KB
/
test_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import openai
import pytest
from agents import set_default_openai_api, set_default_openai_client, set_default_openai_key
from agents.models.openai_chatcompletions import OpenAIChatCompletionsModel
from agents.models.openai_provider import OpenAIProvider
from agents.models.openai_responses import OpenAIResponsesModel
def test_cc_no_default_key_errors(monkeypatch):
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
with pytest.raises(openai.OpenAIError):
OpenAIProvider(use_responses=False).get_model("gpt-4")
def test_cc_set_default_openai_key():
set_default_openai_key("test_key")
chat_model = OpenAIProvider(use_responses=False).get_model("gpt-4")
assert chat_model._client.api_key == "test_key" # type: ignore
def test_cc_set_default_openai_client():
client = openai.AsyncOpenAI(api_key="test_key")
set_default_openai_client(client)
chat_model = OpenAIProvider(use_responses=False).get_model("gpt-4")
assert chat_model._client.api_key == "test_key" # type: ignore
def test_resp_no_default_key_errors(monkeypatch):
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
assert os.getenv("OPENAI_API_KEY") is None
with pytest.raises(openai.OpenAIError):
OpenAIProvider(use_responses=True).get_model("gpt-4")
def test_resp_set_default_openai_key():
set_default_openai_key("test_key")
resp_model = OpenAIProvider(use_responses=True).get_model("gpt-4")
assert resp_model._client.api_key == "test_key" # type: ignore
def test_resp_set_default_openai_client():
client = openai.AsyncOpenAI(api_key="test_key")
set_default_openai_client(client)
resp_model = OpenAIProvider(use_responses=True).get_model("gpt-4")
assert resp_model._client.api_key == "test_key" # type: ignore
def test_set_default_openai_api():
assert isinstance(OpenAIProvider().get_model("gpt-4"), OpenAIResponsesModel), (
"Default should be responses"
)
set_default_openai_api("chat_completions")
assert isinstance(OpenAIProvider().get_model("gpt-4"), OpenAIChatCompletionsModel), (
"Should be chat completions model"
)
set_default_openai_api("responses")
assert isinstance(OpenAIProvider().get_model("gpt-4"), OpenAIResponsesModel), (
"Should be responses model"
)