Skip to content

Commit 3231b52

Browse files
committed
Try to preload tiktoken
1 parent fb2c9f3 commit 3231b52

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

tests/mlmodel_langchain/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717

1818
import pytest
19+
import tiktoken
1920
from langchain_core.messages.ai import AIMessage
2021
from langchain_core.messages.tool import ToolMessage
2122
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
@@ -76,6 +77,8 @@
7677
]
7778
)
7879

80+
TIKTOKEN_ENCODINGS = ["cl100k_base"]
81+
7982

8083
# Intercept outgoing requests and log to file for mocking
8184
EXPECTED_AGENT_RESPONSE = "Hello!"
@@ -108,6 +111,13 @@ def embedding_openai_client(openai_clients):
108111
return embedding_client
109112

110113

114+
@pytest.fixture(scope="session")
115+
def load_tiktoken_encodings():
116+
"""Load tiktoken encodings before tests run to avoid issues with VCR blocking the network."""
117+
for encoding in TIKTOKEN_ENCODINGS:
118+
tiktoken.get_encoding(encoding)
119+
120+
111121
@pytest.fixture
112122
def chat_openai_client(openai_clients):
113123
chat_client, _ = openai_clients

0 commit comments

Comments
 (0)