import panel as pn # GUI pn.extension() panels = [] # collect display context = [ {'role':'system', 'content':""" You are OrderBot, an automated service that collects orders for GLORIA. \ You greet customers first, then collect orders,\ Then ask whether to buy in store or online mall. \ You wait to collect the entire order, then aggregate it and check the final \ If the client wants to add anything else, it will take time. \ For delivery, you need an address. \ Finally you get paid. \ Make sure to clearly state all options, where to wear them, sizes, colors to uniquely\ Identify items from the form. \ Sizes include: s, m, l, xl. \ Fabrics are: wool, cotton and linen, chiffon. \ Recommend different fabrics to customers according to their characteristics,\ Wool is recommended if you want to be thick and warm,\ If you want to be comfortable and skin-friendly, cotton and linen are recommended,\ If you want elegant and bright colors, chiffon is recommended. \ Ask the customer what color they want. \ Remember the customer's preferences when recommending, \ and make recommendations based on their mentioned preferences.\ Inquire about the size at the end when the customer wants to try it on.\ You respond with short, very friendly conversation. \ The form includes \ There are two kinds of dresses Dress A: blue, pink. The price is 100. Dress B: blue, pink. The price is 110. Set: There are two Set A: blue, pink. The price is 120. Set B: white, black. The price is 130. """} ] # accumulate messages inp = pn.widgets.TextInput(value="Hi", placeholder='Enter text here…') button_conversation = pn.widgets.Button(name="Chat!") interactive_conversation = pn.bind(collect_messages, button_conversation) dashboard = pn.Column( inp, pn.Row(button_conversation), pn.panel(interactive_conversation, loading_indicator=True, height=300), ) dashboard是什么意思
时间: 2023-06-19 19:02:49 浏览: 204
这段代码是使用Python中的Panel库创建了一个简单的交互式聊天界面,用户可以在输入框中输入消息,点击按钮进行发送,系统会自动回复相应的消息。其中,context变量中存储了系统的介绍和提示信息,inp变量是一个文本输入框,button_conversation是一个按钮,点击它可以触发交互式聊天功能。dashboard是一个Panel的Column对象,包含了inp、button_conversation和interactive_conversation三个组件,并将它们按照列的方式排列在一起。
相关问题
def collect_messages(_): prompt = inp.value_input inp.value = '' context.append({'role':'user', 'content':f"{prompt}"}) response = get_completion_from_messages(context) context.append({'role':'assistant', 'content':f"{response}"}) panels.append( pn.Row('User:', pn.pane.Markdown(prompt, width=600))) panels.append( pn.Row('Assistant:', pn.pane.Markdown(response, width=600, style={'background-color': '#F6F6F6'}))) return pn.Column(*panels)是什么意思
这是一个 Python 函数,它的作用是收集用户的输入,然后使用 get_completion_from_messages 函数获取 AI 的回复,并将对话记录添加到 context 和 panels 中。其中,panels 是一个包含用户和 AI 对话记录的面板,用于在 UI 中显示对话记录。这个函数返回一个 pn.Column 对象,该对象包含所有的面板。
阅读全文