__init__.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. admin_only,
  46. discover_intent_handlers,
  47. example,
  48. get_intent_metadata,
  49. intent,
  50. is_intent_handler,
  51. pattern,
  52. INTENT_METADATA_ATTR,
  53. )
  54. from trixy_core.nlp.handler import (
  55. IntentReceivedData,
  56. IntentResult,
  57. )
  58. from trixy_core.nlp.system_intents import (
  59. IntentSecurityLevel,
  60. SystemIntentInfo,
  61. PUBLIC_SYSTEM_INTENTS,
  62. ADMIN_SYSTEM_INTENTS,
  63. ALL_SYSTEM_INTENTS,
  64. get_system_intents_for_context,
  65. is_admin_intent,
  66. is_system_intent,
  67. get_system_intent_info,
  68. )
  69. from trixy_core.nlp.intent_dispatcher import IntentDispatcherService
  70. from trixy_core.nlp.entities import (
  71. EntityDefinition,
  72. EntityRegistry,
  73. EntityResolver,
  74. ResolvedEntity,
  75. )
  76. from trixy_core.nlp.intent_loader import load_entity_yaml
  77. __all__ = [
  78. # Provider
  79. "NLPConfig",
  80. "NLPContext",
  81. "NLPProvider",
  82. "NLPResult",
  83. "NLPState",
  84. # Registry
  85. "IntentDefinition",
  86. "IntentRegistry",
  87. "IntentSlot",
  88. # Decorator
  89. "discover_intent_handlers",
  90. "example",
  91. "get_intent_metadata",
  92. "intent",
  93. "is_intent_handler",
  94. "pattern",
  95. "INTENT_METADATA_ATTR",
  96. # Handler
  97. "IntentReceivedData",
  98. "IntentResult",
  99. # System Intents
  100. "IntentSecurityLevel",
  101. "SystemIntentInfo",
  102. "PUBLIC_SYSTEM_INTENTS",
  103. "ADMIN_SYSTEM_INTENTS",
  104. "ALL_SYSTEM_INTENTS",
  105. "get_system_intents_for_context",
  106. "is_admin_intent",
  107. "is_system_intent",
  108. "get_system_intent_info",
  109. # Dispatcher
  110. "IntentDispatcherService",
  111. # Entities
  112. "EntityDefinition",
  113. "EntityRegistry",
  114. "EntityResolver",
  115. "ResolvedEntity",
  116. # Entity-Loader
  117. "load_entity_yaml",
  118. ]