Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run eval in eval mode #6447

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion langchain/client/runner_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async def arun_on_examples(
results: Dict[str, List[Any]] = {}

async def process_example(
example: Example, tracer: LangChainTracer, job_state: dict
example: Example, tracer: Optional[LangChainTracer], job_state: dict
) -> None:
"""Process a single example."""
result = await _arun_llm_or_chain(
Expand Down Expand Up @@ -466,6 +466,7 @@ async def arun_on_dataset(
"""
client_ = client or LangChainPlusClient()
session_name = _get_session_name(session_name, llm_or_chain_factory, dataset_name)
client_.create_session(session_name, mode="eval")
dataset = client_.read_dataset(dataset_name=dataset_name)
examples = client_.list_examples(dataset_id=str(dataset.id))

Expand Down Expand Up @@ -517,6 +518,7 @@ def run_on_dataset(
"""
client_ = client or LangChainPlusClient()
session_name = _get_session_name(session_name, llm_or_chain_factory, dataset_name)
client_.create_session(session_name, mode="eval")
dataset = client_.read_dataset(dataset_name=dataset_name)
examples = client_.list_examples(dataset_id=str(dataset.id))
results = run_on_examples(
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ singlestoredb = {version = "^0.6.1", optional = true}
pyspark = {version = "^3.4.0", optional = true}
tigrisdb = {version = "^1.0.0b6", optional = true}
nebula3-python = {version = "^3.4.0", optional = true}
langchainplus-sdk = ">=0.0.9"
langchainplus-sdk = ">=0.0.13"
awadb = {version = "^0.3.3", optional = true}
azure-search-documents = {version = "11.4.0a20230509004", source = "azure-sdk-dev", optional = true}
# now streamlit requires Python >=3.7, !=3.9.7 So, it is commented out.
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_tests/client/test_runner_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,17 @@ async def mock_arun_chain(
{"result": f"Result for example {example.id}"} for _ in range(n_repetitions)
]

def mock_create_session(*args: Any, **kwargs: Any) -> None:
pass

with mock.patch.object(
LangChainPlusClient, "read_dataset", new=mock_read_dataset
), mock.patch.object(
LangChainPlusClient, "list_examples", new=mock_list_examples
), mock.patch(
"langchain.client.runner_utils._arun_llm_or_chain", new=mock_arun_chain
), mock.patch.object(
LangChainPlusClient, "create_session", new=mock_create_session
):
client = LangChainPlusClient(api_url="http://localhost:1984", api_key="123")
chain = mock.MagicMock()
Expand Down