Instead of calling the fxn.predictions.create method, the Python SDK provides an @fxn.beta.predict decorator
which monkey-patches an existing function to instead make a prediction:
Apply the @fxn.beta.predict decorator to a function. When the function is called, it will instead create a prediction
with the provided tag and return the results:
Copy
from fxn import Function# π₯ Create a Function clientfxn = Function(...)# π₯ Monkey-patch a function@fxn.beta.predict(tag="@yusuf/add")def add_numbers (a, b): ...# π Call the functionprint(add_numbers(9, 10))# Output:# 21
To instead stream the prediction, add an Iterator or Generator return type annotation to the function:
Copy
from fxn import Function# π₯ Create a Function clientfxn = Function(...)# π₯ Monkey-patch a function@fxn.beta.predict(tag="@yusuf/split-sentence")def split_sentence (sentence) -> Iterator[str]: ...# π Call the functionfor split in split_sentence("This is a long speech"): print(split)# Output:# "This"# "is"# "a"# "long"# "speech"