Skip to content

Commit

Permalink
Merge pull request #141 from Chainlit/willy/fix-lc-structured-output
Browse files Browse the repository at this point in the history
fix: lc structured output json ser
  • Loading branch information
willydouhard authored Nov 7, 2024
2 parents 307dcbf + 03ae87c commit de701d1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion literalai/callback/langchain_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from importlib.metadata import version
from typing import TYPE_CHECKING, Any, Dict, List, Optional, TypedDict, Union, cast

from pydantic import BaseModel

from literalai.helper import ensure_values_serializable
from literalai.observability.generation import (
ChatGeneration,
Expand Down Expand Up @@ -148,6 +150,8 @@ def process_content(self, content: Any, root=True):
return [self._convert_message(m) for m in content]
elif self._is_message(content):
return self._convert_message(content)
elif isinstance(content, BaseModel):
return content.model_dump()
elif isinstance(content, dict):
processed_dict = {}
for key, value in content.items():
Expand Down Expand Up @@ -186,7 +190,9 @@ def _build_llm_settings(
}

# make sure there is no api key specification
settings = {k: v for k, v in merged.items() if not k.endswith("_api_key")}
settings = self.process_content(
{k: v for k, v in merged.items() if not k.endswith("_api_key")}
)
model_keys = ["azure_deployment", "deployment_name", "model", "model_name"]
model = next((settings[k] for k in model_keys if k in settings), None)
tools = None
Expand All @@ -203,6 +209,7 @@ def _build_llm_settings(
"RunnableParallel",
"RunnableAssign",
"RunnableLambda",
"structured_outputs_parser",
"<lambda>",
]
DEFAULT_TO_KEEP = ["retriever", "llm", "agent", "chain", "tool"]
Expand Down
2 changes: 1 addition & 1 deletion literalai/event_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class EventProcessor:
batch_timeout: float = 5.0

def __init__(self, api: "LiteralAPI", batch_size: int = 1, disabled: bool = False):
self.stop_event = threading.Event()
self.batch_size = batch_size
self.api = api
self.event_queue = queue.Queue()
Expand All @@ -44,7 +45,6 @@ def __init__(self, api: "LiteralAPI", batch_size: int = 1, disabled: bool = Fals
)
if not self.disabled:
self.processing_thread.start()
self.stop_event = threading.Event()

def add_event(self, event: "StepDict"):
with self.counter_lock:
Expand Down
2 changes: 1 addition & 1 deletion literalai/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.628"
__version__ = "0.0.629"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="literalai",
version="0.0.628", # update version in literalai/version.py
version="0.0.629", # update version in literalai/version.py
description="An SDK for observability in Python applications",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit de701d1

Please sign in to comment.