New RunLLM response generated: >>>*# Question* Hi...
# runllm-flyte-trial
j
New RunLLM response generated: >>>*# Question* Hi, is it possible to make a task based on class? Something like
Copy code
@task
class ConfigurableFunction:
    def __init__(self, x:int):
        self._x = x
    def __call__(self, y:int) -> int:
        return self._x * y
And then usage
Copy code
f10 = ConfigurableFunction(10)
f25 = ConfigurableFunction(25)

@workflow
def wf():
   a = 10
   b = f10(a)
   c = f25(b)
   return c
# Answer Flyte does not natively support defining tasks directly within classes as shown in your example. However, you can achieve similar functionality using a combination of task decorators and class methods. According to Flyte GitHub Issue #3492, there is ongoing discussion and partial implementation for supporting class-based tasks, but it is not fully supported yet. Here's a workaround using class methods and task decorators:
Copy code
from flytekit import task, workflow

class ConfigurableFunction:
    def __init__(self, x: int):
        self._x = x

    @task
    def __call__(self, y: int) -> int:
        return self._x * y

f10 = ConfigurableFunction(10)
f25 = ConfigurableFunction(25)

@workflow
def wf(a: int) -> int:
    b = f10.__call__(y=a)
    c = f25.__call__(y=b)
    return c

if __name__ == "__main__":
    print(wf(a=10))
Would you like more details on this approach or any other specific aspect? Sources: - Flyte GitHub Issue #3492 Slack Link https://.slack.com/archives/CP2HDHKE1/p1727179537.049549 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.