| # Example usage of StreamlitKani | |
| ######################## | |
| ##### 0 - load libs | |
| ######################## | |
| # kani_streamlit imports | |
| import kani_utils.kani_streamlit_server as ks | |
| # for reading API keys from .env file | |
| import os | |
| import dotenv # pip install python-dotenv | |
| # kani imports | |
| from kani.engines.openai import OpenAIEngine | |
| # load app-defined agents | |
| from agents import ICDBot | |
| # read API keys .env file (e.g. set OPENAI_API_KEY=.... in .env and gitignore .env) | |
| dotenv.load_dotenv() | |
| ######################## | |
| ##### 1 - Configuration | |
| ######################## | |
| # initialize the application and set some page settings | |
| # parameters here are passed to streamlit.set_page_config, | |
| # see more at https://docs.streamlit.io/library/api-reference/utilities/st.set_page_config | |
| # this function MUST be run first | |
| ks.initialize_app_config( | |
| show_function_calls = True, | |
| page_title = "ICDBot", | |
| page_icon = "🤖", # can also be a URL | |
| initial_sidebar_state = "expanded", # or "expanded" | |
| menu_items = { | |
| "Get Help": "https://github.com/.../issues", | |
| "Report a Bug": "https://github.com/.../issues", | |
| "About": "An AI agent with access to the ICD-10-CM vocabulary.", | |
| } | |
| ) | |
| ######################## | |
| ##### 2 - Define Agents | |
| ######################## | |
| # define an engine to use (see Kani documentation for more info) | |
| engine = OpenAIEngine(os.environ["OPENAI_API_KEY"], model="gpt-4o") | |
| # engine = OpenAIEngine(os.environ["OPENAI_API_KEY"], model="o1") | |
| # We also have to define a function that returns a dictionary of agents to serve | |
| # Agents are keyed by their name, which is what the user will see in the UI | |
| def get_agents(): | |
| return { | |
| "ICDBot": ICDBot(engine, prompt_tokens_cost = 0.005, completion_tokens_cost = 0.015), | |
| } | |
| # tell the app to use that function to create agents when needed | |
| ks.set_app_agents(get_agents) | |
| ######################## | |
| ##### 3 - Serve App | |
| ######################## | |
| ks.serve_app() | |