Skip to content

Conversation

Copy link

Copilot AI commented Nov 4, 2025

Users currently must manually edit .env files and restart the application to configure API keys. This adds a settings page accessible from the sidebar that allows runtime configuration of OpenAI, Google Gemini, and Ollama credentials.

Changes

New Settings Module (src/ui/settings_page.py)

  • Expandable sections for each provider with password-masked inputs
  • Connection test functions validate credentials before saving
  • Settings stored in session state (memory-only, no disk persistence)
  • Updates environment variables and clears cached agents on save

Main App Integration (app.py)

  • Added "🔑 API Configuration" sidebar button
  • Conditional rendering: show_settings_page() when st.session_state.show_settings is True
  • Settings changes trigger automatic agent re-initialization

Security

SSRF Mitigation

  • URL validation restricts Ollama to localhost/127.0.0.1/'ollama' hostnames only
  • Enforces http/https schemes with 5-second timeouts
  • SSL verification enabled for non-localhost connections

Error Handling

  • Sanitized error messages prevent credential/info disclosure
  • Generic responses for authentication failures

Example Usage

# User clicks "🔑 API Configuration" in sidebar
# Enters OpenAI key: sk-proj-abc123... (displayed as ●●●●●●)
# Clicks "🔌 Test OpenAI" → validates key + model
# Clicks "💾 Save OpenAI Settings" → applies immediately
# Returns to chat with new credentials active

The implementation maintains consistency with existing architecture where client factories read from os.environ, documented for potential future refactoring to direct credential passing.

Original prompt

This section details on the original issue you should resolve

<issue_title>[FEATURE REQUEST] Add API Key Configuration UI</issue_title>
<issue_description>## Description
Add a settings screen or configuration panel in the user interface that allows users to configure API keys directly from the application, without needing to manually edit the .env file.

Motivation

Currently, to configure API keys (OpenAI, Ollama, etc.), users must:

  • Access the .env file
  • Manually modify environment variables
  • Restart the application

This process is unintuitive and not user-friendly, especially for non-technical users. A dedicated UI would make the application more accessible and streamline credential management.

Suggested implementation

The configuration screen could include:

  • A form with input fields for the main API keys (OpenAI API key, Ollama host, etc.)
  • Validation of inserted values
  • Secure storage of credentials (with encryption or secure in-memory management)
  • Ability to test the connection to APIs directly from the UI
  • Visual feedback on successful/failed configuration

The solution could be implemented as:

  • A dedicated settings page/modal in the application
  • Using a UI library (e.g., Streamlit widgets, or a dedicated web UI)
  • Credential management through a secure state variable
    </issue_description>

<agent_instructions>Use the Streamlit library</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add API key configuration UI for user settings Add API Key Configuration UI for Streamlit interface Nov 4, 2025
Copilot AI requested a review from merendamattia November 4, 2025 10:27
@merendamattia merendamattia marked this pull request as ready for review November 4, 2025 11:01
Copilot AI review requested due to automatic review settings November 4, 2025 11:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive API key configuration interface to allow users to configure LLM provider credentials (OpenAI, Google Gemini, Ollama) through the Streamlit UI instead of manually editing the .env file. The settings page includes connection testing, in-memory credential storage, and security validations for Ollama URLs.

Key changes:

  • New settings page UI with API key configuration for all supported providers
  • Connection testing functions for each provider with sanitized error messages
  • Modified provider selection logic to validate API keys before showing providers
  • Initial settings prompt when no providers are configured

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/ui/settings_page.py New module providing settings UI with API key configuration, connection tests, and security validations
app.py Integration of settings page with provider validation, new API key validity checks, and initial settings flow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@merendamattia merendamattia merged commit 8ea5290 into main Nov 5, 2025
5 checks passed
@merendamattia merendamattia deleted the copilot/add-api-key-configuration-ui branch November 5, 2025 08:13
@merendamattia
Copy link
Owner

🎉 This PR is included in version 1.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Add API Key Configuration UI

2 participants