from os import environ from utils.ai import ( retrieve_context, construct_prompt, get_remote_chat_response, ) import panel as pn pn.extension() MODEL = "gpt-3.5-turbo" query = "How do I trigger a function when clicking a button in Panel?" def seek(contents, user, instance): messages = instance.serialize()[1:-1] rag_context = retrieve_context(query, k=1, openai_api_key=environ["OPENAI_API_KEY"]) prompts = construct_prompt( messages, rag_context, model=MODEL, cite_sources=True, context_window=4097, ) message = None for response in get_remote_chat_response(prompts, model=MODEL): if response: message = instance.stream(response, user="Fleet", message=message) chat_interface = pn.chat.ChatInterface(callback=seek, callback_exception="verbose") chat_interface.send("Ask me anything about Python libraries!", user="Fleet", respond=False) template = pn.template.FastListTemplate(main=[chat_interface], title="Panel UI of Fleet Context") template.servable()