|
9 | 9 |
|
10 | 10 | import pytest
|
11 | 11 | from inline_snapshot import snapshot
|
12 |
| -from openai import AsyncOpenAI |
13 |
| -from openai.types import chat |
14 |
| -from openai.types.chat.chat_completion import Choice |
15 |
| -from openai.types.chat.chat_completion_chunk import ( |
16 |
| - Choice as ChunkChoice, |
17 |
| - ChoiceDelta, |
18 |
| - ChoiceDeltaToolCall, |
19 |
| - ChoiceDeltaToolCallFunction, |
20 |
| -) |
21 |
| -from openai.types.chat.chat_completion_message import ChatCompletionMessage |
22 |
| -from openai.types.chat.chat_completion_message_tool_call import Function |
23 |
| -from openai.types.completion_usage import CompletionUsage, PromptTokensDetails |
24 | 12 | from typing_extensions import TypedDict
|
25 | 13 |
|
26 | 14 | from pydantic_ai import Agent, ModelRetry, UnexpectedModelBehavior, _utils
|
|
34 | 22 | ToolReturn,
|
35 | 23 | UserPrompt,
|
36 | 24 | )
|
37 |
| -from pydantic_ai.models.openai import OpenAIModel |
38 | 25 | from pydantic_ai.result import Cost
|
39 |
| -from tests.conftest import IsNow |
| 26 | +from tests.conftest import IsNow, try_import |
| 27 | + |
| 28 | +with try_import() as imports_successful: |
| 29 | + from openai import AsyncOpenAI |
| 30 | + from openai.types import chat |
| 31 | + from openai.types.chat.chat_completion import Choice |
| 32 | + from openai.types.chat.chat_completion_chunk import ( |
| 33 | + Choice as ChunkChoice, |
| 34 | + ChoiceDelta, |
| 35 | + ChoiceDeltaToolCall, |
| 36 | + ChoiceDeltaToolCallFunction, |
| 37 | + ) |
| 38 | + from openai.types.chat.chat_completion_message import ChatCompletionMessage |
| 39 | + from openai.types.chat.chat_completion_message_tool_call import Function |
| 40 | + from openai.types.completion_usage import CompletionUsage, PromptTokensDetails |
| 41 | + |
| 42 | + from pydantic_ai.models.openai import OpenAIModel |
40 | 43 |
|
41 |
| -pytestmark = pytest.mark.anyio |
| 44 | +pytestmark = [ |
| 45 | + pytest.mark.skipif(not imports_successful(), reason='openai not installed'), |
| 46 | + pytest.mark.anyio, |
| 47 | +] |
42 | 48 |
|
43 | 49 |
|
44 | 50 | def test_init():
|
|
0 commit comments