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

Move chat components into its own namespace #5633

Merged
merged 15 commits into from
Oct 16, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"import asyncio\n",
"\n",
ahuang11 marked this conversation as resolved.
Show resolved Hide resolved
"import panel as pn\n",
"from panel.widgets import ChatEntry\n",
"from panel.chat import ChatEntry\n",
"\n",
"pn.extension()\n"
]
Expand Down Expand Up @@ -175,7 +175,7 @@
"metadata": {},
"outputs": [],
"source": [
"chat_entry = pn.widgets.ChatEntry()\n",
"chat_entry = pn.chat.ChatEntry()\n",
"chat_entry"
]
},
Expand Down Expand Up @@ -266,7 +266,7 @@
"metadata": {},
"outputs": [],
"source": [
"pn.widgets.ChatEntry(timestamp_format=\"%b %d, %Y %I:%M %p\")"
"pn.chat.ChatEntry(timestamp_format=\"%b %d, %Y %I:%M %p\")"
]
},
{
Expand Down Expand Up @@ -328,7 +328,7 @@
"metadata": {},
"outputs": [],
"source": [
"pn.widgets.ChatEntry(value=\"Love this!\", reactions=[\"favorite\"])"
"pn.chat.ChatEntry(value=\"Love this!\", reactions=[\"favorite\"])"
]
},
{
Expand All @@ -344,7 +344,7 @@
"metadata": {},
"outputs": [],
"source": [
"entry = pn.widgets.ChatEntry(\n",
"entry = pn.chat.ChatEntry(\n",
" value=\"Looks good!\",\n",
" reactions=[\"like\"],\n",
" reaction_icons={\"like\": \"thumb-up\", \"dislike\": \"thumb-down\"},\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"metadata": {},
"outputs": [],
"source": [
"chat_feed = pn.widgets.ChatFeed()\n",
"chat_feed = pn.chat.ChatFeed()\n",
"chat_feed"
]
},
Expand Down Expand Up @@ -147,9 +147,9 @@
"metadata": {},
"outputs": [],
"source": [
"pn.widgets.ChatFeed(value=[\n",
" pn.widgets.ChatEntry(value=\"I'm an emoji!\", avatar=\"🤖\"),\n",
" pn.widgets.ChatEntry(value=\"I'm an image!\", avatar=\"https://upload.wikimedia.org/wikipedia/commons/6/63/Yumi_UBports.png\"),\n",
"pn.chat.ChatFeed(value=[\n",
" pn.chat.ChatEntry(value=\"I'm an emoji!\", avatar=\"🤖\"),\n",
" pn.chat.ChatEntry(value=\"I'm an image!\", avatar=\"https://upload.wikimedia.org/wikipedia/commons/6/63/Yumi_UBports.png\"),\n",
"])"
]
},
Expand Down Expand Up @@ -187,7 +187,7 @@
"def echo_message(contents, user, instance):\n",
" return f\"Echoing... {contents}\"\n",
"\n",
"chat_feed = pn.widgets.ChatFeed(callback=echo_message)\n",
"chat_feed = pn.chat.ChatFeed(callback=echo_message)\n",
"chat_feed"
]
},
Expand All @@ -213,7 +213,7 @@
"metadata": {},
"outputs": [],
"source": [
"chat_feed = pn.widgets.ChatFeed(callback=echo_message, callback_user=\"Echo Bot\")\n",
"chat_feed = pn.chat.ChatFeed(callback=echo_message, callback_user=\"Echo Bot\")\n",
"chat_feed"
]
},
Expand Down Expand Up @@ -242,7 +242,7 @@
"def parrot_message(contents, user, instance):\n",
" return {\"value\": f\"No, {contents.lower()}\", \"user\": \"Parrot\", \"avatar\": \"🦜\"}\n",
"\n",
"chat_feed = pn.widgets.ChatFeed(callback=parrot_message, callback_user=\"Echo Bot\")\n",
"chat_feed = pn.chat.ChatFeed(callback=parrot_message, callback_user=\"Echo Bot\")\n",
"chat_feed"
]
},
Expand Down Expand Up @@ -289,7 +289,7 @@
"def bad_callback(contents, user, instance):\n",
" return 1 / 0\n",
"\n",
"chat_feed = pn.widgets.ChatFeed(callback=bad_callback, callback_exception=\"summary\")\n",
"chat_feed = pn.chat.ChatFeed(callback=bad_callback, callback_exception=\"summary\")\n",
"chat_feed"
]
},
Expand Down Expand Up @@ -325,7 +325,7 @@
" await asyncio.sleep(2.8)\n",
" return {\"value\": f\"No, {contents.lower()}\", \"user\": \"Parrot\", \"avatar\": \"🦜\"}\n",
"\n",
"chat_feed = pn.widgets.ChatFeed(callback=parrot_message, callback_user=\"Echo Bot\")\n",
"chat_feed = pn.chat.ChatFeed(callback=parrot_message, callback_user=\"Echo Bot\")\n",
"chat_feed"
]
},
Expand Down Expand Up @@ -361,7 +361,7 @@
" message += character\n",
" yield message\n",
"\n",
"chat_feed = pn.widgets.ChatFeed(callback=stream_message)\n",
"chat_feed = pn.chat.ChatFeed(callback=stream_message)\n",
"chat_feed"
]
},
Expand Down Expand Up @@ -392,7 +392,7 @@
" await asyncio.sleep(0.1)\n",
" yield character\n",
"\n",
"chat_feed = pn.widgets.ChatFeed(callback=replace_message)\n",
"chat_feed = pn.chat.ChatFeed(callback=replace_message)\n",
"chat_feed"
]
},
Expand Down Expand Up @@ -428,7 +428,7 @@
" message += chunk[\"choices\"][0][\"delta\"].get(\"content\", \"\")\n",
" yield message\n",
"\n",
"chat_feed = pn.widgets.ChatFeed(callback=openai_callback)\n",
"chat_feed = pn.chat.ChatFeed(callback=openai_callback)\n",
"chat_feed.send(\"Have you heard of HoloViz Panel?\")\n",
"```\n",
"\n",
Expand Down Expand Up @@ -466,7 +466,7 @@
" }\n",
"\n",
"\n",
"chat_feed = pn.widgets.ChatFeed(callback=chain_message)\n",
"chat_feed = pn.chat.ChatFeed(callback=chain_message)\n",
"chat_feed"
]
},
Expand Down Expand Up @@ -514,7 +514,7 @@
" instance.respond()\n",
"\n",
"\n",
"chat_feed = pn.widgets.ChatFeed(callback=openai_self_chat, sizing_mode=\"stretch_width\", height=1000).servable()\n",
"chat_feed = pn.chat.ChatFeed(callback=openai_self_chat, sizing_mode=\"stretch_width\", height=1000).servable()\n",
"chat_feed.send(\"What is HoloViz Panel?\")\n",
"```\n",
"\n",
Expand All @@ -534,7 +534,7 @@
"metadata": {},
"outputs": [],
"source": [
"chat_feed = pn.widgets.ChatFeed()\n",
"chat_feed = pn.chat.ChatFeed()\n",
"\n",
"# creates a new entry\n",
"entry = chat_feed.stream(\"Hello\", user=\"Aspiring User\", avatar=\"🤓\")\n",
Expand Down Expand Up @@ -564,7 +564,7 @@
"metadata": {},
"outputs": [],
"source": [
"chat_feed = pn.widgets.ChatFeed()\n",
"chat_feed = pn.chat.ChatFeed()\n",
"chat_feed"
]
},
Expand Down Expand Up @@ -596,7 +596,7 @@
"entry_params = dict(\n",
" default_avatars={\"System\": \"S\", \"User\": \"👤\"}, reaction_icons={\"like\": \"thumb-up\"}\n",
")\n",
"chat_feed = pn.widgets.ChatFeed(entry_params=entry_params)\n",
"chat_feed = pn.chat.ChatFeed(entry_params=entry_params)\n",
"chat_feed.send(user=\"System\", value=\"This is the System speaking.\")\n",
"chat_feed.send(user=\"User\", value=\"This is the User speaking.\")\n",
"chat_feed"
Expand All @@ -619,7 +619,7 @@
"source": [
"import asyncio\n",
"import panel as pn\n",
"from panel.widgets.chat import ChatEntry, ChatFeed\n",
"from panel.chat import ChatEntry, ChatFeed\n",
"\n",
"pn.extension()\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"outputs": [],
"source": [
"import panel as pn\n",
"from panel.widgets import ChatInterface\n",
"from panel.chat import ChatInterface\n",
"\n",
"pn.extension()"
]
Expand Down Expand Up @@ -275,7 +275,7 @@
" instance.active = 0 # Change to TextAreaInput tab\n",
" return f\"Got {num}.\"\n",
"\n",
"pn.widgets.ChatInterface(\n",
"pn.chat.ChatInterface(\n",
" callback=guided_get_num,\n",
" widgets=[\n",
" pn.widgets.TextAreaInput(placeholder=\"Enter some text to get a count!\"),\n",
Expand Down Expand Up @@ -311,7 +311,7 @@
" pn.widgets.TextAreaInput(placeholder=\"Enter some text to get a count!\"),\n",
" pn.widgets.IntSlider(name=\"Number Input\", end=10)\n",
"]\n",
"pn.widgets.ChatInterface(\n",
"pn.chat.ChatInterface(\n",
" callback=get_num_guided,\n",
" widgets=widgets[0],\n",
")"
Expand All @@ -334,7 +334,7 @@
" pn.widgets.TextAreaInput(placeholder=\"Enter some text to get a count!\"),\n",
" pn.widgets.IntSlider(name=\"Number Input\", end=10)\n",
"]\n",
"chat_interface = pn.widgets.ChatInterface(\n",
"chat_interface = pn.chat.ChatInterface(\n",
" widgets=widgets,\n",
")\n",
"print(chat_interface.active_widget)"
Expand All @@ -355,7 +355,7 @@
"metadata": {},
"outputs": [],
"source": [
"pn.widgets.ChatInterface(\n",
"pn.chat.ChatInterface(\n",
" widgets=pn.widgets.TextAreaInput(),\n",
" reset_on_send=False,\n",
")"
Expand All @@ -376,7 +376,7 @@
"metadata": {},
"outputs": [],
"source": [
"pn.widgets.ChatInterface(callback=get_num, show_rerun=False, show_undo=False)"
"pn.chat.ChatInterface(callback=get_num, show_rerun=False, show_undo=False)"
]
},
{
Expand All @@ -392,7 +392,7 @@
"metadata": {},
"outputs": [],
"source": [
"pn.widgets.ChatInterface(callback=get_num, show_button_name=False, width=400)"
"pn.chat.ChatInterface(callback=get_num, show_button_name=False, width=400)"
]
}
],
Expand Down
2 changes: 2 additions & 0 deletions panel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"""
from param import rx

from . import chat # noqa
from . import layout # noqa
from . import links # noqa
from . import pane # noqa
Expand Down Expand Up @@ -74,6 +75,7 @@
"__version__",
"Accordion",
"Card",
"chat",
"Column",
"FlexBox",
"FloatPanel",
Expand Down
43 changes: 43 additions & 0 deletions panel/chat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Panel chat makes creating chat components easy
==============================================================

Check out the widget gallery
https://panel.holoviz.org/reference/index.html#chat for inspiration.

How to use Panel widgets in 3 simple steps
------------------------------------------

1. Define your function

>>> async def repeat_contents(contents, user, instance):
>>> yield contents

2. Define your widgets and callback.

>>> chat_interface = ChatInterface(callback=repeat_contents)

3. Layout the chat interface in a template

>>> template = pn.template.FastListTemplate(
>>> title="Panel Chat",
>>> main=[chat_interface],
>>> )
>>> template.servable()

For more detail see the Reference Gallery guide.
https://panel.holoviz.org/reference/chat/ChatInterface.html
"""
from .entry import ChatEntry # noqa
from .feed import ChatFeed # noqa
from .icon import ChatReactionIcons # noqa
from .interface import ChatInterface # noqa
from .langchain import PanelCallbackHandler # noqa

__all__ = (
"ChatEntry",
"ChatFeed",
"ChatInterface",
"ChatReactionIcons",
"PanelCallbackHandler",
)
Loading
Loading