mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
add repr for not serializable (#10071)
Co-authored-by: Nuno Campos <nuno@boringbits.io>
This commit is contained in:
parent
355ff09cce
commit
d7bf7dc412
@ -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",
|
||||||
|
@ -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
|
||||||
|
@ -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,
|
||||||
|
@ -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
Loading…
Reference in New Issue
Block a user