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

Include stylesheets downstream, including layouts in ChatMessage #6405

Merged
merged 3 commits into from Mar 2, 2024

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Feb 28, 2024

Before (no message background, even though css class is set.):
image

After:
image

"""
Demonstrates how to use the `ChatInterface` to create a chatbot using
OpenAI's with async/await.
"""

import panel as pn
from openai import AsyncOpenAI

pn.extension()


async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
    response = await aclient.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": contents}],
        stream=True,
    )
    message = None
    parts = ""
    indicator = pn.indicators.Dial(name="Length")
    async for chunk in response:
        part = chunk.choices[0].delta.content
        if part:
            parts += part
            indicator.value = len(parts)
            layout = pn.Row(
                pn.pane.Markdown(parts, css_classes=["message"]),
                indicator,
            )
            yield layout


aclient = AsyncOpenAI()
chat_interface = pn.chat.ChatInterface(callback=callback, callback_user="ChatGPT")
chat_interface.send(
    "Send a message to get a reply from ChatGPT!", user="System", respond=False
)
chat_interface.servable()

Copy link

codecov bot commented Feb 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.66%. Comparing base (4581b4a) to head (8c7db6b).

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #6405       +/-   ##
===========================================
- Coverage   82.03%   71.66%   -10.38%     
===========================================
  Files         305      305               
  Lines       45730    45738        +8     
===========================================
- Hits        37515    32776     -4739     
- Misses       8215    12962     +4747     
Flag Coverage Δ
ui-tests ?
unitexamples-tests 71.66% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ahuang11 ahuang11 changed the title Include stylesheets downstream, including layouts in message Include stylesheets downstream, including layouts in ChatMessage Feb 28, 2024
@ahuang11 ahuang11 added this to the v1.4.0 milestone Feb 28, 2024
@@ -498,6 +498,7 @@ def _create_panel(self, value, old=None):
"""
if isinstance(value, Viewable):
self._internal = False
self._include_stylesheets_inplace(value)
Copy link
Member

Choose a reason for hiding this comment

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

I'm always a little wary for applying stylesheets inplace on objects the user created but I guess it's okay here.

@philippjfr philippjfr merged commit dacea9a into main Mar 2, 2024
11 of 15 checks passed
@philippjfr philippjfr deleted the merge_stylesheets branch March 2, 2024 22:39
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.

None yet

2 participants