Home / File/ test_openai_assistant.py — langchain Source File

test_openai_assistant.py — langchain Source File

Architecture documentation for test_openai_assistant.py, a python file in the langchain codebase. 5 imports, 0 dependents.

File python LangChainCore Runnables 5 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  d76760d8_a189_0f15_aae7_cb699a67e504["test_openai_assistant.py"]
  f46e1812_79f8_1bd0_7815_2ba4471dc470["functools"]
  d76760d8_a189_0f15_aae7_cb699a67e504 --> f46e1812_79f8_1bd0_7815_2ba4471dc470
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  d76760d8_a189_0f15_aae7_cb699a67e504 --> feec1ec4_6917_867b_d228_b134d0ff8099
  23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"]
  d76760d8_a189_0f15_aae7_cb699a67e504 --> 23cb242e_1754_041d_200a_553fcb8abe1b
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  d76760d8_a189_0f15_aae7_cb699a67e504 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  cd3ac0d8_8844_f7fb_08a0_d7f6d81a0646["langchain_classic.agents.openai_assistant"]
  d76760d8_a189_0f15_aae7_cb699a67e504 --> cd3ac0d8_8844_f7fb_08a0_d7f6d81a0646
  style d76760d8_a189_0f15_aae7_cb699a67e504 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from functools import partial
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch

import pytest

from langchain_classic.agents.openai_assistant import OpenAIAssistantRunnable


def _create_mock_client(*_: Any, use_async: bool = False, **__: Any) -> Any:
    client = AsyncMock() if use_async else MagicMock()
    mock_assistant = MagicMock()
    mock_assistant.id = "abc123"
    client.beta.assistants.create.return_value = mock_assistant
    return client


@pytest.mark.requires("openai")
def test_user_supplied_client() -> None:
    openai = pytest.importorskip("openai")

    client = openai.AzureOpenAI(
        azure_endpoint="azure_endpoint",
        api_key="api_key",
        api_version="api_version",
    )

    assistant = OpenAIAssistantRunnable(
        assistant_id="assistant_id",
        client=client,
    )

    assert assistant.client == client


@pytest.mark.requires("openai")
@patch(
    "langchain_classic.agents.openai_assistant.base._get_openai_client",
    _create_mock_client,
)
def test_create_assistant() -> None:
    assistant = OpenAIAssistantRunnable.create_assistant(
        name="name",
        instructions="instructions",
        tools=[{"type": "code_interpreter"}],
        model="",
    )
    assert isinstance(assistant, OpenAIAssistantRunnable)


@pytest.mark.requires("openai")
@patch(
    "langchain_classic.agents.openai_assistant.base._get_openai_async_client",
    partial(_create_mock_client, use_async=True),
)
async def test_ainvoke_uses_async_response_completed() -> None:
    # Arrange a runner with mocked async client and a completed run
    assistant = OpenAIAssistantRunnable(
        assistant_id="assistant_id",
        client=_create_mock_client(),
// ... (84 more lines)

Domain

Subdomains

Dependencies

  • functools
  • langchain_classic.agents.openai_assistant
  • pytest
  • typing
  • unittest.mock

Frequently Asked Questions

What does test_openai_assistant.py do?
test_openai_assistant.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What functions are defined in test_openai_assistant.py?
test_openai_assistant.py defines 6 function(s): _create_mock_client, test_acreate_assistant, test_ainvoke_uses_async_response_completed, test_ainvoke_uses_async_response_requires_action_agent, test_create_assistant, test_user_supplied_client.
What does test_openai_assistant.py depend on?
test_openai_assistant.py imports 5 module(s): functools, langchain_classic.agents.openai_assistant, pytest, typing, unittest.mock.
Where is test_openai_assistant.py in the architecture?
test_openai_assistant.py is located at libs/langchain/tests/unit_tests/agents/test_openai_assistant.py (domain: LangChainCore, subdomain: Runnables, directory: libs/langchain/tests/unit_tests/agents).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free