@chain decorator on class functions #24181
Replies: 2 comments 4 replies
-
Hey @kim-borgen! I'm here to help you with any bugs, questions, or contribution-related matters. Let's take a look at the issue you've encountered together. To resolve the issue where the Using Static Methodsfrom langchain_core.runnables import chain
class SomeModule:
def __init__(self):
self.value = 5
@staticmethod
@chain
def add_one(input):
return input + 1
@staticmethod
@chain
def router(input):
if SomeModule().value == 5:
return SomeModule.add_one
else:
return input
def get_chain(self):
return self.router
m = SomeModule()
m.get_chain().invoke(5) Using Class Methodsfrom langchain_core.runnables import chain
class SomeModule:
def __init__(self):
self.value = 5
@classmethod
@chain
def add_one(cls, input):
return input + 1
@classmethod
@chain
def router(cls, input):
if cls().value == 5:
return cls.add_one
else:
return input
def get_chain(self):
return self.router
m = SomeModule()
m.get_chain().invoke(5) By using static or class methods, you avoid the issue of the |
Beta Was this translation helpful? Give feedback.
-
I am having this problem as well. Should I open a ticket for this? |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
Hi, we have a similar pattern to the toy example above. We wish to use the
@chain
decorator for simplicity to wrap python functions to RunnableLambdas. However, when I try to add this@chain
decorator to our class function, it doesn`t recognize the self variable I assume and thus throws this error:System Info
Truncated package Information
Beta Was this translation helpful? Give feedback.
All reactions