Keeping your sales knowledge base up-to-date is crucial for fast-moving teams. Manual updates are slow and error-prone, but with AI and automation, you can streamline the process, ensure accuracy, and empower your sales force with the latest information. This tutorial walks you through building an automated pipeline that uses AI to extract, summarize, and update your sales knowledge base from various sources.
Prerequisites
- Basic Knowledge: Experience with Python, REST APIs, and Git.
- Tools & Services:
- Python 3.10+
- Pip (Python package manager)
- OpenAI API access (for GPT-4 or GPT-3.5)
- Access to your knowledge base platform's API (e.g., Confluence, Notion, Zendesk, or custom CMS)
- GitHub Actions or another CI/CD tool (optional, for automation)
- Accounts: API keys for OpenAI and your knowledge base provider.
1. Set Up Your Project Environment
-
Create a project directory:
mkdir ai-kb-automation && cd ai-kb-automation
-
Initialize a Python virtual environment:
python3 -m venv venv source venv/bin/activate
-
Install required Python packages:
pip install openai requests python-dotenv
-
Create a
.envfile for your API keys:touch .env
Add the following (replace with your keys):
OPENAI_API_KEY=sk-... KB_API_TOKEN=your_kb_api_token KB_API_URL=https://yourkb.example.com/api/
2. Collect Source Content for Updates
-
Identify your update sources.
Examples: Slack channels, sales call transcripts, CRM notes, product release docs.
-
Write a script to fetch new content.
Let's fetch recent product release notes from a public URL as an example:
import requests def fetch_release_notes(url): response = requests.get(url) response.raise_for_status() return response.text release_notes = fetch_release_notes("https://example.com/release-notes/latest") print(release_notes)Screenshot description: Terminal output showing the latest release notes text.
-
Save the content for processing:
with open("latest_release_notes.txt", "w") as f: f.write(release_notes)
3. Summarize and Structure Content with AI
-
Load your API key securely:
import os from dotenv import load_dotenv load_dotenv() openai_api_key = os.getenv("OPENAI_API_KEY") -
Write a function to summarize content using OpenAI:
import openai def summarize_content(text): response = openai.ChatCompletion.create( model="gpt-4", api_key=openai_api_key, messages=[ {"role": "system", "content": "You are a helpful assistant that summarizes product updates for a sales knowledge base."}, {"role": "user", "content": f"Summarize the following release notes for sales reps:\n{text}"} ], max_tokens=500, temperature=0.2, ) return response['choices'][0]['message']['content'] with open("latest_release_notes.txt") as f: notes = f.read() summary = summarize_content(notes) print(summary)Screenshot description: Terminal output showing a concise, bullet-point summary of release notes.
-
Save the AI summary:
with open("kb_update_summary.txt", "w") as f: f.write(summary)
4. Update the Knowledge Base via API
-
Configure your knowledge base API access.
Example: Updating a Confluence page via REST API.
-
Write a function to update the KB page:
import json kb_api_token = os.getenv("KB_API_TOKEN") kb_api_url = os.getenv("KB_API_URL") def update_kb_page(page_id, new_content): url = f"{kb_api_url}/content/{page_id}" headers = { "Authorization": f"Bearer {kb_api_token}", "Content-Type": "application/json" } # Fetch current version resp = requests.get(url, headers=headers) resp.raise_for_status() data = resp.json() current_version = data['version']['number'] # Prepare update payload = { "version": {"number": current_version + 1}, "title": data['title'], "type": "page", "body": { "storage": { "value": new_content, "representation": "storage" } } } # Update page update_resp = requests.put(url, headers=headers, data=json.dumps(payload)) update_resp.raise_for_status() return update_resp.json() with open("kb_update_summary.txt") as f: summary_content = f.read() result = update_kb_page(page_id="123456", new_content=summary_content) print(result)Screenshot description: Terminal output confirming the page update with a new version number.
5. Automate the Workflow (Optional: CI/CD Integration)
-
Create a shell script to run all steps:
#!/bin/bash source venv/bin/activate python fetch_release_notes.py python summarize_content.py python update_kb.py -
Set up a GitHub Actions workflow:
name: KB Automation on: schedule: - cron: '0 8 * * 1' # Every Monday at 8am UTC workflow_dispatch: jobs: update-kb: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.10' - name: Install dependencies run: pip install -r requirements.txt - name: Run automation script env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} KB_API_TOKEN: ${{ secrets.KB_API_TOKEN }} KB_API_URL: ${{ secrets.KB_API_URL }} run: bash run_automation.shScreenshot description: GitHub Actions dashboard showing a successful workflow run.
Common Issues & Troubleshooting
-
OpenAI API quota errors:
Ensure your API key is valid and you have sufficient quota. Check OpenAI usage dashboard. -
Knowledge base API authentication failures:
Double-check your API token and permissions. Try a simple GET request to verify access. -
Content formatting issues:
Some KB platforms require specific HTML/Markdown. Adjust therepresentationfield in your API payload accordingly. -
Rate limits:
Add error handling and retries if you hit rate limits. Consult your platform's API docs for guidance. -
Environment variable issues in CI/CD:
Ensure secrets are set up in your CI/CD provider and referenced correctly in your workflow YAML.
Next Steps
- Expand your automation to include multiple content sources (Slack, CRM, etc.).
- Use AI for entity extraction or tagging to improve searchability.
- Set up notifications (e.g., Slack or email) when the knowledge base updates.
- Monitor update success and log errors for audit trails.
- Experiment with different AI models for improved summarization.
