I made some progress:
import panel as pnci
from panel.chat import ChatMessage
pnci.extension() #In notebook
promptsGUI=[]
responsesGUI=[]
message_params = dict(
default_avatars = {"System": "☂️", "User": "👤", "Asker": "?", "EduBot" :pnci.pane.PNG('https://panel.pyviz.org/_images/JPG.png') }, # this does not apply to creating a ChatMessage. Does ChatFeed have a creation function?
reaction_icons = {},
show_user = True,
show_timestamp = False,
show_copy_icon = False,
sizing_mode = "scale_width",
)
STYLE = """
.avatar {
border-radius: 50% 20% / 10% 40%;;
margin-top: 0;
margin-left: 0;
margin-right: 0;
}
.left {
min-height: 10px;
height: 18px;
}
.center {
/* background-color: yellow; */
margin-right:0px;
width: calc(100% - 5px);
}
.message {
min-height: 15px;
}
.right {
margin-left: 0;
/* background-color: gray; */
}
"""
welcome= "Hi im Edubot, im here to help you...write your question please"
def system_response(contents: str, user: str, instance: pnci.chat.ChatInterface):
promptActualGUI=contents
promptsGUI.append(promptActualGUI)
# chat_history.append({'role':'user', 'content':f"{prompt}"})
#response = llama_chat_openaiGUI(promptsGUI, responsesGUI)
response ="hola" + promptActualGUI
responsesGUI.append(response)
if contents == welcome:
None
else:
response =f'The result is: {promptActualGUI}'
return response
gui = pnci.chat.ChatInterface( message_params=message_params,
show_rerun=False, show_undo=False,show_stop=False,
stylesheets=[STYLE],
#css_classes=[STYLE],
widgets=pnci.widgets.TextAreaInput( placeholder="Escribe tu pregunta aqui", auto_grow=True, max_rows=5 ),
height=400,
callback=system_response,
# avatar = pnci.pane.PNG('https://panel.pyviz.org/_images/JPG.png'),
user="Asker",
callback_user="EduBot"
)
# sending messages
initialmsg = gui.send( pnci.chat.ChatMessage( welcome,
avatar = "🤖",
stylesheets = [STYLE],
show_user = True,
show_timestamp = False,
show_copy_icon = False,
show_reaction_icons=False,
sizing_mode = "stretch_width",
user="EduBot",
))
initialmsg
gui
And this is the result:
1 - I made a trick to bypass the problem that the welcome or initial message got also a response of the system…with if the contents in callback function is the welcome message then does nothing, else returns the response…Hope someone could give me a better answer or solution…but for now works…
2 - Seem that message_params dont work very well, as the EduBot avatar is changed… if i delete the robot avatar in gui.send to generate initialmsg…then a E appears as avatar, instead the one defined in params ( perhaps a bug) ??
3 - In the callback function, seems callbac_user name EduBot, works fine, but the name and avatar of the user ( should be Asker and the avatar again is defined in params) doesnt work… It gets a user name that dont know where it cames from…
4 - tried to put all params in messsageparams avalaible i thought to all definitions and all chatinterface…but didnt work: show_user = True,
show_timestamp = False,
show_copy_icon = False,
show_reaction_icons=False,
has to be redefined again in gui.send…and i think you should avoid these params if they have already been declared/defined in the messageparams dict.
5 - Similar to 4 happens to show_rerun=False, show_undo=False,show_stop=False, in gui = pnci.chat.ChatInterface … i had to define again because if not it took another values than desired…
Wouldn be easier to have a messageparams defined at the begining/top of the code, and all the params stored there, and very ChatInterface or ChatMEssage take their values. If you want to change the predefined values then change it in the call.
Any help would be apreciated