Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions tests/contrib/openai_agents/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,16 @@
from tests.helpers import new_worker
from tests.helpers.nexus import create_nexus_endpoint, make_nexus_endpoint_name

response_index: int = 0


class StaticTestModel(TestModel):
__test__ = False
responses: list[ModelResponse] = []

def response(self):
global response_index
response = self.responses[response_index]
response_index += 1
return response

def __init__(
self,
) -> None:
global response_index
response_index = 0
super().__init__(self.response)
self._responses = iter(self.responses)
super().__init__(lambda: next(self._responses))


class TestHelloModel(StaticTestModel):
Expand Down Expand Up @@ -1342,9 +1333,6 @@ async def test_customer_service_workflow(client: Client, use_local_model: bool):
)


guardrail_response_index: int = 0


class InputGuardrailModel(OpenAIResponsesModel):
__test__ = False
responses: list[ModelResponse] = [
Expand Down Expand Up @@ -1433,11 +1421,9 @@ def __init__(
model: str,
openai_client: AsyncOpenAI,
) -> None:
global response_index
response_index = 0
global guardrail_response_index
guardrail_response_index = 0
super().__init__(model, openai_client)
self._responses = iter(self.responses)
self._guardrail_responses = iter(self.guardrail_responses)

async def get_response(
self,
Expand All @@ -1455,15 +1441,9 @@ async def get_response(
system_instructions
== "Check if the user is asking you to do their math homework."
):
global guardrail_response_index
response = self.guardrail_responses[guardrail_response_index]
guardrail_response_index += 1
return response
return next(self._guardrail_responses)
else:
global response_index
response = self.responses[response_index]
response_index += 1
return response
return next(self._responses)


### 1. An agent-based guardrail that is triggered if the user is asking to do math homework
Expand Down