Skip to content

Commit

Permalink
Closes #74
Browse files Browse the repository at this point in the history
  • Loading branch information
gotsysdba committed Jan 26, 2025
1 parent 12e9027 commit 8fe0c2e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
5 changes: 4 additions & 1 deletion app/common/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ class RagSettings(DatabaseVectorStorage):
default=0.5, ge=0.0, le=1.0, description="Degree of Diversity (for Maximal Marginal Relevance)"
)

class OciSettings(BaseModel):
"""OCI Settings"""
profile: Optional[str] = Field(default="DEFAULT", description="Oracle Cloud Settings Profile")

class Settings(BaseModel):
"""Server Settings"""
Expand All @@ -195,7 +198,7 @@ class Settings(BaseModel):
default_factory=PromptSettings, description="Prompt Engineering Settings"
)
rag: Optional[RagSettings] = Field(default_factory=RagSettings, description="RAG Settings")
oci_profile: Optional[str] = Field(default="DEFAULT", description="Oracle Cloud Settings Profile")
oci: Optional[OciSettings] = Field(default_factory=OciSettings, description="OCI Settings")


#####################################################
Expand Down
21 changes: 16 additions & 5 deletions app/sandbox/content/config/oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Session States Set:
- oci_config: Stores OCI Configuration
"""
# spell-checker:ignore streamlit, ocid
# spell-checker:ignore streamlit, ocid, selectbox

import inspect

Expand All @@ -33,11 +33,11 @@ def get_oci() -> dict[str, dict]:
api_url = f"{state.server['url']}:{state.server['port']}/v1/oci"
response = api_call.get(url=api_url)
state["oci_config"] = {
item["profile"]: {k: v if v is not None else None for k, v in item.items() if k != "profile"}
item["profile"]: {k: v if v is not None else None for k, v in item.items() if k != "profile"}
for item in response
}
logger.info("State created: state['oci_config']")
print(state['oci_config'])
print(state["oci_config"])
except api_call.ApiError as ex:
st.error(f"Unable to retrieve oci_configuration: {ex}", icon="🚨")
state["oci_config"] = {}
Expand Down Expand Up @@ -105,9 +105,20 @@ def main() -> None:
get_oci() # Create/Rebuild state
except api_call.ApiError:
st.stop()
# TODO(gotsysdba) Add select for profiles
profile = "DEFAULT"
st.subheader("Configuration")
# Set Default Profile
profile = state.user_settings["oci"]["profile"]
avail_profiles = [key for key in state.oci_config.keys() if key != "DEFAULT"]
avail_profiles = ["DEFAULT"] + avail_profiles
if len(avail_profiles) > 0:
st.selectbox(
"Profile:",
options=avail_profiles,
index=avail_profiles.index(profile),
key="selected_oci_profile",
on_change=st_common.update_user_settings,
args=("oci", "profile"),
)
token_auth = st.checkbox("Use token authentication?", value=False)
with st.form("update_oci_config"):
user = st.text_input(
Expand Down
12 changes: 6 additions & 6 deletions app/sandbox/content/tools/split_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@
@st.cache_data
def get_compartments() -> dict:
"""Get OCI Compartments; function for Streamlit caching"""
api_url = f"{OCI_API_ENDPOINT}/compartments/{state.user_settings['oci_profile']}"
api_url = f"{OCI_API_ENDPOINT}/compartments/{state.user_settings['oci']['profile']}"
response = api_call.get(url=api_url)
return response


@st.cache_data
def get_buckets(compartment: str) -> list:
"""Get OCI Buckets in selected compartment; function for Streamlit caching"""
api_url = f"{OCI_API_ENDPOINT}/buckets/{compartment}/{state.user_settings['oci_profile']}"
api_url = f"{OCI_API_ENDPOINT}/buckets/{compartment}/{state.user_settings['oci']['profile']}"
response = api_call.get(url=api_url)
return response


@st.cache_data
def get_bucket_objects(bucket: str) -> list:
"""Get OCI Buckets in selected compartment; function for Streamlit caching"""
api_url = f"{OCI_API_ENDPOINT}/objects/{bucket}/{state.user_settings['oci_profile']}"
api_url = f"{OCI_API_ENDPOINT}/objects/{bucket}/{state.user_settings['oci']['profile']}"
response = api_call.get(url=api_url)
return response

Expand Down Expand Up @@ -135,7 +135,7 @@ def main() -> None:
file_sources = ["OCI", "Local", "Web"]
get_oci()
try:
if not state.oci_config[state.user_settings["oci_profile"]].get("namespace"):
if not state.oci_config[state.user_settings[""]].get("namespace"):
raise KeyError
except (KeyError, TypeError):
st.warning("OCI is not configured, some functionality is disabled", icon="⚠️")
Expand Down Expand Up @@ -289,7 +289,7 @@ def main() -> None:
This button is disabled if there are no documents from the source bucket split with
the current split and embed options. Please Split and Embed to enable Vector Storage.
"""
st.text(f"OCI namespace: {state.oci_config[state.user_settings['oci_profile']]['namespace']}")
st.text(f"OCI namespace: {state.oci_config[state.user_settings['oci']['profile']]['namespace']}")
oci_compartments = get_compartments()
src_bucket_list = []
col2_1, col2_2 = st.columns([0.5, 0.5])
Expand Down Expand Up @@ -375,7 +375,7 @@ def main() -> None:

if file_source == "OCI":
# Download OCI Objects for Processing
api_url = f"{OCI_API_ENDPOINT}/objects/download/{src_bucket}/{state.user_settings['oci_profile']}"
api_url = f"{OCI_API_ENDPOINT}/objects/download/{src_bucket}/{state.user_settings['oci']['profile']}"
process_list = src_files_selected[src_files_selected["Process"]].reset_index(drop=True)
api_payload = {"json": process_list["File"].tolist()}

Expand Down

0 comments on commit 8fe0c2e

Please sign in to comment.