Skip to main content

DeEscalation Scoring Module

PyPI version Python 3.10+ License: MIT

A Python module for evaluating escalation and de-escalation patterns in chat conversations using AI-powered scoring. Perfect for customer service, community management, and conflict resolution applications.

🚀 Features

  • AI-Powered Scoring: Analyze chat conversations for escalation levels (1-5 scale)
  • Flexible API Support: Works with Poe API, OpenAI, or any OpenAI-compatible endpoint
  • Multiple Input Formats: Handle string conversations or structured message arrays
  • Batch Processing: Score multiple conversations efficiently
  • Robust JSON Parsing: Automatic handling of LLM response parsing
  • Easy Integration: Simple API for developers and non-technical users
  • Coaching Tips: Get actionable suggestions for improving conversations

📦 Installation

pip install de-escalation-scoring-module

🔧 Quick Setup

export POE_API_KEY="your_poe_api_key_here"

2. Or use API key directly in code

from de_escalation_scoring import DeEscalationScorer

scorer = DeEscalationScorer(api_key="your_poe_api_key_here")

📚 Usage Examples

Basic Usage

from de_escalation_scoring import DeEscalationScorer, score_chat

# Using environment variable for API key
scorer = DeEscalationScorer()

# Score a simple message
result = scorer.score_conversation("Hello, how can I help you today?")
print(result)
# Output: {"score": 5, "reason": "Polite and helpful greeting", "coaching_tip": "Great start to build rapport"}

# Quick scoring function
result = score_chat("I'm really frustrated with this service!")
print(result)
# Output: {"score": 2, "reason": "Shows frustration and dissatisfaction", "coaching_tip": "Acknowledge the frustration and ask for specifics"}

Advanced Usage with Custom API

# Using OpenAI API instead of Poe
scorer = DeEscalationScorer(
    api_key="your_openai_api_key",
    base_url="https://api.openai.com/v1",
    model="gpt-4",
    system_prompt="Analyze conversations for de-escalation patterns and provide constructive feedback."
)

result = scorer.score_conversation("I understand your concern. Let me help you solve this.")

Conversation Thread Scoring

# Score a multi-message conversation
messages = [
    "This service is terrible!",
    "I'm sorry to hear about your experience. Can you tell me what specifically went wrong?",
    "Well, my order was delayed and nobody told me.",
    "I apologize for the delay and lack of communication. Let me check your order status right away."
]

result = scorer.score_message_thread(messages)
print(f"Score: {result['score']}/5")
print(f"Reason: {result['reason']}")
print(f"Tip: {result['coaching_tip']}")

Batch Processing

conversations = [
    "Thank you for your help!",
    "This is unacceptable!",
    "I appreciate your patience while we resolve this."
]

results = scorer.batch_score(conversations)
for i, result in enumerate(results):
    print(f"Conversation {i+1}: Score {result['score']}/5")

Structured Message Format

chat_history = [
    {"role": "user", "content": "I need help with my account"},
    {"role": "assistant", "content": "I'd be happy to help you with your account. What specific issue are you experiencing?"},
    {"role": "user", "content": "I can't log in and it's really frustrating"}
]

result = scorer.score_conversation(chat_history)

🎯 Use Cases

Customer Service

  • Real-time monitoring of support conversations
  • Quality assurance for customer service representatives
  • Training feedback for support teams
  • Escalation prediction to prevent conflicts

Community Management

  • Forum moderation assistance
  • Social media monitoring for brand reputation
  • Discord/Slack channel health monitoring
  • Online community wellness tracking

Conflict Resolution

  • Mediation support in dispute resolution
  • Communication coaching for better outcomes
  • De-escalation training programs
  • Workplace communication improvement

📊 Scoring System

Score Level Description Example
1 Highly Escalated Aggressive, hostile, threatening "This is ridiculous! I demand to speak to your manager now!"
2 Escalated Frustrated, angry, demanding "I'm really upset about this delay. This is unacceptable."
3 Neutral Matter-of-fact, neither calm nor agitated "I have a problem with my order. Can you help?"
4 Calm Polite, patient, understanding "I understand these things happen. How can we fix this?"
5 De-escalating Actively calming, empathetic, solution-focused "I appreciate your patience. Let me personally ensure this gets resolved."

🔑 API Configuration

Supported APIs

Poe API (Default)

scorer = DeEscalationScorer(
    api_key="your_poe_api_key",
    base_url="https://api.poe.com/v1",
    model="DeEscalationScoring"
)

OpenAI

scorer = DeEscalationScorer(
    api_key="your_openai_api_key",
    base_url="https://api.openai.com/v1",
    model="gpt-4"
)

Azure OpenAI

scorer = DeEscalationScorer(
    api_key="your_azure_api_key",
    base_url="https://your-resource.openai.azure.com/",
    model="gpt-4"
)

Custom/Local APIs

scorer = DeEscalationScorer(
    api_key="your_api_key",
    base_url="http://localhost:8000/v1",
    model="your-custom-model"
)

🛡️ Error Handling

try:
    result = scorer.score_conversation("Hello world")
    print(f"Score: {result['score']}")
except ValueError as e:
    print(f"JSON parsing error: {e}")
except Exception as e:
    print(f"API error: {e}")

🔧 Integration Examples

Flask Web Application

from flask import Flask, request, jsonify
from de_escalation_scoring import DeEscalationScorer

app = Flask(__name__)
scorer = DeEscalationScorer()

@app.route('/score', methods=['POST'])
def score_conversation():
    data = request.json
    result = scorer.score_conversation(data['conversation'])
    return jsonify(result)

Discord Bot

import discord
from de_escalation_scoring import DeEscalationScorer

scorer = DeEscalationScorer()

@bot.event
async def on_message(message):
    if not message.author.bot:
        result = scorer.score_conversation(message.content)
        if result['score'] <= 2:
            # Alert moderators for potential escalation
            await message.channel.send("🤖 Escalation detected. Moderator notified.")

Slack Integration

from slack_sdk import WebClient
from de_escalation_scoring import DeEscalationScorer

scorer = DeEscalationScorer()

def handle_message(event):
    text = event['text']
    result = scorer.score_conversation(text)
    
    if result['score'] <= 2:
        # Send coaching tip to manager
        client.chat_postMessage(
            channel="manager-alerts",
            text=f"Escalation detected. Coaching tip: {result['coaching_tip']}"
        )

🤖 For Non-Technical Users

If you're not a developer, you can still use this module by:

  1. Hiring a developer to integrate it into your existing systems
  2. Using AI coding assistants like ChatGPT, Claude, or GitHub Copilot
  3. Consulting with a technical specialist for custom integration

Sample Request for Developers:

"Please integrate the de-escalation-scoring-module into our customer service system. We need to monitor chat conversations and get alerts when escalation levels are high (score ≤ 2). The module is available on PyPI as 'de-escalation-scoring-module'."

📋 Requirements

  • Python 3.10 or higher
  • openai library for API communication
  • json-repair library for robust JSON parsing
  • Valid API key for your chosen AI service

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔄 Changelog

v0.1.1

  • Initial release
  • Support for Poe API and OpenAI-compatible endpoints
  • Batch processing capabilities
  • Comprehensive error handling
  • Multiple input format support

Made with ❤️ in Hackathon Hack the Divide

Metadata

Release files for de-escalation-scoring-module 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for de-escalation-scoring-module 0.1.1
File Size Uploaded
de_escalation_scoring_module-0.1.1.tar.gz 11.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for de-escalation-scoring-module 0.1.1
File Interpreter ABI Platform
de_escalation_scoring_module-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 22.5 kB

Release files / de_escalation_scoring_module-0.1.1.tar.gz

Download URL de_escalation_scoring_module-0.1.1.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7f4a20fba3681cdf11720f7294ca2a39a0fd7a3e801d604aa607bdefd7ab0bd4
BLAKE2b-256 checksum
How to use checksums
5ba3a50d66ac18c5e38656b2f4854fefd0322da57c8312e78398153f78cbacc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2025.

Transparency log

Release files / de_escalation_scoring_module-0.1.1-py3-none-any.whl

Download URL de_escalation_scoring_module-0.1.1-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
343670524fd7f36939927a34098dee441e1f3055189c4a191b6a66ff6d31d1f1
BLAKE2b-256 checksum
How to use checksums
79992cb1cdb1d92151ba249ff610fd5a4708a8d32f50344d14d1537fe2766532
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page