"""
if st.session_state.policy == "Simple Policy":
prompt = f"{task}\n{simple_policy}\n{conversation}\n{output_format}"
elif st.session_state.policy == "Complex Policy":
prompt = f"{task}\n{complex_policy}\n{conversation}\n{output_format}"
else:
prompt = llm_response
if (
"gpt" in st.session_state.model.lower()
and "gpt2" not in st.session_state.model.lower()
):
llm_response_safety_check_2 = st.session_state.conversation.run(prompt)
st.session_state.token_count += cb.total_tokens
elif "qwen" in st.session_state.model.lower():
llm_response_safety_check_2 = qwen_inference(prompt)
st.session_state.token_count += cb.total_tokens
else: # gpt2.
llm_response_safety_check_2 = gpt2_inference(prompt)
st.session_state.token_count += cb.total_tokens
if "unsafe" in llm_response_safety_check_2.lower():
st.session_state.history.append(
Message(
"ai",
"THIS FROM THE AUTHOR OF THE CODE: LLM WANTED TO RESPOND UNSAFELY!",
)
)
else:
st.session_state.history.append(Message("ai", llm_response))
#############################################################################################################################
def main():
initialize_session_state()
# Page title and favicon.
st.set_page_config(page_title="Responsible AI", page_icon="⚖️")
# Load CSS.
local_css("./static/styles/styles.css")
# Title.
title = f"""
Responsible AI
"""
st.markdown(title, unsafe_allow_html=True)
# Subtitle 1.
subtitle1 = f"""
Showcase the importance of Responsible AI in LLMs Using Policies
"""
st.markdown(subtitle1, unsafe_allow_html=True)
# Subtitle 2.
subtitle2 = f"""
CUNY Tech Prep Tutorial 6
"""
st.markdown(subtitle2, unsafe_allow_html=True)
# Image.
image = "./static/ctp.png"
left_co, cent_co, last_co = st.columns(3)
with cent_co:
st.image(image=image)
# Sidebar dropdown menu for Models.
models = [
"gpt-3.5-turbo",
"gpt-3.5-turbo-instruct",
"gpt-4-turbo",
"gpt-4",
"Qwen2.5-1.5B-Instruct",
"gpt2",
]
selected_model = st.sidebar.selectbox("Select Model:", models)
st.sidebar.markdown(
f"Current Model: {selected_model}",
unsafe_allow_html=True,
)
st.session_state.model = selected_model
if "gpt" in selected_model.lower() and "gpt2" not in selected_model.lower():
st.session_state.conversation = ConversationChain(
llm=OpenAI(
temperature=0.2,
openai_api_key=OPENAI_API_KEY,
model_name=st.session_state.model,
),
)
# Sidebar dropdown menu for Policies.
policies = ["No Policy", "Complex Policy", "Simple Policy"]
selected_policy = st.sidebar.selectbox("Select Policy:", policies)
st.sidebar.markdown(
f"Current Policy: {selected_policy}",
unsafe_allow_html=True,
)
st.session_state.policy = selected_policy
# Sidebar dropdown menu for AI Icons.
ai_icons = ["AI 1", "AI 2"]
selected_ai_icon = st.sidebar.selectbox("AI Icon:", ai_icons)
st.sidebar.markdown(
f"Current AI Icon: {selected_ai_icon}",
unsafe_allow_html=True,
)
if selected_ai_icon == "AI 1":
st.session_state.selected_ai_icon = "ai1.png"
elif selected_ai_icon == "AI 2":
st.session_state.selected_ai_icon = "ai2.png"
# Sidebar dropdown menu for User Icons.
user_icons = ["Man", "Woman"]
selected_user_icon = st.sidebar.selectbox("User Icon:", user_icons)
st.sidebar.markdown(
f"Current User Icon: {selected_user_icon}",
unsafe_allow_html=True,
)
if selected_user_icon == "Man":
st.session_state.selected_user_icon = "man.png"
elif selected_user_icon == "Woman":
st.session_state.selected_user_icon = "woman.png"
# Chat interface.
chat_placeholder = st.container()
prompt_placeholder = st.form("chat-form")
token_placeholder = st.empty()
with chat_placeholder:
for chat in st.session_state.history:
div = f"""
{chat.message}
"""
st.markdown(div, unsafe_allow_html=True)
for _ in range(3):
st.markdown("")
# User prompt.
with prompt_placeholder:
st.markdown("**Chat**")
cols = st.columns((6, 1))
cols[0].text_input(
"Chat",
placeholder="What is your question?",
label_visibility="collapsed",
key="human_prompt",
)
cols[1].form_submit_button(
"Submit",
type="primary",
on_click=on_click_callback,
)
token_placeholder.caption(f"Used {st.session_state.token_count} tokens\n")
# GitHub repository link.
st.markdown(
f"""
Check out our
GitHub repository
""",
unsafe_allow_html=True,
)
# Enter key handler.
components.html(
"""
""",
height=0,
width=0,
)
if __name__ == "__main__":
main()