Skip to content

Commit 3860f7d

Browse files
committed
Skip langchain test for less than 3.7
1 parent 9250922 commit 3860f7d

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

databricks/sdk/mixins/open_ai_client.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,30 @@ def get_open_ai_client(self):
1111
except Exception:
1212
raise ValueError("Unable to extract authorization token for OpenAI Client")
1313

14-
from openai import OpenAI
14+
try:
15+
from openai import OpenAI
16+
except Exception:
17+
raise ImportError(
18+
"Open AI is not installed. Please install the Databricks SDK with the following command `pip isntall databricks-sdk[openai]`"
19+
)
20+
1521
return OpenAI(base_url=self._api._cfg.host + "/serving-endpoints", api_key=token)
1622

1723
def get_langchain_chat_open_ai_client(self, model):
1824
auth_headers = self._api._cfg.authenticate()
1925

26+
try:
27+
from langchain_openai import ChatOpenAI
28+
except Exception:
29+
raise ImportError(
30+
"Langchain Open AI is not installed. Please install the Databricks SDK with the following command `pip isntall databricks-sdk[openai]` and ensure you are using python>3.7"
31+
)
32+
2033
try:
2134
token = auth_headers["Authorization"][len("Bearer "):]
2235
except Exception:
2336
raise ValueError("Unable to extract authorization token for Langchain OpenAI Client")
2437

25-
from langchain_openai import ChatOpenAI
2638
return ChatOpenAI(model=model,
2739
openai_api_base=self._api._cfg.host + "/serving-endpoints",
2840
openai_api_key=token)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"databricks-connect", "pytest-rerunfailures", "openai",
2121
"langchain-openai"],
2222
"notebook": ["ipython>=8,<9", "ipywidgets>=8,<9"],
23-
"openai": ["openai", "langchain-openai"]},
23+
"openai": ["openai", 'langchain-openai; python_version > "3.7"']},
2424
author="Serge Smertin",
2525
author_email="[email protected]",
2626
description="Databricks SDK for Python (Beta)",

tests/test_open_ai_mixin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import sys
2+
3+
import pytest
4+
15
from databricks.sdk.core import Config
26

37

@@ -13,6 +17,7 @@ def test_open_ai_client(monkeypatch):
1317
assert client.api_key == "test_token"
1418

1519

20+
@pytest.mark.skipif(sys.version_info <= (3, 7), reason="Requires Python > 3.7")
1621
def test_langchain_open_ai_client(monkeypatch):
1722
from databricks.sdk import WorkspaceClient
1823

@@ -22,4 +27,4 @@ def test_langchain_open_ai_client(monkeypatch):
2227
client = w.serving_endpoints.get_langchain_chat_open_ai_client("databricks-meta-llama-3-1-70b-instruct")
2328

2429
assert client.openai_api_base == "https://test_host/serving-endpoints"
25-
assert client.model_name == "databricks-meta-llama-3-1-70b-instruct"
30+
assert client.model_name == "databricks-meta-llama-3-1-70b-instruct"

0 commit comments

Comments
 (0)