Skip to content

Commit bd560f7

Browse files
committed
exclude unused/private methods from langchain core
1 parent 9ce0d12 commit bd560f7

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/langtrace_python_sdk/instrumentation/langchain_core/instrumentation.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ def patch_module_classes(
6666
if name.startswith("_") or name in exclude_classes:
6767
continue
6868
# loop through all public methods of the class
69-
for method_name, method in inspect.getmembers(obj, predicate=inspect.isfunction):
70-
if method_name in exclude_methods or method.__qualname__.split('.')[0] != name:
69+
for method_name, method in inspect.getmembers(
70+
obj, predicate=inspect.isfunction
71+
):
72+
if (
73+
method_name in exclude_methods
74+
or method.__qualname__.split(".")[0] != name
75+
or method_name.startswith("_")
76+
):
7177
continue
7278
try:
7379
method_path = f"{name}.{method_name}"
@@ -108,6 +114,9 @@ def _instrument(self, **kwargs):
108114
"format",
109115
"format_messages",
110116
"format_prompt",
117+
"__or__",
118+
"__init__",
119+
"__repr__",
111120
]
112121
exclude_classes = [
113122
"BaseChatPromptTemplate",
@@ -125,7 +134,13 @@ def _instrument(self, **kwargs):
125134
modules_to_patch = [
126135
("langchain_core.retrievers", "retriever", generic_patch, True, True),
127136
("langchain_core.prompts.chat", "prompt", generic_patch, True, True),
128-
("langchain_core.language_models.llms", "generate", generic_patch, True, True),
137+
(
138+
"langchain_core.language_models.llms",
139+
"generate",
140+
generic_patch,
141+
True,
142+
True,
143+
),
129144
("langchain_core.runnables.base", "runnable", runnable_patch, True, True),
130145
(
131146
"langchain_core.runnables.passthrough",

0 commit comments

Comments
 (0)