vnoelifant / cozmo-companion

1 stars 0 forks source link

Fix the tool related error #27

Closed vnoelifant closed 11 months ago

vnoelifant commented 1 year ago
          Create follow up issue to fix the tool related error

_Originally posted by @Zaubeerer in https://github.com/vnoelifant/cozmo-companion/pull/26#discussion_r1375761094_

vnoelifant commented 11 months ago

Fixed per comment in Marvin forums @Zaubeerer:

i think the issue (as is often the issue with fancy decorators 🙂 ) has to do with the fact that @tool expects to be decorating a python function that is not a method on a class

this is working for me if a tool like get_feedback_inquiry is not a method on a class, but a pure python function

In [1]: from marvin.tools import tool

In [2]: @tool
   ...: def get_feedback_inquiry(user_text: str = "") -> str | None:
   ...:     feedback_phrases = ["joke", "motivational quote"]
   ...:     for phrase in feedback_phrases:
   ...:         if phrase in user_text.lower():
   ...:             return "Did this help put a smile on your face?"
   ...:     return None
   ...:

In [3]: from marvin import AIApplication

In [4]: app = AIApplication(name="marvin", description="talk like a pirate", tools=[get_feedback_inquiry])

In [5]: app.tools[0]("joke")
Out[5]: 'Did this help put a smile on your face?'

In [6]: !pip list | rg marvin
marvin                          1.5.6
Zaubeerer commented 11 months ago

Interesting!

Soon, Marvin 2.0 will be released, probably some of these bugs will be fixed.