Team Integration Guide

Complete integration guides for backend, frontend, UX, and data science teams. Get your team up and running with SAMO-DL in minutes.

API Overview

Base URL
https://samo-unified-api-frrnetyhfa-uc.a.run.app

Available Endpoints

Health Check
GET /health

Check API status and model health

Emotion Detection
POST /predict

Analyze text and return detected emotions

Metrics
GET /metrics

Prometheus metrics for monitoring

Backend Integration Guide

Python (Flask/Django)

Integrate with Python web frameworks

  • Flask integration
  • Django integration
  • FastAPI support
Node.js (Express)

Integrate with Node.js applications

  • Express.js middleware
  • Error handling
  • Rate limiting

Quick Start

1
Install Dependencies
pip install requests
# or
npm install axios
2
Create Integration Function
import requests

def detect_emotion(text: str) -> dict:
    """Integrate with SAMO Emotion API"""
    try:
         response = requests.post(
            "https://samo-unified-api-frrnetyhfa-uc.a.run.app/analyze/journal",
            json={"text": text},
            headers={"Content-Type": "application/json"},
            timeout=10
        )
        response.raise_for_status()
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"API Error: {e}")
        return {"error": "Failed to analyze emotions"}

# Example usage
emotions = detect_emotion("I'm feeling excited about this project!")
print(emotions)  # [{"emotion": "excitement", "confidence": 0.92}]
3
Add Error Handling
def safe_emotion_detection(text: str) -> dict:
    """Safe emotion detection with comprehensive error handling"""
    if not text or len(text.strip()) == 0:
        return {"error": "Empty text provided"}
    
    if len(text) > 1000:
        return {"error": "Text too long (max 1000 characters)"}
    
    try:
        emotions = detect_emotion(text)
        if "error" in emotions:
            return emotions
        
        # Validate response format
        if not isinstance(emotions, list):
            return {"error": "Invalid response format"}
        
        return {"success": True, "emotions": emotions}
    except Exception as e:
        return {"error": f"Unexpected error: {str(e)}"}

Frontend Integration Guide

React

React hooks and components

  • Custom hooks
  • Error boundaries
  • Loading states
Vue.js

Vue composables and components

  • Composables
  • Reactive data
  • Error handling
Angular

Angular services and components

  • Injectable services
  • Observables
  • Error handling

React Integration Example

import React, { useState } from 'react';

// Custom hook for emotion detection
const useEmotionDetection = () => {
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState(null);
  const [emotions, setEmotions] = useState([]);

  const analyzeEmotion = async (text) => {
    setLoading(true);
    setError(null);
    
    try {
      const response = await fetch(
        'https://samo-unified-api-frrnetyhfa-uc.a.run.app/analyze/journal',
        {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ text, generate_summary: false })
        }
      );
      
      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
      }
      
      const data = await response.json();
      setEmotions(data);
    } catch (err) {
      setError(err.message);
    } finally {
      setLoading(false);
    }
  };

  return { analyzeEmotion, emotions, loading, error };
};

// React component
const EmotionAnalyzer = () => {
  const [text, setText] = useState('');
  const { analyzeEmotion, emotions, loading, error } = useEmotionDetection();

  const handleSubmit = (e) => {
    e.preventDefault();
    if (text.trim()) {
      analyzeEmotion(text);
    }
  };

  return (