__init__.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # -*- coding: utf-8 -*-
  2. """
  3. NLP Module für Trixy.
  4. Dieses Modul stellt die NLP-Infrastruktur für Intent-Erkennung
  5. und Antwortgenerierung bereit.
  6. Komponenten:
  7. - NLPProvider: Abstrakte Basisklasse für NLP-Backends
  8. - IntentRegistry: Globale Registry für verfügbare Intents
  9. - @intent: Dekorator zum Markieren von Intent-Handlern
  10. - IntentReceivedData / IntentResult: Datenklassen für Handler
  11. Verwendung:
  12. # Intent-Handler in einem Plugin definieren
  13. from trixy_core.nlp import intent, IntentReceivedData, IntentResult
  14. class MyPlugin(TrixyPlugin):
  15. @intent(
  16. "my_intent",
  17. slots={"param": str},
  18. examples=["mach das", "tu dies"]
  19. )
  20. async def handle_my_intent(self, data: IntentReceivedData) -> IntentResult:
  21. return IntentResult.success_with_response("Fertig!")
  22. # NLP-Provider implementieren
  23. from trixy_core.nlp import NLPProvider, NLPConfig, NLPContext, NLPResult
  24. class MyNLPProvider(NLPProvider):
  25. async def initialize(self, config: NLPConfig) -> bool:
  26. # Provider initialisieren
  27. return True
  28. async def process(self, context: NLPContext) -> NLPResult:
  29. # Text verarbeiten
  30. return NLPResult(intent="my_intent", confidence=0.95)
  31. """
  32. from trixy_core.nlp.provider import (
  33. NLPConfig,
  34. NLPContext,
  35. NLPProvider,
  36. NLPResult,
  37. NLPState,
  38. )
  39. from trixy_core.nlp.intent_registry import (
  40. IntentDefinition,
  41. IntentRegistry,
  42. IntentSlot,
  43. )
  44. from trixy_core.nlp.decorators import (
  45. discover_intent_handlers,
  46. get_intent_metadata,
  47. intent,
  48. is_intent_handler,
  49. INTENT_METADATA_ATTR,
  50. )
  51. from trixy_core.nlp.handler import (
  52. IntentReceivedData,
  53. IntentResult,
  54. )
  55. from trixy_core.nlp.system_intents import (
  56. IntentSecurityLevel,
  57. SystemIntentInfo,
  58. PUBLIC_SYSTEM_INTENTS,
  59. ADMIN_SYSTEM_INTENTS,
  60. ALL_SYSTEM_INTENTS,
  61. get_system_intents_for_context,
  62. is_admin_intent,
  63. is_system_intent,
  64. get_system_intent_info,
  65. )
  66. from trixy_core.nlp.intent_dispatcher import IntentDispatcherService
  67. __all__ = [
  68. # Provider
  69. "NLPConfig",
  70. "NLPContext",
  71. "NLPProvider",
  72. "NLPResult",
  73. "NLPState",
  74. # Registry
  75. "IntentDefinition",
  76. "IntentRegistry",
  77. "IntentSlot",
  78. # Decorator
  79. "discover_intent_handlers",
  80. "get_intent_metadata",
  81. "intent",
  82. "is_intent_handler",
  83. "INTENT_METADATA_ATTR",
  84. # Handler
  85. "IntentReceivedData",
  86. "IntentResult",
  87. # System Intents
  88. "IntentSecurityLevel",
  89. "SystemIntentInfo",
  90. "PUBLIC_SYSTEM_INTENTS",
  91. "ADMIN_SYSTEM_INTENTS",
  92. "ALL_SYSTEM_INTENTS",
  93. "get_system_intents_for_context",
  94. "is_admin_intent",
  95. "is_system_intent",
  96. "get_system_intent_info",
  97. # Dispatcher
  98. "IntentDispatcherService",
  99. ]