Spaces:
Sleeping
Sleeping
File size: 1,713 Bytes
37f6183 1962054 37f6183 1962054 5c01590 f37551c 37f6183 1962054 6cefc9f 1962054 37f6183 1962054 37f6183 f37551c 04b186b f37551c 37f6183 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import os
import sys
from shiny.express import input, ui
from all_rag_fns import do_rag
ui.page_opts(
title="Use Shiny to Run RAG on the previous R/Gov Talks",
fillable=True,
fillable_mobile=True,
)
oai_api_key = os.getenv("OPENAI_API_KEY")
with ui.layout_sidebar():
# Add radio buttons in the sidebar
with ui.sidebar():
ui.input_radio_buttons(
"model_choice",
"Select Model:",
choices={"gpt-4o-mini": "Cheaper", "gpt-4o": "More Accurate"},
selected="gpt-4o-mini",
)
# Create a chat instance and display it in the main panel
chat = ui.Chat(id="chat")
chat.ui()
ui.markdown(
"""
This app was created for Alan Feder's [talk at the 2024 R/Gov Conference](https://rstats.ai/gov.html).
The Github repository that houses all the code is [here](https://github.com/AlanFeder/rgov-2024) -- feel free to fork it and use it on your own!
"""
)
ui.hr() # Divider
ui.h3("Contact me!")
ui.img(src="https://raw.githubusercontent.com/AlanFeder/rgov-2024/refs/heads/main/AJF_Headshot.jpg", width="60px")
ui.markdown(
"""
[Email](mailto:[email protected]) | [Website](https://www.alanfeder.com/) | [LinkedIn](https://www.linkedin.com/in/alanfeder/) | [GitHub](https://github.com/AlanFeder)
"""
)
# Define a callback to run when the user submits a message
@chat.on_user_submit
async def _():
user_message = chat.user_input()
response, _ = do_rag(
user_input=user_message,
n_results=3,
stream=True,
oai_api_key=oai_api_key,
model_name=input.model_choice(),
)
# Append the response into the chat
await chat.append_message_stream(response)
|