File size: 10,628 Bytes
8791d59 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
"""
Type definitions for MCP (Model Context Protocol)
"""
from typing import Dict, Any, List, Optional, Union, TypedDict
from enum import Enum
from datetime import datetime
from pydantic import BaseModel, Field
# ==================== ENUMS ====================
class ModelType(str, Enum):
"""Types of models available"""
STANCE_DETECTION = "stance_detection"
KPA_MATCHING = "kpa_matching"
ARGUMENT_GENERATION = "argument_generation"
CHATBOT = "chatbot"
class StanceType(str, Enum):
"""Stance types"""
PRO = "PRO"
CON = "CON"
NEUTRAL = "NEUTRAL"
class KpaLabel(str, Enum):
"""KPA matching labels"""
APPARIE = "apparie"
NON_APPARIE = "non_apparie"
class ServiceStatus(str, Enum):
"""Service status"""
OPERATIONAL = "operational"
DEGRADED = "degraded"
MAINTENANCE = "maintenance"
OFFLINE = "offline"
class ToolCategory(str, Enum):
"""Tool categories"""
PREDICTION = "prediction"
GENERATION = "generation"
TRANSFORMATION = "transformation"
ANALYSIS = "analysis"
UTILITY = "utility"
# ==================== CORE TYPES ====================
class ResourceMetadata(TypedDict):
"""Metadata for a resource"""
uri: str
name: str
description: Optional[str]
mime_type: str
created_at: datetime
updated_at: datetime
tags: List[str]
class ToolMetadata(TypedDict):
"""Metadata for a tool"""
name: str
description: str
version: str
category: ToolCategory
input_schema: Dict[str, Any]
output_schema: Dict[str, Any]
rate_limit: Optional[int]
requires_auth: bool
class ModelMetadata(TypedDict):
"""Metadata for a model"""
model_id: str
model_type: ModelType
provider: str
version: str
description: str
capabilities: List[str]
parameters: Dict[str, Any]
hardware_requirements: Dict[str, Any]
# ==================== PREDICTION TYPES ====================
class PredictionInput(BaseModel):
"""Base class for prediction inputs"""
model_id: Optional[str] = Field(None, description="Specific model to use")
class StancePredictionInput(PredictionInput):
"""Input for stance prediction"""
topic: str = Field(..., min_length=5, max_length=500, description="Debate topic")
argument: str = Field(..., min_length=5, max_length=1000, description="Argument text")
class Config:
json_schema_extra = {
"example": {
"topic": "Climate change is the most pressing issue of our time",
"argument": "Renewable energy investments have created millions of jobs worldwide"
}
}
class KPAPredictionInput(PredictionInput):
"""Input for KPA prediction"""
argument: str = Field(..., description="Argument text")
key_point: str = Field(..., description="Key point to match")
class Config:
json_schema_extra = {
"example": {
"argument": "Renewable energy is cost-effective in the long term",
"key_point": "Economic benefits of green energy"
}
}
class BatchPredictionInput(BaseModel):
"""Input for batch predictions"""
items: List[Union[StancePredictionInput, KPAPredictionInput]]
batch_size: Optional[int] = Field(10, ge=1, le=100)
parallel: bool = Field(False, description="Process in parallel")
# ==================== GENERATION TYPES ====================
class ArgumentGenerationInput(BaseModel):
"""Input for argument generation"""
prompt: str = Field(..., description="Main topic or question")
context: Optional[str] = Field(None, description="Additional context")
stance: Optional[StanceType] = Field(StanceType.NEUTRAL, description="Desired stance")
length: Optional[str] = Field("medium", description="Argument length: short/medium/long")
style: Optional[str] = Field("persuasive", description="Writing style")
num_arguments: Optional[int] = Field(1, ge=1, le=5, description="Number of arguments to generate")
class Config:
json_schema_extra = {
"example": {
"prompt": "Should artificial intelligence be regulated?",
"stance": "PRO",
"context": "Focus on ethical considerations",
"length": "medium"
}
}
class CounterArgumentInput(BaseModel):
"""Input for counter-argument generation"""
original_argument: str = Field(..., description="Original argument to counter")
target_stance: StanceType = Field(..., description="Stance for counter-argument")
context: Optional[str] = Field(None, description="Additional context")
class Config:
json_schema_extra = {
"example": {
"original_argument": "AI regulation stifles innovation",
"target_stance": "CON",
"context": "Focus on safety and ethics"
}
}
# ==================== VOICE TYPES ====================
class AudioFormat(str, Enum):
"""Supported audio formats"""
WAV = "wav"
MP3 = "mp3"
M4A = "m4a"
OGG = "ogg"
class VoiceProfile(str, Enum):
"""Available voice profiles"""
ALIYAH = "Aaliyah-PlayAI"
ARIA = "Aria-PlayAI"
DEXTER = "Dexter-PlayAI"
FIONA = "Fiona-PlayAI"
class STTInput(BaseModel):
"""Input for speech-to-text"""
audio_format: AudioFormat = Field(AudioFormat.WAV, description="Audio format")
language: str = Field("en", description="Language code (en, fr, etc.)")
enable_timestamps: bool = Field(False, description="Include word timestamps")
class Config:
json_schema_extra = {
"example": {
"audio_format": "wav",
"language": "en",
"enable_timestamps": False
}
}
class TTSInput(BaseModel):
"""Input for text-to-speech"""
text: str = Field(..., description="Text to convert to speech")
voice: VoiceProfile = Field(VoiceProfile.ALIYAH, description="Voice to use")
format: AudioFormat = Field(AudioFormat.WAV, description="Output format")
speed: float = Field(1.0, ge=0.5, le=2.0, description="Speech speed")
pitch: float = Field(1.0, ge=0.5, le=2.0, description="Voice pitch")
class Config:
json_schema_extra = {
"example": {
"text": "Hello, this is a test of text-to-speech.",
"voice": "Aaliyah-PlayAI",
"format": "wav",
"speed": 1.0,
"pitch": 1.0
}
}
# ==================== RESPONSE TYPES ====================
class PredictionResult(BaseModel):
"""Base prediction result"""
prediction: Union[int, str]
confidence: float = Field(..., ge=0.0, le=1.0)
processing_time: Optional[float] = Field(None, description="Processing time in seconds")
class StancePredictionResult(PredictionResult):
"""Stance prediction result"""
predicted_stance: StanceType
probability_pro: float = Field(..., ge=0.0, le=1.0)
probability_con: float = Field(..., ge=0.0, le=1.0)
topic: str
argument: str
class KPAPredictionResult(PredictionResult):
"""KPA prediction result"""
label: KpaLabel
probabilities: Dict[KpaLabel, float]
argument: str
key_point: str
class GenerationResult(BaseModel):
"""Base generation result"""
generated_text: str
prompt: str
context: Optional[str]
parameters: Dict[str, Any]
generation_time: Optional[float]
class ArgumentGenerationResult(GenerationResult):
"""Argument generation result"""
stance: StanceType
length: str
style: str
coherence_score: Optional[float] = Field(None, ge=0.0, le=1.0)
class BatchResult(BaseModel):
"""Batch processing result"""
results: List[Union[StancePredictionResult, KPAPredictionResult, ArgumentGenerationResult]]
total_processed: int
successful: int
failed: int
average_confidence: Optional[float]
total_time: float
class ErrorResponse(BaseModel):
"""Error response"""
error: str
code: Optional[str]
details: Optional[Dict[str, Any]]
timestamp: datetime = Field(default_factory=datetime.now)
class HealthResponse(BaseModel):
"""Health check response"""
status: ServiceStatus
version: str
uptime: float
models: Dict[str, bool]
services: Dict[str, bool]
timestamp: datetime = Field(default_factory=datetime.now)
# ==================== TOOL EXECUTION TYPES ====================
class ToolExecutionContext(BaseModel):
"""Context for tool execution"""
tool_id: str
user_id: Optional[str]
session_id: Optional[str]
timestamp: datetime = Field(default_factory=datetime.now)
metadata: Optional[Dict[str, Any]]
class ToolExecutionResult(BaseModel):
"""Result of tool execution"""
success: bool
output: Optional[Dict[str, Any]]
error: Optional[str]
execution_time: float
context: ToolExecutionContext
# ==================== CONVERSATION TYPES ====================
class MessageRole(str, Enum):
"""Roles in conversation"""
USER = "user"
ASSISTANT = "assistant"
SYSTEM = "system"
class ConversationMessage(BaseModel):
"""Single message in conversation"""
role: MessageRole
content: str
timestamp: datetime = Field(default_factory=datetime.now)
metadata: Optional[Dict[str, Any]]
class ConversationState(BaseModel):
"""Conversation state"""
conversation_id: str
messages: List[ConversationMessage]
created_at: datetime
updated_at: datetime = Field(default_factory=datetime.now)
metadata: Dict[str, Any] = Field(default_factory=dict)
# ==================== EXPORT ====================
__all__ = [
# Enums
"ModelType",
"StanceType",
"KpaLabel",
"ServiceStatus",
"ToolCategory",
"AudioFormat",
"VoiceProfile",
"MessageRole",
# Input Types
"PredictionInput",
"StancePredictionInput",
"KPAPredictionInput",
"BatchPredictionInput",
"ArgumentGenerationInput",
"CounterArgumentInput",
"STTInput",
"TTSInput",
# Result Types
"PredictionResult",
"StancePredictionResult",
"KPAPredictionResult",
"GenerationResult",
"ArgumentGenerationResult",
"BatchResult",
# Response Types
"ErrorResponse",
"HealthResponse",
# Tool Types
"ToolExecutionContext",
"ToolExecutionResult",
# Conversation Types
"ConversationMessage",
"ConversationState",
# TypedDicts (for compatibility)
"ResourceMetadata",
"ToolMetadata",
"ModelMetadata"
] |