Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation Update #26

Merged
merged 23 commits into from
Oct 2, 2024
Merged
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -11,20 +11,26 @@
### pip3 install -r app/requirements.txt

## Top-Level brings in the required dependencies, if adding modules, try to find the minimum required
giskard[llm]==2.15.1
giskard==2.15.1
bokeh==3.6.0
evaluate==0.4.3
faiss-cpu==1.8.0.post1
IPython==8.27.0
langchain_community==0.3.0
langchain_huggingface==0.1.0
langchain_ollama==0.2.0
langchain_openai==0.2.0
llama_index==0.11.10
langchain-community==0.3.1
langchain-huggingface==0.1.0
langchain-ollama==0.2.0
langchain-openai==0.2.1
llama_index==0.11.14
lxml==5.3.0
matplotlib==3.9.2
oci>=2.0.0
oracledb>=2.0.0
plotly==5.24.1
streamlit==1.38.0
umap-learn==0.5.6

## For Licensing Purposes... this ensures no GPU modules
## For Licensing Purposes; ensures no GPU modules are installed
## as part of langchain-huggingface
-f https://download.pytorch.org/whl/cpu/torch
torch==2.4.1+cpu ; sys_platform == "linux"
torch==2.2.2 ; sys_platform == "darwin"
torch==2.2.2 ; sys_platform == "darwin"
28 changes: 17 additions & 11 deletions app/src/content/chatbot.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
Copyright (c) 2023, 2024, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v1.0 as shown at http://oss.oracle.com/licenses/upl.
"""
# spell-checker:ignore streamlit, langchain, llms

import inspect

@@ -13,6 +14,7 @@
import modules.st_common as st_common
import modules.logging_config as logging_config
import modules.chatbot as chatbot
import modules.chatbot_server as chatbot_server

# History
from langchain_community.chat_message_histories import StreamlitChatMessageHistory
@@ -69,15 +71,15 @@ def show_refs(context):
#############################################################################
def main():
"""Streamlit GUI"""
# Initialise RAG
st_common.initialise_rag()
# Initialize RAG
st_common.initialize_rag()
# Setup History
chat_history = StreamlitChatMessageHistory(key="sandbox_chat_history")

#########################################################################
# Sidebar Settings
#########################################################################
enabled_llms = sum(model_info["enabled"] for model_info in state.lm_model_config.values())
enabled_llms = sum(model_info["enabled"] for model_info in state.ll_model_config.values())
if enabled_llms > 0:
with st.chat_message("ai"):
# Do not put this in the history as messages must alternate human/ai
@@ -89,34 +91,38 @@ def main():
)
if st.sidebar.button("Clear History", disabled=not enable_history):
chat_history.clear()
lm_model = st_common.lm_sidebar()
st.sidebar.divider()
ll_model = st_common.lm_sidebar()
else:
st.error("No chat models are configured and/or enabled.", icon="🚨")
st.stop()

# RAG
st_common.rag_sidebar()

# Chatbot
chatbot_server.chatbot_sidebar()

# Save
st_common.save_settings_sidebar()
#########################################################################
# Initialise the Client
# Initialize the Client
#########################################################################
if "initialised" not in state:
if "initialized" not in state:
if not state.rag_params["enable"] or all(
state.rag_params[key] for key in ["model", "chunk_size", "chunk_overlap", "distance_metric"]
):
try:
state.chat_manager = st_common.initialise_chatbot(lm_model)
state.initialised = True
state.chat_manager = st_common.initialize_chatbot(ll_model)
state.initialized = True
st_common.update_rag()
logger.debug("Force rerun to save state")
st.rerun()
except Exception as ex:
logger.exception(ex, exc_info=False)
st.error(f"Failed to initialise the chat client: {ex}")
st_common.clear_initialised()
if st.button("Retry", key="retry_initialise"):
st.error(f"Failed to initialize the chat client: {ex}")
st_common.clear_initialized()
if st.button("Retry", key="retry_initialize"):
st.rerun()
st.stop()

23 changes: 12 additions & 11 deletions app/src/content/db_config.py
Original file line number Diff line number Diff line change
@@ -5,11 +5,12 @@
This script initializes a web interface for database configuration using Streamlit (`st`).
It includes a form to input and test database connection settings.
"""
# spell-checker:ignore streamlit, oracledb

import inspect

import modules.logging_config as logging_config
import modules.db_utils as db_utils
import modules.utilities as utilities
import modules.st_common as st_common

import streamlit as st
@@ -21,26 +22,26 @@
#####################################################
# Functions
#####################################################
def initialise_streamlit():
"""Initialise the database configuration settings into Streamlit state"""
def initialize_streamlit():
"""Initialize the database configuration settings into Streamlit state"""
if "db_configured" in state:
return

state.db_config = db_utils.initialise()
state.db_config = utilities.db_initialize()
try:
db_utils.connect(state.db_config)
utilities.db_connect(state.db_config)
state.db_configured = True
except db_utils.oracledb.DatabaseError as ex:
except utilities.oracledb.DatabaseError as ex:
state.db_configured = False
logger.info("Unable to initialise database: %s", ex, exc_info=False)
logger.info("Unable to initialize database: %s", ex, exc_info=False)


#####################################################
# MAIN
#####################################################
def main():
"""Streamlit GUI"""
initialise_streamlit()
initialize_streamlit()
with st.form("Database Connectivity"):
user = st.text_input(
"Database User:",
@@ -71,14 +72,14 @@ def main():
st.stop()

try:
test_config = db_utils.initialise(user, password, dsn, wallet_password)
db_utils.connect(test_config)
test_config = utilities.db_initialize(user, password, dsn, wallet_password)
utilities.db_connect(test_config)
st.success("Database Connectivity Tested Successfully", icon="✅")
state.db_config = test_config
st.success("Database Configuration Saved", icon="✅")
state.db_configured = True
st_common.reset_rag()
except db_utils.oracledb.DatabaseError as ex:
except utilities.oracledb.DatabaseError as ex:
st.error(ex, icon="🚨")
state.db_configured = False

1 change: 1 addition & 0 deletions app/src/content/import_settings.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

This script allows importing/exporting configurations using Streamlit (`st`).
"""
# spell-checker:ignore streamlit

import inspect
import json
58 changes: 40 additions & 18 deletions app/src/content/model_config.py
Original file line number Diff line number Diff line change
@@ -4,11 +4,13 @@

This script initializes a web interface for model configuration using Streamlit (`st`).
"""
# spell-checker:ignore streamlit, llms, langchain, testid, vectorstores

import inspect

import modules.logging_config as logging_config
import modules.metadata as metadata
from modules.st_common import reset_rag

import streamlit as st
from streamlit import session_state as state
@@ -19,18 +21,27 @@
logger = logging_config.logging.getLogger("model_config")


def initialise_streamlit():
"""Initialise Streamlit Session State"""
def state_enabled_models():
"""Set state for enabled LLMs"""
if "ll_model_config" in state:
state.enabled_llms = list(key for key, value in state.ll_model_config.items() if value.get("enabled"))
logger.debug("Enabled LLMs: %s", state.enabled_llms)
state.enabled_embed = list(key for key, value in state.embed_model_config.items() if value.get("enabled"))
logger.debug("Enabled Embedding Models: %s", state.enabled_embed)


def initialize_streamlit():
"""initialize Streamlit Session State"""
## Embedding Model
if "embed_model_config" not in state:
state.embed_model_config = metadata.embedding_models()
logger.info("Initialised Embedding Model Config")
logger.info("initialized Embedding Model Config")

## Chat Model
if "lm_model_config" not in state:
state.lm_model_config = metadata.lm_models()
state.lm_model = list(state.lm_model_config.keys())[0]
logger.info("Initialised Language Model Config")
if "ll_model_config" not in state:
state.ll_model_config = metadata.ll_models()
state.ll_model = list(state.ll_model_config.keys())[0]
logger.info("initialized Language Model Config")

## Distance Metrics
if "distance_metric_config" not in state:
@@ -40,7 +51,10 @@ def initialise_streamlit():
"DOT_PRODUCT": [DistanceStrategy.EUCLIDEAN_DISTANCE],
"MAX_INNER_PRODUCT": [DistanceStrategy.MAX_INNER_PRODUCT],
}
logger.info("Initialised Distance Metric Config")
logger.info("initialized Distance Metric Config")

# Set Enabled State
state_enabled_models()


def get_class_name(class_ref):
@@ -55,19 +69,27 @@ def update_embed_model_config():
state.embed_model_config[model_name]["enabled"] = state[f"embed_{model_name}_enabled"]
state.embed_model_config[model_name]["url"] = state[f"embed_{model_name}_api_server"]
state.embed_model_config[model_name]["api_key"] = state[f"embed_{model_name}_api_key"]
# Reset RAG
reset_rag()
st.success("Embedding Model Configuration - Updated", icon="✅")

# Set Enabled State
state_enabled_models()

def update_lm_model_config():

def update_ll_model_config():
"""Update Language Model Configuration"""
for model_name, _ in state.lm_model_config.items():
state.lm_model_config[model_name]["enabled"] = state[f"lm_{model_name}_enabled"]
state.lm_model_config[model_name]["url"] = state[f"lm_{model_name}_api_server"]
state.lm_model_config[model_name]["api_key"] = state[f"lm_{model_name}_api_key"]
for model_name, _ in state.ll_model_config.items():
state.ll_model_config[model_name]["enabled"] = state[f"lm_{model_name}_enabled"]
state.ll_model_config[model_name]["url"] = state[f"lm_{model_name}_api_server"]
state.ll_model_config[model_name]["api_key"] = state[f"lm_{model_name}_api_key"]
# Re-init the chatbot
state.pop("initialised", None)
state.pop("initialized", None)
st.success("Language Model Configuration - Updated", icon="✅")

# Set Enabled State
state_enabled_models()


#############################################################################
# MAIN
@@ -83,10 +105,10 @@ def main():
"""
st.markdown(css, unsafe_allow_html=True)

initialise_streamlit()
initialize_streamlit()

st.header("Language Models")
with st.form("update_lm_model_config"):
with st.form("update_ll_model_config"):
# Create table header
table2_col_format = st.columns([0.08, 0.3, 0.2, 0.2, 0.2])
col1_2, col2_2, col3_2, col4_2, col5_2 = table2_col_format
@@ -97,7 +119,7 @@ def main():
col5_2.markdown("**<u>API Key</u>**", unsafe_allow_html=True)

# Create table rows
for model_name, config in state.lm_model_config.items():
for model_name, config in state.ll_model_config.items():
col1_2, col2_2, col3_2, col4_2, col5_2 = table2_col_format
col1_2.checkbox(
"Enabled",
@@ -133,7 +155,7 @@ def main():
type="password",
label_visibility="collapsed",
)
st.form_submit_button(label="Save", on_click=update_lm_model_config)
st.form_submit_button(label="Save", on_click=update_ll_model_config)

st.header("Embedding Models")
with st.form("update_embed_model_config"):
21 changes: 12 additions & 9 deletions app/src/content/oci_config.py
Original file line number Diff line number Diff line change
@@ -5,11 +5,12 @@
Script initializes a web interface for Oracle Cloud Infrastructure (OCI)
It includes a form to input and test OCI API Access.
"""
# spell-checker:ignore streamlit, ocid

import inspect

import modules.logging_config as logging_config
import modules.oci_utils as oci_utils
import modules.utilities as utilities

import streamlit as st
from streamlit import session_state as state
@@ -20,7 +21,7 @@
#####################################################
# Functions
#####################################################
def initialise_streamlit():
def initialize_streamlit():
"""
Initialize Oracle Cloud Infrastructure (OCI) configuration settings
This should only be run when state.oci_configured is not defined
@@ -30,11 +31,11 @@ def initialise_streamlit():

logger.info("Initializing OCI Configuration")
if "oci_config" not in state:
state.oci_config = oci_utils.initialise()
state.oci_config = utilities.oci_initialize()
try:
oci_utils.get_namespace(state.oci_config, retries=False)
utilities.oci_get_namespace(state.oci_config, retries=False)
state.oci_configured = True
except oci_utils.OciException as ex:
except utilities.OciException as ex:
logger.exception(ex, exc_info=False)
state.oci_configured = False

@@ -44,7 +45,7 @@ def initialise_streamlit():
#####################################################
def main():
"""Streamlit GUI"""
initialise_streamlit()
initialize_streamlit()
# TODO(gotsysdba) Add input for File and Profile

auth_sources = ["User", "Token"]
@@ -102,14 +103,16 @@ def main():
st.stop()

try:
test_config = oci_utils.initialise(user, fingerprint, tenancy, region, key_file, security_token_file)
test_config = utilities.oci_initialize(
user, fingerprint, tenancy, region, key_file, security_token_file
)
logger.debug("Testing OCI config: %s", test_config)
oci_utils.get_namespace(test_config, retries=False)
utilities.oci_get_namespace(test_config, retries=False)
st.success("OCI API Authentication Tested Successfully", icon="✅")
state.oci_config = test_config
st.success("OCI Configuration Saved", icon="✅")
state.oci_configured = True
except oci_utils.OciException as ex:
except utilities.OciException as ex:
logger.exception(ex, exc_info=False)
st.error(ex, icon="🚨")
state.oci_configured = False
Loading