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

Allow appending objects to the ChatMessage header & footer #6410

Merged
merged 2 commits into from
Mar 2, 2024

Conversation

ahuang11
Copy link
Contributor

image image

If user runs serialize the contents will be separate from the footer/header objects, and reduces the need to write a custom serializer.

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,
    )
    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)
            yield pn.chat.ChatMessage(
                parts,
                user="ChatGPT",
                header_objects=[
                    pn.Row(
                        pn.widgets.FileDownload(icon="download", margin=(0, 5, 5, 15)),
                    )
                ],
                footer_objects=[indicator],
            )

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 (39379c8) to head (df2f2c0).
Report is 12 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #6410       +/-   ##
===========================================
- Coverage   83.63%   71.66%   -11.98%     
===========================================
  Files         305      305               
  Lines       45594    45739      +145     
===========================================
- Hits        38132    32777     -5355     
- Misses       7462    12962     +5500     
Flag Coverage Δ
ui-tests ?
unitexamples-tests 71.66% <100.00%> (+0.04%) ⬆️

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 Allow appending objects to the header & footer Allow appending objects to the ChatMessage header & footer Feb 28, 2024
@philippjfr philippjfr merged commit 6772742 into main Mar 2, 2024
10 of 15 checks passed
@philippjfr philippjfr deleted the add_header_footer branch March 2, 2024 22:34
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.

2 participants