diff --git a/python/langsmith/client.py b/python/langsmith/client.py index c11a84830..75913e87d 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -1700,32 +1700,46 @@ def multipart_ingest_runs( # send the request self._send_multipart_req(acc_parts, _context="; ".join(acc_context)) - def _send_multipart_req(self, parts: MultipartParts, *, _context: str): + def _send_multipart_req( + self, parts: MultipartParts, *, _context: str, attempts: int = 3 + ): for api_url, api_key in self._write_api_urls.items(): - try: - encoder = MultipartEncoder(parts, boundary=BOUNDARY) - self.request_with_retries( - "POST", - f"{api_url}/runs/multipart", - request_kwargs={ - "data": encoder, - "headers": { - **self._headers, - X_API_KEY: api_key, - "Content-Type": encoder.content_type, - }, - }, - to_ignore=(ls_utils.LangSmithConflictError,), - stop_after_attempt=3, - _context=_context, - ) - except Exception as e: + for idx in range(1, attempts + 1): try: - exc_desc_lines = traceback.format_exception_only(type(e), e) - exc_desc = "".join(exc_desc_lines).rstrip() - logger.warning(f"Failed to multipart ingest runs: {exc_desc}") - except Exception: - logger.warning(f"Failed to multipart ingest runs: {repr(e)}") + encoder = MultipartEncoder(parts, boundary=BOUNDARY) + self.request_with_retries( + "POST", + f"{api_url}/runs/multipart", + request_kwargs={ + "data": encoder, + "headers": { + **self._headers, + X_API_KEY: api_key, + "Content-Type": encoder.content_type, + }, + }, + stop_after_attempt=1, + _context=_context, + ) + break + except ls_utils.LangSmithConflictError: + break + except ( + ls_utils.LangSmithConnectionError, + ls_utils.LangSmithRequestTimeout, + ls_utils.LangSmithAPIError, + ) as exc: + if idx == attempts: + logger.warning(f"Failed to multipart ingest runs: {exc}") + else: + continue + except Exception as e: + try: + exc_desc_lines = traceback.format_exception_only(type(e), e) + exc_desc = "".join(exc_desc_lines).rstrip() + logger.warning(f"Failed to multipart ingest runs: {exc_desc}") + except Exception: + logger.warning(f"Failed to multipart ingest runs: {repr(e)}") def update_run( self, diff --git a/python/pyproject.toml b/python/pyproject.toml index 55a165512..fc5e0f0af 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langsmith" -version = "0.1.136" +version = "0.1.137" description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform." authors = ["LangChain "] license = "MIT"