Skip to content

Commit 29599e5

Browse files
authored
Adding an end to end test which uses an openai service account (#922)
* Adding an end to end test which uses an openai service account * Lint * Add trace intercepter * Include data converter
1 parent dac2eb2 commit 29599e5

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ jobs:
7979
- if: ${{ !endsWith(matrix.os, '-arm') }}
8080
run: poe test ${{matrix.pytestExtraArgs}} -s --workflow-environment time-skipping --junit-xml=junit-xml/${{ matrix.python }}--${{ matrix.os }}--time-skipping.xml
8181
timeout-minutes: 10
82+
env:
83+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
8284
# Check cloud if proper target and not on fork
8385
- if: ${{ matrix.cloudTestTarget && (github.event.pull_request.head.repo.full_name == '' || github.event.pull_request.head.repo.full_name == 'temporalio/sdk-python') }}
8486
run: poe test ${{matrix.pytestExtraArgs}} -s -k test_cloud_client --junit-xml=junit-xml/${{ matrix.python }}--${{ matrix.os }}--cloud.xml

tests/contrib/test_openai.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23
import uuid
34
from dataclasses import dataclass
@@ -19,6 +20,9 @@
1920
set_open_ai_agent_temporal_overrides,
2021
)
2122
from temporalio.contrib.openai_agents.temporal_tools import activity_as_tool
23+
from temporalio.contrib.openai_agents.trace_interceptor import (
24+
OpenAIAgentsTracingInterceptor,
25+
)
2226
from tests.helpers import new_worker
2327

2428
with workflow.unsafe.imports_passed_through():
@@ -167,6 +171,32 @@ async def test_hello_world_agent(client: Client):
167171
assert result == "test"
168172

169173

174+
async def test_end_to_end(client: Client):
175+
if "OPENAI_API_KEY" not in os.environ:
176+
pytest.skip("No openai API key")
177+
178+
new_config = client.config()
179+
new_config["data_converter"] = open_ai_data_converter
180+
client = Client(**new_config)
181+
182+
model_params = ModelActivityParameters(start_to_close_timeout=timedelta(seconds=10))
183+
with set_open_ai_agent_temporal_overrides(model_params):
184+
async with new_worker(
185+
client,
186+
HelloWorldAgent,
187+
activities=[ModelActivity().invoke_model_activity],
188+
interceptors=[OpenAIAgentsTracingInterceptor()],
189+
) as worker:
190+
result = await client.execute_workflow(
191+
HelloWorldAgent.run,
192+
"Tell me about recursion in programming. Include the word 'function'",
193+
id=f"hello-workflow-{uuid.uuid4()}",
194+
task_queue=worker.task_queue,
195+
execution_timeout=timedelta(seconds=30),
196+
)
197+
assert "function" in result.lower()
198+
199+
170200
@dataclass
171201
class Weather:
172202
city: str
@@ -225,7 +255,7 @@ class ToolsWorkflow:
225255
@workflow.run
226256
async def run(self, question: str) -> str:
227257
agent = Agent(
228-
name="Hello world",
258+
name="Tools Workflow",
229259
instructions="You are a helpful agent.",
230260
tools=[
231261
activity_as_tool(
@@ -255,6 +285,7 @@ async def test_tool_workflow(client: Client):
255285
client,
256286
ToolsWorkflow,
257287
activities=[model_activity.invoke_model_activity, get_weather],
288+
interceptors=[OpenAIAgentsTracingInterceptor()],
258289
) as worker:
259290
workflow_handle = await client.start_workflow(
260291
ToolsWorkflow.run,
@@ -476,6 +507,7 @@ async def test_research_workflow(client: Client):
476507
client,
477508
ResearchWorkflow,
478509
activities=[model_activity.invoke_model_activity, get_weather],
510+
interceptors=[OpenAIAgentsTracingInterceptor()],
479511
) as worker:
480512
workflow_handle = await client.start_workflow(
481513
ResearchWorkflow.run,
@@ -686,6 +718,7 @@ async def test_agents_as_tools_workflow(client: Client):
686718
client,
687719
AgentsAsToolsWorkflow,
688720
activities=[model_activity.invoke_model_activity],
721+
interceptors=[OpenAIAgentsTracingInterceptor()],
689722
) as worker:
690723
workflow_handle = await client.start_workflow(
691724
AgentsAsToolsWorkflow.run,
@@ -1043,6 +1076,7 @@ async def test_customer_service_workflow(client: Client):
10431076
client,
10441077
CustomerServiceWorkflow,
10451078
activities=[model_activity.invoke_model_activity],
1079+
interceptors=[OpenAIAgentsTracingInterceptor()],
10461080
) as worker:
10471081
workflow_handle = await client.start_workflow(
10481082
CustomerServiceWorkflow.run,

0 commit comments

Comments
 (0)