-
Notifications
You must be signed in to change notification settings - Fork 160
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
Use rich.print in Chat utility #746
Comments
I guess you can already do this using from rich import print as rich_print
Chat(
structure=agent,
intro_text="\n[red]Welcome to Griptape Chat![/red]\n",
prompt_prefix="\n[steel_blue3]You: ",
processing_text="\n[aquamarine3]:thought_balloon: Thinking...",
response_prefix="\n[pink3]Agent: ",
output_fn=rich_print,
).start() |
@shhlife is the solution proposed by @michal-repo sufficient? If we move Open to discussion though, I haven't used |
@collindutter - sorry, just saw this reply! :) i've done some work using notice how the prompt_prefix isn't doing the right thing, and I found the output was doing newlines: |
@shhlife To solve this input issue you can introduce another Callable on Chat util, eg. from rich.console import Console
console = Console()
Chat(
structure=agent,
intro_text="\n[red]Welcome to Griptape Chat![/red]\n",
prompt_prefix="\n[steel_blue3]You: ",
processing_text="\n[aquamarine3]:thought_balloon: Thinking...",
response_prefix="\n[pink3]Agent: ",
input_fn=console.input,
).start() Newlines I guess are result of stream, this is solved by default here. from rich import print as rich_print
def rich_printer(text: str):
if agent.config.global_drivers.prompt_driver.stream:
rich_print(text, end="", flush=True)
else:
rich_print(text)
Chat(
structure=agent,
intro_text="\n[red]Welcome to Griptape Chat![/red]\n",
prompt_prefix="\n[steel_blue3]You: ",
processing_text="\n[aquamarine3]:thought_balloon: Thinking...",
response_prefix="\n[pink3]Agent: ",
output_fn=rich_printer,
).start() |
Hey @michal-repo - thanks for the response! yes, I could do that - but I think once we get to this point, I'd rather have this functionality built into the Chat utility so it's reusable elsewhere. :) |
Describe the solution you'd like
I would like to use the Rich library in the Chat utility to make it easier to discern the output between the Agent and the user.
We currently have the ability to modify the intro_text, prompt_prefix, processing_text, and response_prefix - but if the user includes some of the nice formatting of the Rich library, those aren't taken into account.
For example:
doesn't use the colors when executing the code.
Describe alternatives you've considered
I have tried creating my own formatted response, which will work for some of the responses - but using the rich library inside the Chat utility would make this much nicer.
Adding this line at the start of
chat.py
helps:Making these changes would allow the user to have their output look something like:
The text was updated successfully, but these errors were encountered: