A Streamlit-based chat interface for interacting with Oracle Cloud Infrastructure (OCI) AI Digital Platform (AIDP) agents. This application provides an intuitive web interface for chat conversations with AIDP endpoints, with support for both local development and production deployment on OCI Container Instances.
- Interactive chat interface with conversation history
- Streaming responses: Real-time token-by-token display for more interactive experience
- Real-time communication with AIDP chat endpoints
- Comprehensive trace and span visualization for observability
- Support for multiple authentication modes:
- Local Development: OCI API Key or Security Token authentication
- OCI Container Instance: Resource Principal authentication
- Session management with configurable trace history
- Tree and table views for span analysis
- Prerequisites
- Local Development
- OCI Container Instance Deployment
- Configuration
- Customizing Prompt Templates
- Troubleshooting
- Python 3.9 or later
- OCI CLI configured with valid credentials (
~/.oci/config) - Access to an AIDP chat endpoint
- pip package manager
- OCI tenancy with appropriate permissions
- Docker installed locally for building images
- Access to OCI Container Registry (OCIR)
- AIDP chat endpoint URL
- Dynamic group and policy configuration for resource principal authentication
# Clone or navigate to the project directory
cd /path/to/chat_container_streamlite
# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtThe application automatically detects your OCI authentication method from your OCI config file.
Option A: API Key Authentication (Default)
Ensure your ~/.oci/config file contains:
[DEFAULT]
user=ocid1.user.oc1..aaaa...
fingerprint=xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
key_file=~/.oci/oci_api_key.pem
tenancy=ocid1.tenancy.oc1..aaaa...
region=us-ashburn-1Option B: Security Token Authentication
For security token-based authentication:
[DEFAULT]
user=ocid1.user.oc1..aaaa...
fingerprint=xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
key_file=~/.oci/oci_api_key.pem
security_token_file=~/.oci/token
tenancy=ocid1.tenancy.oc1..aaaa...
region=us-ashburn-1Set the AIDP chat endpoint URL as an environment variable:
export AIDP_CHAT_URL="https://your-aidp-endpoint.oci.oraclecloud.com/chat"Or configure it in the Streamlit sidebar after launching the application.
streamlit run aidp_streamlit_chat.py --server.port=8501Open your browser to http://localhost:8501 to access the chat interface.
- In the sidebar, verify or enter your AIDP Chat URL
- Optionally configure OCI profile settings (defaults to
DEFAULTprofile) - Toggle streaming mode: Enable or disable "Enable Streaming" checkbox for real-time token-by-token responses
- Click "Init Client" to initialize the connection
- Start chatting in the main panel
- View traces and spans in the sidebar's trace panel
- Streaming Enabled (default): Responses appear token-by-token as they're generated, providing immediate feedback and a more interactive experience
- Streaming Disabled: Responses appear all at once after generation completes, which may be faster for short responses
Both modes fully support trace visualization and conversation history.
This section covers deploying the application to OCI Container Instances with resource principal authentication.
# Navigate to project directory
cd /path/to/chat_container_streamlite
# Build the image
docker build -t aidp-chat-streamlit:latest .# Format: docker login <region-key>.ocir.io
# Username format: <tenancy-namespace>/<oci-username>
# Password: Auth token from OCI Console (Identity > Users > User Details > Auth Tokens)
docker login <region-key>.ocir.ioExample:
docker login us-ashburn-1.ocir.io
Username: mytenancy/john.doe@example.com
Password: <your-auth-token>Common region keys:
us-ashburn-1.ocir.io(Ashburn)us-phoenix-1.ocir.io(Phoenix)uk-london-1.ocir.io(London)ap-tokyo-1.ocir.io(Tokyo)
# Tag the image
docker tag aidp-chat-streamlit:latest \
<region-key>.ocir.io/<tenancy-namespace>/aidp-chat-streamlit:latest
# Push to OCIR
docker push <region-key>.ocir.io/<tenancy-namespace>/aidp-chat-streamlit:latestExample:
docker tag aidp-chat-streamlit:latest \
us-ashburn-1.ocir.io/mytenancy/aidp-chat-streamlit:latest
docker push us-ashburn-1.ocir.io/mytenancy/aidp-chat-streamlit:latestThe container instance needs a resource principal to authenticate with AIDP endpoints.
- Navigate to Identity & Security > Domains > Default Domain > Dynamic Groups
- Click Create Dynamic Group
- Provide a name:
aidp-chat-container-instances - Description:
Dynamic group for AIDP chat container instances - Add matching rules:
Match all container instances in a specific compartment:
ALL {resource.type='computecontainerinstance', resource.compartment.id='ocid1.compartment.oc1..aaaa...'}
Match a specific container instance by OCID:
resource.id='ocid1.computecontainerinstance.oc1.iad.aaaa...'
Match by tag (recommended for production):
ALL {resource.type='computecontainerinstance', tag.app.name='aidp-chat'}
- Click Create
Copy the OCID of the created dynamic group - you'll need it for AIDP policy configuration.
The dynamic group needs to be granted access to the AIDP service. This can be done in two ways:
- Navigate to your AIDP Console (product-specific interface)
- Go to Permissions or Access Control
- Click Add Principal
- Select Dynamic Group
- Enter the dynamic group OCID or name:
aidp-chat-container-instances - Assign required permissions:
chat:invoke(required for chat endpoint access)session:read(optional, for session management)
- Click Save
- Navigate to AIDP Console > Roles
- Select or create a role (e.g.,
chat-user-role) - Ensure the role has necessary permissions:
chat:invoke- Any additional permissions required
- Go to Role Members or Principals
- Click Add Member
- Select Dynamic Group
- Choose
aidp-chat-container-instances - Click Add
-
Navigate to Developer Services > Container Instances
-
Click Create Container Instance
-
Provide basic information:
- Name:
aidp-chat-app - Compartment: Select your compartment
- Availability Domain: Choose an AD
- Shape: Select appropriate shape (e.g.,
CI.Standard.E4.Flex) - Configure shape (if applicable): Set OCPUs and memory
- Name:
-
Configure networking:
- Virtual Cloud Network: Select your VCN
- Subnet: Choose a public subnet (for internet access)
- Public IP: Enable (if you want direct access)
-
Add container:
- Container name:
chat-app - Image:
<region-key>.ocir.io/<tenancy-namespace>/aidp-chat-streamlit:latest - Image registry: Select OCIR
- Image pull authentication: Select appropriate auth method
- Container name:
-
Configure container:
- Port mapping: Add port
8501(TCP) - Environment variables:
AIDP_CHAT_URL=https://your-aidp-endpoint.oci.oraclecloud.com/chat
- Port mapping: Add port
-
Tagging (optional but recommended):
- Add tag:
app.name = aidp-chat(matches dynamic group rule)
- Add tag:
-
Review and click Create
oci container-instances container-instance create \
--compartment-id ocid1.compartment.oc1..aaaa... \
--availability-domain "AD-1" \
--shape "CI.Standard.E4.Flex" \
--shape-config '{"ocpus":1.0,"memory_in_gbs":8.0}' \
--vnics '[{"subnetId":"ocid1.subnet.oc1..aaaa...","isPublicIpAssigned":true}]' \
--containers '[{
"displayName":"chat-app",
"imageUrl":"us-ashburn-1.ocir.io/mytenancy/aidp-chat-streamlit:latest",
"environmentVariables":{
"AIDP_CHAT_URL":"https://your-aidp-endpoint.oci.oraclecloud.com/chat"
}
}]' \
--display-name "aidp-chat-app" \
--freeform-tags '{"app.name":"aidp-chat"}'-
Get the public IP of the container instance:
- In Console: Navigate to the container instance details
- Or via CLI:
oci container-instances container-instance get --container-instance-id <ocid>
-
Access the application:
http://<public-ip>:8501 -
For production, set up a load balancer with HTTPS:
- Create an OCI Load Balancer
- Configure backend set pointing to container instance IP:8501
- Set up SSL certificate
- Configure security lists/NSGs for load balancer
Once the container instance is running:
-
Access the Streamlit application via the public IP
-
In the sidebar, check the Status section
-
You should see:
π Auth Mode: Resource Principal (Container) -
Initialize the client and test chat functionality
-
If authentication fails, verify:
- Dynamic group rules match your container instance
- AIDP permissions are correctly configured
- Container instance has internet connectivity to reach AIDP endpoint
| Variable | Description | Required | Default |
|---|---|---|---|
AIDP_CHAT_URL |
Full URL to AIDP chat endpoint (must end with /chat) |
Yes | None |
OCI_CONFIG_FILE |
Path to OCI config file | No | ~/.oci/config |
OCI_CONFIG_PROFILE |
OCI profile name to use | No | DEFAULT |
OCI_RESOURCE_PRINCIPAL_VERSION |
Auto-set by OCI Container Instance | No | None |
Configure these settings in the Streamlit sidebar:
- AIDP Chat URL: Full endpoint URL for AIDP chat service
- OCI Config File: Override default OCI config location (local mode only)
- OCI Profile: Select which profile to use from config (local mode only)
The application automatically detects the authentication mode:
-
Resource Principal (Container Instance):
- Automatically used when
OCI_RESOURCE_PRINCIPAL_VERSIONenvironment variable is present - No configuration file needed
- Requires dynamic group and AIDP policy configuration
- Automatically used when
-
API Key (Local):
- Uses standard OCI config file
- Detected when config has
user,fingerprint,key_file
-
Security Token (Local):
- Uses OCI config with security token
- Detected when config has
security_token_file
The application supports customizable prompt templates loaded from a JSON file. This allows you to define frequently-used prompts with variable placeholders.
Create a prompt_templates.json file with this structure:
{
"Template Name": {
"template": "Your prompt text with {variable} placeholders",
"description": "Optional description"
}
}Example:
{
"Generate SQL Query": {
"template": "Generate a SQL query to {task}.\n\nTable schema:\n{schema}\n\nRequirements:\n{requirements}",
"description": "Create SQL queries based on requirements and schema"
}
}The app searches for prompt_templates.json in these locations (in order):
- Current working directory:
./prompt_templates.json - Application directory:
<app_dir>/prompt_templates.json - Docker mount:
/app/prompt_templates.json - Custom path:
$TEMPLATES_PATH/prompt_templates.json
- Edit
prompt_templates.jsonin the app directory - Click the "π Reload" button in the sidebar, or restart the app
- Your templates will appear in the template selector
Option 1: Mount a custom templates file
docker run -v /path/to/your/prompt_templates.json:/app/prompt_templates.json \
-p 8501:8501 \
-e AIDP_CHAT_URL="your-endpoint-url" \
your-image-nameOption 2: Use custom path with environment variable
docker run -v /path/to/templates:/custom/templates \
-e TEMPLATES_PATH=/custom/templates \
-e AIDP_CHAT_URL="your-endpoint-url" \
-p 8501:8501 \
your-image-nameOption 3: Build with custom templates
FROM your-image-name
COPY my_custom_templates.json /app/prompt_templates.jsonThe app includes two sets of pre-built templates:
Perfect for beginners and everyday data tasks (15 templates):
- Getting Started - Learn data concepts
- Explore Dataset - Understand new data
- Simple Data Summary - Quick insights
- Basic SQL Query - Generate queries
- Visualize Data - Choose charts
- Find Patterns - Discover relationships
- Clean Data - Fix data issues
- Compare Groups - Analyze differences
- Calculate Metrics - Compute KPIs
- Data Question - Ask anything
- Predict Outcome - Make forecasts
- Interpret Results - Understand outputs
- Join Tables - Combine data
- Filter Data - Find specific records
- Handle Missing Data - Deal with nulls
See GETTING_STARTED.md for detailed usage examples!
For ML engineers and data scientists (15 templates):
- Generate SQL Query (complex)
- Explain Model Results
- Data Quality Check
- Feature Engineering
- Optimize Pipeline
- Debug Model Performance
- Compare Models
- Data Transformation
- Analyze Time Series
- RAG Query Optimization
- Hyperparameter Tuning
- A/B Test Analysis
- Production Deployment
- Data Drift Detection
- Cost Optimization
To use advanced templates: Copy prompt_templates.advanced.json to prompt_templates.json
Use {variable_name} in templates for user-provided values. The app automatically detects variables and creates input fields.
Example usage:
- Select "Generate SQL Query" template
- Fill in
{task},{schema},{requirements} - Click "π€ Use Template"
- Click "π€ Send" to submit to the AI
For more details, see TEMPLATES.md.
Issue: "Failed to initialize AIDP client"
- Verify
~/.oci/configexists and is properly formatted - Check that key file path is correct and accessible
- Ensure OCI profile name matches config file section
- Validate network connectivity to OCI services
Issue: "Failed to create OCI signer"
- For API key auth: Verify fingerprint matches the key file
- For security token: Ensure token file exists and is not expired
- Check file permissions on key and token files
Issue: Chat endpoint returns 401/403
- Verify the OCI principal (user) has proper AIDP permissions
- Check that AIDP_CHAT_URL is correct and accessible
- Ensure the user/group has
chat:invokepermission in AIDP
Issue: Container fails to start
- Check container logs in OCI Console
- Verify image was pushed correctly to OCIR
- Ensure container has sufficient memory/CPU resources
Issue: "Resource Principal authentication failed"
- Verify dynamic group rules match the container instance
- Check that dynamic group has been added to AIDP permissions/role
- Confirm container instance is in the correct compartment
- Validate AIDP endpoint is reachable from container subnet
Issue: Cannot access application on port 8501
- Verify security list allows ingress on TCP port 8501
- Check NSG rules if using Network Security Groups
- Ensure container instance has public IP or is behind load balancer
- Confirm container is running: check status in Console
Issue: "Auth Mode: Resource Principal" not showing
- Check environment variables in container configuration
- Review container instance logs for startup errors
- Verify OCI_RESOURCE_PRINCIPAL_VERSION is set (auto-set by OCI)
Issue: Cannot reach AIDP endpoint from container
- Verify VCN has internet gateway and route table configured
- Check that subnet security lists allow outbound HTTPS (443)
- Ensure DNS resolution works in the container
- Test connectivity using a debug container in the same subnet
Issue: "Permission denied" when calling chat endpoint
- Verify dynamic group membership (instance OCID matches rules)
- Check AIDP console for policy assignments
- Ensure role (if used) has correct permissions
- Validate policy statements are in the correct compartment
Local Development:
User -> Streamlit App -> AIDPChatClient -> OCI SDK (API Key/Token) -> AIDP Endpoint
Container Instance:
User -> Streamlit App -> AIDPChatClient -> OCI SDK (Resource Principal) -> AIDP Endpoint
β
Dynamic Group -> AIDP Policies
- aidp_streamlit_chat.py: Main Streamlit UI application
- aidp_chat.py: AIDP client library with automatic auth detection
- Dockerfile: Container image definition
- requirements.txt: Python dependencies
- Never commit credentials: Keep OCI config and keys out of version control
- Use resource principals in production: Avoid embedding API keys in containers
- Principle of least privilege: Grant only necessary AIDP permissions
- Use private subnets: Place containers in private subnets with NAT gateway
- Enable HTTPS: Use load balancers with SSL termination for production
- Regular updates: Keep base images and dependencies updated
- Secret management: Use OCI Vault for sensitive configuration
- OCI Container Instances Documentation
- OCI Resource Principal Authentication
- OCI Dynamic Groups
- Streamlit Documentation
chat_container_streamlite/
βββ aidp_streamlit_chat.py # Main Streamlit application
βββ aidp_chat.py # AIDP client with auth handling
βββ requirements.txt # Python dependencies
βββ Dockerfile # Container build definition
βββ README.md # This file