AI Chat Assistant
Configure the AI chat assistant safely for GitHub Pages using a proxy endpoint.
Table of Contents
AI Chat Assistant
Use the AI chat assistant with page-aware responses while keeping your GitHub Pages site static and secure.
Why Proxy Mode
GitHub Pages cannot run server-side code. If you call the OpenAI API directly from browser JavaScript, your key is exposed and CORS can fail.
The recommended approach is:
- Keep the site static on GitHub Pages.
- Send chat requests to your own proxy endpoint.
- Let the proxy hold the OpenAI key server-side.
Configuration
Add this to your production config:
ai_chat:
enabled: true
auth_mode: 'proxy'
proxy_ready: true
endpoint: 'https://your-proxy.example.com/v1/chat/completions'
strict_context: true
out_of_scope_message: "I can only answer from the content on this page."
Important Defaults
auth_mode: 'proxy'is the recommended mode.proxy_ready: falsekeeps the widget hidden unless your proxy is deployed.strict_context: truereduces hallucinations by grounding answers to the current page.
GitHub Pages Compatible Deployment Flow
- Deploy your proxy endpoint first.
- Set
proxy_ready: trueandendpointto that proxy URL. - Build and publish your Jekyll site as usual.
Example build command:
jekyll build --config _config.yml
No client-side OpenAI key is required in proxy mode.
Optional Direct Mode (Not Recommended)
Direct mode sends requests from the browser to the provider API and may expose secrets in static output.
ai_chat:
auth_mode: 'direct'
api_key: 'sk-...'
endpoint: 'https://api.openai.com/v1/chat/completions'
Use direct mode only for temporary local experiments.
Response Quality Improvements Included
The assistant now includes:
- Strict grounding: answers are constrained to page metadata and excerpt context.
- Out-of-scope fallback: returns a configured fallback message when context is missing.
- Safe markdown rendering: assistant output supports basic markdown formatting without unsafe HTML execution.
Troubleshooting
Widget does not appear
Check:
ai_chat.enabledistrue.- If using proxy mode,
proxy_readyistrue. - Your
endpointis reachable from the browser.
Requests fail in browser
Check:
- Proxy endpoint URL is correct.
- Proxy returns CORS headers for your site origin.
- Proxy can reach OpenAI and has a valid server-side API key.
Replies are too generic
Check:
strict_contextistrue.context_max_lengthis high enough for your page content.system_promptstill emphasizes page-only grounding.