Skip to content

Commit

Permalink
fix: AttributeError in LangSmithEventHandler (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
micpst authored May 15, 2024
1 parent 61f1066 commit c8cfe97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ examples =
pydantic_settings~=2.1.0
psycopg2-binary~=2.9.9
langsmith=
langsmith>=0.0.87
langsmith~=0.1.57
transformers=
transformers>=4.37.1
benchmark =
Expand Down
14 changes: 9 additions & 5 deletions src/dbally/audit/event_handlers/langsmith_event_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import socket
from getpass import getuser
from typing import Union
from typing import Optional, Union

from langsmith.client import Client
from langsmith.run_trees import RunTree
Expand All @@ -13,13 +13,18 @@ class LangSmithEventHandler(EventHandler[RunTree, RunTree]):
"""
This handler Logs events to a LangSmith instance.
!!! tip
To learn how to use `LangSmithEventHandler` visit
[How-To: Log db-ally runs to LangSmith](../../how-to/log_runs_to_langsmith.md)
"""

def __init__(self, api_key: str):
def __init__(self, api_key: Optional[str] = None):
"""
Constructs a new langsmith event handler instance.
Args:
api_key: The api key for LangSmith. If None LANGCHAIN_API_KEY environment variable will be used.
"""
self._client = Client(api_key=api_key)

async def request_start(self, user_request: RequestStart) -> RunTree:
Expand Down Expand Up @@ -88,5 +93,4 @@ async def request_end(self, output: RequestEnd, request_context: RunTree) -> Non
request_context: Optional context passed from request_start method
"""
request_context.end(outputs={"sql": output.result.context["sql"]})
res = request_context.post(exclude_child_runs=False)
res.result()
request_context.post(exclude_child_runs=False)

0 comments on commit c8cfe97

Please sign in to comment.