Skip to content

Commit

Permalink
Add crush dumping if content size limit exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Huang authored and Nick Huang committed Oct 8, 2024
1 parent f034c38 commit c0f3745
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def _get_settings(self) -> ls_schemas.LangSmithSettings:

return self._settings

def _content_above_size(self, content_length: Optional[int]) -> Optional[str]:
def _content_above_size(self, content_length: Optional[int], request: Optional[requests.Request | requests.PreparedRequest] ) -> Optional[str]:
if content_length is None or self._info is None:
return None
info = cast(ls_schemas.LangSmithInfo, self._info)
Expand All @@ -742,6 +742,11 @@ def _content_above_size(self, content_length: Optional[int]) -> Optional[str]:
if size_limit is None:
return None
if content_length > size_limit:
should_debug_crash_dump = os.getenv("LANGSMITH_DEBUG_CRASH_DUMP") in ["1", "true"]
if should_debug_crash_dump:
with open("content_size_limit_crash_dump.jsonl", "a") as f:
json.dump(request.body, f)
f.write("\n")
return (
f"The content length of {content_length} bytes exceeds the "
f"maximum size limit of {size_limit} bytes."
Expand Down Expand Up @@ -918,7 +923,7 @@ def request_with_retries(
if e.request
else ""
)
size_rec = self._content_above_size(content_length)
size_rec = self._content_above_size(content_length, e.request)
if size_rec:
recommendation = size_rec
except ValueError:
Expand Down

0 comments on commit c0f3745

Please sign in to comment.