Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to print both tool use requests and responses inside chat.toolloop? #9

Open
maraoz opened this issue Jun 23, 2024 · 2 comments

Comments

@maraoz
Copy link
Contributor

maraoz commented Jun 23, 2024

Hi, sorry if this is a dumb question but I've been trying to make this work and reading the source code and I've had no luck.

I'm playing with an assistant which has 3 tools.
I'm trying to print everything that's happening so I can debug the system prompt and the initial message prompt.
However, if I call chat.toolloop like so:

answer = chat.toolloop(main_prompt, trace_func=print)

I only get prints of:

  • (1) the messages from the assistant before calling the tool
  • (2) the tool_use request
  • (3) the messages from the assistant after calling the tool and seeing the results

I'm not seeing, however, any output regarding the tool function call, nor the results and how they are sent to Claude (which would be very useful in debugging).

To work around this, I added prints inside the tool function, but the result is a little weird (at least to me):
The prints from the tool function call appear before (1) from above.

The question is: is there easy way to have the debug prints in chronological order (that is, (1), (2), tool function prints, (3))?
Thanks in advance! Claudette inspired me to play with Claude API and it's fun! :)

@maraoz maraoz changed the title Is there a way to print tool use requests and responses inside chat.toolloop? Is there a way to print both tool use requests and responses inside chat.toolloop? Jun 23, 2024
@jph00
Copy link
Contributor

jph00 commented Jun 24, 2024

I want that too! At some point I'll get around to adding it...

@maraoz
Copy link
Contributor Author

maraoz commented Jun 24, 2024

In case anyone is in the same situation...
For now I'm using the following decorator:

import functools

def debug_print(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        result = func(*args, **kwargs)
        print(f"TOOL DEBUG: {func.__name__}() returned {result}")
        return result
    return wrapper

You can use it by prefixing your tool functions with @debug_print like so:

@debug_print
def get_customer_info(...):
  ...

If I have time this week I'll try to add the functionality to claudette (although I wouldn't do it with a decorator)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants