forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_logprobs.py
More file actions
50 lines (41 loc) · 1.48 KB
/
Copy pathtest_logprobs.py
File metadata and controls
50 lines (41 loc) · 1.48 KB
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
import pytest
from openai.types.responses.response_usage import InputTokensDetails, OutputTokensDetails
from agents import ModelSettings, ModelTracing, OpenAIResponsesModel
class DummyResponses:
async def create(self, **kwargs):
self.kwargs = kwargs
class DummyResponse:
id = "dummy"
output = []
usage = type(
"Usage",
(),
{
"input_tokens": 0,
"output_tokens": 0,
"total_tokens": 0,
"input_tokens_details": InputTokensDetails(cached_tokens=0),
"output_tokens_details": OutputTokensDetails(reasoning_tokens=0),
},
)()
return DummyResponse()
class DummyClient:
def __init__(self):
self.responses = DummyResponses()
@pytest.mark.allow_call_model_methods
@pytest.mark.asyncio
async def test_top_logprobs_param_passed():
client = DummyClient()
model = OpenAIResponsesModel(model="gpt-4", openai_client=client) # type: ignore
await model.get_response(
system_instructions=None,
input="hi",
model_settings=ModelSettings(top_logprobs=2),
tools=[],
output_schema=None,
handoffs=[],
tracing=ModelTracing.DISABLED,
previous_response_id=None,
)
assert client.responses.kwargs["top_logprobs"] == 2
assert "message.output_text.logprobs" in client.responses.kwargs["include"]