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

Add support for thinking LLMs directly in gr.ChatInterface #10305

Merged
merged 98 commits into from
Jan 10, 2025
Merged

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Jan 7, 2025

This PR builds off of #10226 to add support for thoughts directly in gr.ChatInterface. I actually spent a lot of time trying to get the duration to show up automatically based on timing the chat function calls but in the end, everything I tried seemed very "magical" and not too configurable and so I left it to the dev to manually set it.

To test, try these two demos:

  • demo/chatinterface_thoughts/run.py
  • demo/chatinterface_nested_thoughts/run.py

This PR also essentially closes: #9051, or at least the most actionable part of it -- increased documentation on how to use thinking LLMs with gr.ChatInterface

@@ -37,6 +37,8 @@ class MetadataDict(TypedDict):
title: Union[str, None]
id: NotRequired[int | str]
parent_id: NotRequired[int | str]
duration: NotRequired[int]
status: NotRequired[Literal["pending", "done"]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I moved duration inside of metadata where I think it makes more sense. I also added a status for more control over the loading spinner, as it improves the UI a bit (cc @yvrjsharma)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep that makes sense!

@abidlabs
Copy link
Member Author

abidlabs commented Jan 9, 2025

Will fix the tests tomorrow but should otherwise be ready for review

Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs changes look good, but should we add docs for the gr.ChatMessage data class? Similar to how we did for Audio and ImageEditor?

@@ -87,14 +88,15 @@ class Metadata(GradioModel):
title: Optional[str] = None
id: Optional[int | str] = None
parent_id: Optional[int | str] = None
duration: Optional[float] = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be float or int? it's an int on line 40

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be a float in the general case, I'll update the other reference!

@abidlabs
Copy link
Member Author

abidlabs commented Jan 9, 2025

Docs changes look good, but should we add docs for the gr.ChatMessage data class? Similar to how we did for Audio and ImageEditor?

yeah good point, I'll expose this!

Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice docs and PR @abidlabs !

@aliabd
Copy link
Collaborator

aliabd commented Jan 9, 2025

@abidlabs I added ChatMessage to the docs page for Chatbot as a helper class. The docs are mostly a placeholder though so please correct/rewrite them.

Copy link
Collaborator

@hannahblair hannahblair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and LGTM! :) Thanks @abidlabs!

@abidlabs
Copy link
Member Author

abidlabs commented Jan 9, 2025

Sweet thanks everyone for the reviews and contribution! Everything should be addressed now I'll merge in once CI runs

@abidlabs abidlabs enabled auto-merge (squash) January 9, 2025 23:44
@abidlabs abidlabs merged commit be40307 into main Jan 10, 2025
22 of 23 checks passed
@abidlabs abidlabs deleted the thought-ci branch January 10, 2025 00:06
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

Successfully merging this pull request may close these issues.

Enhancements to tool use in gr.Chatbot
5 participants