Compare commits

...

3 Commits

Author SHA1 Message Date
vowelparrot
e1f9da3768 Use thread pool 2023-05-16 19:56:08 -07:00
vowelparrot
f565bbe889 an option 2023-05-16 19:17:24 -07:00
vowelparrot
fcb0869672 Update task 2023-05-16 19:10:14 -07:00
2 changed files with 6 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
import logging
import os
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from typing import Any, Dict, List, Optional
from uuid import UUID
@@ -72,6 +73,9 @@ class LangChainTracer(BaseTracer):
self.example_id = example_id
self.session_name = session_name or os.getenv("LANGCHAIN_SESSION", "default")
self.session_extra = session_extra
self._executor = ThreadPoolExecutor(
max_workers=5, thread_name_prefix="langchain_tracer"
)
def on_chat_model_start(
self,
@@ -151,4 +155,4 @@ class LangChainTracer(BaseTracer):
"""Persist a run."""
run.reference_example_id = self.example_id
# TODO: Post first then patch
self._persist_run_nested(run)
self._executor.submit(self._persist_run_nested, run)

View File

@@ -98,6 +98,7 @@ def test_persist_run(
lang_chain_tracer_v2.run_map[str(run.id)] = run
for run in sample_runs:
lang_chain_tracer_v2._end_trace(run)
lang_chain_tracer_v2._executor.shutdown(wait=True)
assert post.call_count == 3
assert get.call_count == 0