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

Implement ChatSteps and ChatStep to show/hide intermediate steps #6617

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Mar 30, 2024

Edit: see notebook for updated usage.

Closes #6598

The relationship:
ChatInterface > ChatFeed > Steps or Step
Steps > Step

Easily available to use by:
instance.step(**kwargs) -> instance.stream(ChatStep(**kwargs))
instance.steps(**kwargs) -> instance.stream(ChatSteps(**kwargs))
steps.step(**kwargs) -> steps.append(step)

ChatStep(s) methods mimic ChatFeed methods:
step.stream()
step.stream_title()

import time
import panel as pn

pn.extension()


def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
    with instance.steps() as steps:
        for i in range(0, 4):
            with steps.step() as step:
                message = None
                for c in contents[i:]:
                    time.sleep(0.3)
                    message = step.stream(c, message=message)
                    step.title = f"Processing: {c}"

chat_interface = pn.chat.ChatInterface(callback=callback, callback_exception="verbose")
chat_interface.show()

These context managers are optional and the equivalent of:

import time
import panel as pn

pn.extension()


def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
    steps = pn.chat.ChatSteps(title="Running...", status="running")
    instance.stream(steps)
    
    for i in range(0, 4):
        step = pn.chat.ChatStep(margin=0)
        step.title = "Running..."
        step.status = "running"
        steps.append(step)
        message = None
        for c in contents[i:]:
            time.sleep(0.3)
            message = step.stream(c, message=message)
            step.title = f"Processing: {c}"
        step.status = "completed"
    steps.title = step.objects[-1].object
    steps.status = "completed"

chat_interface = pn.chat.ChatInterface(callback=callback, callback_exception="verbose")
chat_interface.show()
Screen.Recording.2024-04-01.at.6.00.35.PM.mov
  • docs
  • tests
  • serialize

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Apr 2, 2024

I'm overall very much for making progress reporting easy.

The first feedback I have is

  • Is this functionality really chat specific. I believe many other processes/ flows would like to report back feedback like this. For example Streamlit made a status component. Not a chat_status component. The feature will be more valuable if its general.
  • I like the context manager a lot. But if we introduce it here would it not be a good idea to analyze which components/ flows could benefit from a context manager approach and then make a general design specification?
  • Rember to check look and feel with sizing_mode="stretch_width" and in a template (like FastListTemplate). I would also recommend finding some beautiful icons instead of colorful emojis that will not work great with specific accent colors and templates.

@ahuang11
Copy link
Contributor Author

ahuang11 commented Apr 2, 2024

I like the idea of a Status component that inherits from Card.

I like the context manager a lot. But if we introduce it here would it not be a good idea to analyze which components/ flows could benefit from a context manager approach and then make a general design specification?

I'm not 100% sure that's neceessary since it's a matter of implementing __enter__ & __exit__ in the corresponding classes if needed--no special method names required.

@MarcSkovMadsen
Copy link
Collaborator

The reason i think its important with a strategy for Context managers is that its much easier to use a framework if it follows some general principløs. It's much harder if suddenly one component can be used as a Context manager and the rest of the components cannot.

@ahuang11
Copy link
Contributor Author

ahuang11 commented Apr 2, 2024

Can you think of other components that context managers could be useful for?

I imagine indicators, boolean, Card/Accordion.

Also, maybe disabled/loading?

@ahuang11
Copy link
Contributor Author

Cleaner layout:

Screen.Recording.2024-05-14.at.7.23.52.PM.mov

Copy link

codecov bot commented May 15, 2024

Codecov Report

Attention: Patch coverage is 43.40426% with 133 lines in your changes are missing coverage. Please review.

Project coverage is 39.91%. Comparing base (c7af196) to head (d4468bb).
Report is 18 commits behind head on main.

Files Patch % Lines
panel/chat/utils.py 40.00% 54 Missing ⚠️
panel/chat/step.py 45.23% 46 Missing ⚠️
panel/chat/steps.py 50.00% 19 Missing ⚠️
panel/chat/feed.py 28.57% 10 Missing ⚠️
panel/chat/__init__.py 50.00% 2 Missing ⚠️
panel/chat/message.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #6617       +/-   ##
===========================================
- Coverage   81.51%   39.91%   -41.60%     
===========================================
  Files         318      310        -8     
  Lines       46709    45093     -1616     
===========================================
- Hits        38074    17999    -20075     
- Misses       8635    27094    +18459     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahuang11 ahuang11 requested a review from philippjfr May 20, 2024 20:40
@ahuang11
Copy link
Contributor Author

ahuang11 commented May 20, 2024

Okay this is ready for review! See https://github.com/holoviz/panel/blob/1fbaac662d8e33887eebac7e215fa441e04c091b/examples/reference/chat/ChatStep.ipynb for usage.

I'm not sure if ChatSteps requires a separate gallery notebook?

image

@ahuang11 ahuang11 marked this pull request as ready for review May 20, 2024 20:41
panel/chat/feed.py Outdated Show resolved Hide resolved
@@ -335,70 +336,6 @@ def _build_layout(self):
viewable_params['stylesheets'] = self._stylesheets + self.param.stylesheets.rx()
self._composite = Row(left_col, right_col, **viewable_params)

def _get_obj_label(self, obj):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ported to utils.py

@@ -782,8 +656,6 @@ def serialize(

Arguments
---------
obj : Any
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No obj arg.

@ahuang11 ahuang11 changed the title Start adding chat steps Implement ChatSteps and ChatStep to show/hide intermediate steps May 20, 2024
@ahuang11 ahuang11 marked this pull request as draft May 23, 2024 06:04
@ahuang11
Copy link
Contributor Author

Added some new methods while implementing holoviz/lumen#560. Need to change the docs, and also add tests, which I realized I didn't commit it and accidentally removed it locally :(

Screen.Recording.2024-05-22.at.11.01.27.PM.mov

@ahuang11 ahuang11 marked this pull request as ready for review May 23, 2024 21:18
@ahuang11
Copy link
Contributor Author

ready for review now

Screen.Recording.2024-05-23.at.2.23.24.PM.mov

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.

ChatAccordion and ChatCard
2 participants