|
@@ -3,7 +3,9 @@ from typing import List, Tuple
|
|
|
|
|
|
from langchain.chains import ConversationChain
|
|
|
from langchain.chat_models import ChatOpenAI
|
|
|
+from log_callback_handler import NiceGuiLogElementCallbackHandler
|
|
|
|
|
|
+import nicegui.globals
|
|
|
from nicegui import Client, ui
|
|
|
|
|
|
OPENAI_API_KEY = 'not-set' # TODO: set your OpenAI API key here
|
|
@@ -20,11 +22,13 @@ def chat_messages() -> None:
|
|
|
ui.chat_message(text=text, name=name, sent=name == 'You')
|
|
|
if thinking:
|
|
|
ui.spinner(size='3rem').classes('self-center')
|
|
|
- ui.run_javascript('window.scrollTo(0, document.body.scrollHeight)')
|
|
|
+ if nicegui.globals.get_client().has_socket_connection:
|
|
|
+ ui.run_javascript('window.scrollTo(0, document.body.scrollHeight)')
|
|
|
|
|
|
|
|
|
@ui.page('/')
|
|
|
-async def main(client: Client):
|
|
|
+async def main():
|
|
|
+
|
|
|
async def send() -> None:
|
|
|
global thinking
|
|
|
message = text.value
|
|
@@ -33,17 +37,27 @@ async def main(client: Client):
|
|
|
text.value = ''
|
|
|
chat_messages.refresh()
|
|
|
|
|
|
- response = await llm.arun(message)
|
|
|
+ response = await llm.arun(message, callbacks=[NiceGuiLogElementCallbackHandler(log)])
|
|
|
messages.append(('Bot', response))
|
|
|
thinking = False
|
|
|
chat_messages.refresh()
|
|
|
|
|
|
anchor_style = r'a:link, a:visited {color: inherit !important; text-decoration: none; font-weight: 500}'
|
|
|
ui.add_head_html(f'<style>{anchor_style}</style>')
|
|
|
- await client.connected()
|
|
|
|
|
|
- with ui.column().classes('w-full max-w-2xl mx-auto items-stretch'):
|
|
|
- chat_messages()
|
|
|
+ # the queries below are used to expand the contend down to the footer (content can then use flex-grow to expand)
|
|
|
+ ui.query('.q-page').classes('flex')
|
|
|
+ ui.query('.nicegui-content').classes('w-full')
|
|
|
+
|
|
|
+ with ui.tabs().classes('w-full') as tabs:
|
|
|
+ chat_tab = ui.tab('Chat')
|
|
|
+ logs_tab = ui.tab('Logs')
|
|
|
+ with ui.tab_panels(tabs, value=chat_tab).classes('w-full max-w-2xl mx-auto flex-grow items-stretch'):
|
|
|
+ with ui.tab_panel(chat_tab):
|
|
|
+ with ui.column().classes('w-full'):
|
|
|
+ chat_messages()
|
|
|
+ with ui.tab_panel(logs_tab):
|
|
|
+ log = ui.log().classes('w-full h-full')
|
|
|
|
|
|
with ui.footer().classes('bg-white'), ui.column().classes('w-full max-w-3xl mx-auto my-6'):
|
|
|
with ui.row().classes('w-full no-wrap items-center'):
|