add repr for not serializable (#10071)

Co-authored-by: Nuno Campos <nuno@boringbits.io>
This commit is contained in:
Harrison Chase 2023-09-01 09:18:32 -07:00 committed by GitHub
parent 355ff09cce
commit d7bf7dc412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 108 additions and 54 deletions

View File

@ -1193,7 +1193,6 @@ class CallbackManager(BaseCallbackManager):
""" """
if run_id is None: if run_id is None:
run_id = uuid.uuid4() run_id = uuid.uuid4()
_handle_event( _handle_event(
self.handlers, self.handlers,
"on_chain_start", "on_chain_start",

View File

@ -1,5 +1,5 @@
from abc import ABC from abc import ABC
from typing import Any, Dict, List, Literal, TypedDict, Union, cast from typing import Any, Dict, List, Literal, Optional, TypedDict, Union, cast
from langchain.pydantic_v1 import BaseModel, PrivateAttr from langchain.pydantic_v1 import BaseModel, PrivateAttr
@ -28,6 +28,7 @@ class SerializedNotImplemented(BaseSerialized):
"""Serialized not implemented.""" """Serialized not implemented."""
type: Literal["not_implemented"] type: Literal["not_implemented"]
repr: Optional[str]
class Serializable(BaseModel, ABC): class Serializable(BaseModel, ABC):
@ -156,8 +157,15 @@ def to_json_not_implemented(obj: object) -> SerializedNotImplemented:
_id = [*obj.__class__.__module__.split("."), obj.__class__.__name__] _id = [*obj.__class__.__module__.split("."), obj.__class__.__name__]
except Exception: except Exception:
pass pass
return {
result: SerializedNotImplemented = {
"lc": 1, "lc": 1,
"type": "not_implemented", "type": "not_implemented",
"id": _id, "id": _id,
"repr": None,
} }
try:
result["repr"] = repr(obj)
except Exception:
pass
return result

View File

@ -1697,6 +1697,9 @@ class RunnableLambda(Runnable[Input, Output]):
else: else:
return False return False
def __repr__(self) -> str:
return "RunnableLambda(...)"
def _invoke( def _invoke(
self, self,
input: Input, input: Input,

View File

@ -229,7 +229,8 @@
"api_resources", "api_resources",
"completion", "completion",
"Completion" "Completion"
] ],
"repr": "<class 'openai.api_resources.completion.Completion'>"
} }
} }
}, },

File diff suppressed because one or more lines are too long