Skip to content

Commit a39d020

Browse files
committed
Merge branch '112-selectai-integration' of github.com:oracle-samples/ai-optimizer into 112-selectai-integration
2 parents c41dfc0 + e6c6163 commit a39d020

File tree

10 files changed

+74
-49
lines changed

10 files changed

+74
-49
lines changed

opentofu/iam.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2024, 2025, Oracle and/or its affiliates.
2+
# All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
# spell-checker: disable
4+
5+
resource "oci_identity_tag_namespace" "tag_namespace" {
6+
compartment_id = local.compartment_ocid
7+
description = format("%s Tag Namespace", local.label_prefix)
8+
name = local.label_prefix
9+
provider = oci.home_region
10+
}
11+
12+
resource "oci_identity_tag" "identity_tag" {
13+
description = format("%s Infrastructure", local.label_prefix)
14+
name = "infrastructure"
15+
tag_namespace_id = oci_identity_tag_namespace.tag_namespace.id
16+
provider = oci.home_region
17+
}
18+
19+
resource "oci_identity_dynamic_group" "resource_dynamic_group" {
20+
compartment_id = var.tenancy_ocid
21+
name = format("%s-dyngrp", local.label_prefix)
22+
description = format("%s Dynamic Group", local.label_prefix)
23+
matching_rule = format(
24+
"All {resource.compartment.id = '%s', tag.%s.value = '%s'}",
25+
local.compartment_ocid, local.identity_tag_key, local.label_prefix
26+
)
27+
provider = oci.home_region
28+
}
29+
30+
resource "oci_identity_policy" "adb_policies" {
31+
compartment_id = var.tenancy_ocid
32+
name = format("%s-adb-policy", var.label_prefix)
33+
description = format("%s - ADB", var.label_prefix)
34+
statements = [
35+
format("allow dynamic-group %s to use generative-ai-family in compartment id %s", oci_identity_dynamic_group.resource_dynamic_group.name, local.compartment_ocid),
36+
]
37+
provider = oci.home_region
38+
}

opentofu/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
locals {
77
compartment_ocid = var.compartment_ocid != "" ? var.compartment_ocid : var.tenancy_ocid
88
label_prefix = var.label_prefix != "" ? lower(var.label_prefix) : lower(random_pet.label.id)
9+
identity_tag_key = format("%s.%s", oci_identity_tag_namespace.tag_namespace.name, oci_identity_tag.identity_tag.name)
910
}
1011

1112
// Autonomous Database

opentofu/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ resource "oci_database_autonomous_database" "default_adb" {
7474
license_model = var.adb_license_model
7575
is_mtls_connection_required = true
7676
whitelisted_ips = local.adb_whitelist_cidrs
77+
defined_tags = { (local.identity_tag_key) = local.label_prefix }
7778
}
7879

7980
// Virtual Machine
@@ -112,6 +113,7 @@ module "kubernetes" {
112113
compartment_id = local.compartment_ocid
113114
vcn_id = module.network.vcn_ocid
114115
region = var.region
116+
dynamic_group = oci_identity_dynamic_group.resource_dynamic_group.name
115117
lb = oci_load_balancer_load_balancer.lb
116118
adb_id = oci_database_autonomous_database.default_adb.id
117119
adb_name = local.adb_name
@@ -130,6 +132,7 @@ module "kubernetes" {
130132
public_subnet_id = module.network.public_subnet_ocid
131133
private_subnet_id = module.network.private_subnet_ocid
132134
lb_nsg_id = oci_core_network_security_group.lb.id
135+
identity_tag_key = local.identity_tag_key
133136
providers = {
134137
oci.home_region = oci.home_region
135138
}

opentofu/modules/kubernetes/iam.tf

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,10 @@
22
# All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
33
# spell-checker: disable
44

5-
resource "oci_identity_tag_namespace" "tag_namespace" {
6-
compartment_id = var.compartment_id
7-
description = format("%s Tag Namespace", var.label_prefix)
8-
name = var.label_prefix
9-
provider = oci.home_region
10-
}
11-
12-
resource "oci_identity_tag" "identity_tag" {
13-
description = format("%s Infrastructure", var.label_prefix)
14-
name = "infrastructure"
15-
tag_namespace_id = oci_identity_tag_namespace.tag_namespace.id
16-
provider = oci.home_region
17-
}
18-
19-
resource "oci_identity_dynamic_group" "node_dynamic_group" {
20-
compartment_id = var.tenancy_id
21-
name = format("%s-workers-dyngrp", var.label_prefix)
22-
description = format("%s Dynamic Group - K8s Workers", var.label_prefix)
23-
matching_rule = format(
24-
"All {instance.compartment.id = '%s', tag.%s.value = '%s'}",
25-
var.compartment_id, local.identity_tag_key, local.identity_tag_val
26-
)
27-
provider = oci.home_region
28-
}
29-
30-
resource "oci_identity_policy" "workload_node_policies" {
5+
resource "oci_identity_policy" "workers_policies" {
316
compartment_id = var.tenancy_id
32-
name = format("%s-worker-workload-policy", var.label_prefix)
33-
description = format("%s PrincipleAuth - K8s Workers", var.label_prefix)
7+
name = format("%s-workers-policy", var.label_prefix)
8+
description = format("%s - K8s Workers", var.label_prefix)
349
statements = [
3510
format("allow any-user to manage autonomous-database-family in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'oracle-database-operator-system', request.principal.service_account = 'default', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
3611
format("allow any-user to read objectstorage-namespaces in compartment id %s where all {request.principal.type = 'workload', request.principal.service_account = 'default', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
@@ -52,7 +27,7 @@ resource "oci_identity_policy" "workload_node_policies" {
5227
format("allow any-user to manage waf-family in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
5328
format("allow any-user to read cluster-family in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
5429
format("allow any-user to use tag-namespaces in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
55-
format("allow dynamic-group %s to manage repos in compartment id %s", oci_identity_dynamic_group.node_dynamic_group.name, var.compartment_id),
30+
format("allow dynamic-group %s to manage repos in compartment id %s", var.dynamic_group, var.compartment_id),
5631
]
5732
provider = oci.home_region
5833
}

opentofu/modules/kubernetes/locals.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
// Region Mapping
66
locals {
7-
identity_tag_key = format("%s.%s", oci_identity_tag_namespace.tag_namespace.name, oci_identity_tag.identity_tag.name)
8-
identity_tag_val = var.label_prefix
97
region_map = {
108
for r in data.oci_identity_regions.identity_regions.regions : r.name => r.key
119
}

opentofu/modules/kubernetes/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ resource "oci_containerengine_cluster" "default_cluster" {
8484
}
8585
service_lb_subnet_ids = [var.public_subnet_id]
8686
}
87+
defined_tags = { (var.identity_tag_key) = var.label_prefix }
8788
freeform_tags = {
8889
"clusterName" = local.k8s_cluster_name
8990
}
@@ -146,7 +147,7 @@ resource "oci_containerengine_node_pool" "default_node_pool_details" {
146147
size = var.k8s_cpu_node_pool_size
147148
nsg_ids = [oci_core_network_security_group.k8s_workers.id]
148149
// Used for Instance Principles
149-
defined_tags = { (local.identity_tag_key) = local.identity_tag_val }
150+
defined_tags = { (var.identity_tag_key) = var.label_prefix }
150151
}
151152
node_eviction_node_pool_settings {
152153
eviction_grace_duration = "PT5M"
@@ -197,6 +198,8 @@ resource "oci_containerengine_node_pool" "gpu_node_pool_details" {
197198
}
198199
size = var.k8s_gpu_node_pool_size
199200
nsg_ids = [oci_core_network_security_group.k8s_workers.id]
201+
// Used for Instance Principles
202+
defined_tags = { (var.identity_tag_key) = var.label_prefix }
200203
}
201204
node_eviction_node_pool_settings {
202205
eviction_grace_duration = "PT5M"

opentofu/modules/kubernetes/variables.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ variable "label_prefix" {
4747
type = string
4848
}
4949

50+
variable "dynamic_group" {
51+
type = string
52+
}
53+
5054
variable "adb_id" {
5155
type = string
5256
}
@@ -100,4 +104,8 @@ variable "lb_nsg_id" {
100104
variable "k8s_api_endpoint_allowed_cidrs" {
101105
type = string
102106
default = ""
103-
}
107+
}
108+
109+
variable "identity_tag_key" {
110+
type = string
111+
}

src/client/content/chatbot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ async def main() -> None:
6767
st.stop()
6868
# the sidebars will set this to False if not everything is configured.
6969
state.enable_client = True
70+
st_common.tools_sidebar()
7071
st_common.history_sidebar()
7172
st_common.ll_sidebar()
72-
st_common.tools_sidebar()
73+
st_common.selectai_sidebar()
74+
st_common.vector_search_sidebar()
7375
# Stop when sidebar configurations not set
7476
if not state.enable_client:
7577
st.stop()

src/client/utils/st_common.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def update_settings():
249249
switch_prompt("sys", "Basic Example")
250250
else:
251251
tools = [
252-
("None", "Do not use tools", False),
252+
("LLM Only", "Do not use tools", False),
253253
("SelectAI", "Use AI with Structured Data", disable_selectai),
254254
("VectorSearch", "Use AI with Unstructured Data", disable_vector_search),
255255
]
@@ -277,7 +277,7 @@ def update_settings():
277277
tool_box = [name for name, _, disabled in tools if not disabled]
278278
# tool_cap = [desc for _, desc, disabled in tools if not disabled]
279279
if len(tool_box) > 1:
280-
st.sidebar.subheader("Tools", divider="red")
280+
st.sidebar.subheader("Toolkit", divider="red")
281281
tool_index = next(
282282
(
283283
i
@@ -287,7 +287,7 @@ def update_settings():
287287
),
288288
0,
289289
)
290-
st.sidebar.radio(
290+
st.sidebar.selectbox(
291291
"Tool Selection",
292292
tool_box,
293293
# captions=tool_cap,
@@ -298,9 +298,6 @@ def update_settings():
298298
)
299299
if state.selected_tool == "None":
300300
switch_prompt("sys", "Basic Example")
301-
selectai_sidebar()
302-
vector_search_sidebar()
303-
304301

305302
#####################################################
306303
# SelectAI Options

src/pyproject.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ authors = [
1414

1515
# Common dependencies that are always needed
1616
dependencies = [
17-
"langchain-core==0.3.59",
17+
"langchain-core==0.3.62",
1818
"httpx==0.28.1",
1919
"oracledb~=3.1",
20-
"plotly==6.0.1",
20+
"plotly==6.1.2",
2121
]
2222

2323
[project.optional-dependencies]
2424
# Server component dependencies
2525
# torch is installed via requirements for platform specifics
2626
server = [
27-
"bokeh==3.7.2",
27+
"bokeh==3.7.3",
2828
"evaluate==0.4.3",
2929
"fastapi==0.115.12",
3030
"faiss-cpu==1.11.0",
@@ -33,13 +33,13 @@ server = [
3333
"langchain-cohere==0.4.4",
3434
"langchain-community==0.3.24",
3535
"langchain-huggingface==0.2.0",
36-
"langchain-ollama==0.3.2",
37-
"langchain-openai==0.3.16",
38-
"langgraph==0.4.3",
39-
"litellm==1.69.2",
40-
"llama_index==0.12.36",
36+
"langchain-ollama==0.3.3",
37+
"langchain-openai==0.3.18",
38+
"langgraph==0.4.7",
39+
"litellm==1.71.1",
40+
"llama_index==0.12.37",
4141
"lxml==5.4.0",
42-
"matplotlib==3.10.1",
42+
"matplotlib==3.10.3",
4343
"oci~=2.0",
4444
"psutil==7.0.0",
4545
"python-multipart==0.0.20",

0 commit comments

Comments
 (0)