AnswerDotAI / claudette

Claudette is Claude's friend
https://claudette.answer.ai/
Apache License 2.0
81 stars 10 forks source link

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

Open maraoz opened 1 week ago

maraoz commented 1 week ago

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:

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! :)

jph00 commented 1 week ago

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

maraoz commented 1 week ago

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)