File size: 1,977 Bytes
c0aa211 | 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 60 61 62 63 64 65 66 67 68 69 | # 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()
|