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 message into css_classes to ChatMessage's markup #6407

Merged
merged 5 commits into from
Mar 11, 2024

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Feb 28, 2024

Builds upon #6405

Text wrapped in pn.Row/pn.Column without the grey background looks extremely out of place; this alleviates it by attaching "message" into css_classes, unless the user provides their own css_classes.

Before:
image

After:
image

Note, no need to pass css_classes=["message"]; simply pass parts (previously pn.pane.Markdown(parts, css_classes=["message"]))

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(
                parts,
                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()

@ahuang11 ahuang11 changed the title Add message css classes to markup Add message into css_classes to ChatMessage's markup Feb 28, 2024
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

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

Project coverage is 22.22%. Comparing base (5578f98) to head (0de3b7c).
Report is 1175 commits behind head on main.

Files Patch % Lines
panel/chat/message.py 6.25% 15 Missing ⚠️
panel/tests/chat/test_message.py 9.09% 10 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #6407       +/-   ##
===========================================
- Coverage   82.75%   22.22%   -60.54%     
===========================================
  Files         239      312       +73     
  Lines       34507    46074    +11567     
===========================================
- Hits        28555    10238    -18317     
- Misses       5952    35836    +29884     
Flag Coverage Δ
ui-tests ?
unitexamples-tests 22.22% <7.40%> (-51.64%) ⬇️

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.

Base automatically changed from merge_stylesheets to main March 2, 2024 22:39
panel/chat/message.py Outdated Show resolved Hide resolved
panel/chat/message.py Outdated Show resolved Hide resolved
@ahuang11 ahuang11 requested a review from philippjfr March 4, 2024 17:23
panel/chat/message.py Outdated Show resolved Hide resolved
@philippjfr philippjfr merged commit 8a7e6b0 into main Mar 11, 2024
12 of 15 checks passed
@philippjfr philippjfr deleted the add_message_css_class branch March 11, 2024 23:47
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