Dear community,
On the chat examples page Panel Chat Examples , I see an example of the Image Generating Chatbot as shown in the snapshot below:
However, it is not available on GitHub GitHub - holoviz-topics/panel-chat-examples: Examples of Chat Bots using Panels chat features: Traditional, LLMs, AI Agents, LangChain, OpenAI etc . Could someone provide a lead to a chatbot example for generating images with OpenAI/LangChain in Panel?
Thank you,
Sergey
Thanks for raising that! I probably should add a DALL-E generator; here’s the code
import panel as pn
from openai import AsyncOpenAI
pn.extension()
async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
response = await aclient.images.generate(
model="dall-e-3",
prompt=contents,
n=1,
)
image_url = response.data[0].url
return pn.pane.Image(image_url)
aclient = AsyncOpenAI()
chat_interface = pn.chat.ChatInterface(
callback=callback,
callback_user="GPT-3.5",
help_text="Send a message to get a reply from GPT-3.5 Turbo!",
)
template = pn.template.FastListTemplate(
title="OpenAI GPT-3.5",
header_background="#212121",
main=[chat_interface],
)
template.servable()
Thank you, Andrew @ahuang11 ! That’s exactly what I needed. My further question would have been, “How can I switch between the text and image generator within one chat interface?” but it was already answered by you in Applicable Recipes - Panel Chat Examples , which could be easily adapted for this.
Sergey
1 Like
For others reference, you could have two separate Chat widgets
Or prompt for reference
Another version inspired by Marc’s
import panel as pn
import param
pn.extension()
class PreferenceInput(pn.widgets.CompositeWidget):
value = param.Parameter()
def __init__(self, **params):
super().__init__(**params)
self._preference_widget = pn.widgets.RadioBoxGroup(
options=["", "blue", "red", "green"], name="preference"
)
pn.bind(self._update_value, self._preference_widget, watch=True)
self._composite[:] = [
"What is…
Or have openai automatically decide whether it should generate an image using a classifier