nlp2cmd-intent 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nlp2cmd_intent/__init__.py +31 -0
- nlp2cmd_intent/clarification.py +37 -0
- nlp2cmd_intent/data/keyword_intent_detector_config.json +215 -0
- nlp2cmd_intent/data/patterns.json +2016 -0
- nlp2cmd_intent/data_files.py +67 -0
- nlp2cmd_intent/domain_mapping.py +43 -0
- nlp2cmd_intent/facade.py +52 -0
- nlp2cmd_intent/input.py +34 -0
- nlp2cmd_intent/keywords/__init__.py +12 -0
- nlp2cmd_intent/keywords/keyword_detector.py +1209 -0
- nlp2cmd_intent/keywords/keyword_patterns.py +228 -0
- nlp2cmd_intent/nlp2cmd_convert.py +47 -0
- nlp2cmd_intent/normalize.py +16 -0
- nlp2cmd_intent/protocols.py +15 -0
- nlp2cmd_intent-0.1.1.dist-info/METADATA +74 -0
- nlp2cmd_intent-0.1.1.dist-info/RECORD +17 -0
- nlp2cmd_intent-0.1.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""NL → IntentIR pipeline."""
|
|
2
|
+
|
|
3
|
+
from nlp2cmd_intent.clarification import (
|
|
4
|
+
IntentClarificationRequired,
|
|
5
|
+
clarification_enforced,
|
|
6
|
+
ensure_intent_clear,
|
|
7
|
+
)
|
|
8
|
+
from nlp2cmd_intent.facade import IntentPipeline, default_intent_detector
|
|
9
|
+
from nlp2cmd_intent.input import analyze_query
|
|
10
|
+
from nlp2cmd_intent.keywords import DetectionResult, KeywordIntentDetector, KeywordPatterns
|
|
11
|
+
from nlp2cmd_intent.normalize import QueryNormalizer
|
|
12
|
+
from nlp2cmd_intent.nlp2cmd_convert import detection_to_intent_ir
|
|
13
|
+
from nlp2cmd_intent.protocols import EntityExtractor, IntentDetector
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"DetectionResult",
|
|
17
|
+
"EntityExtractor",
|
|
18
|
+
"IntentClarificationRequired",
|
|
19
|
+
"IntentDetector",
|
|
20
|
+
"IntentPipeline",
|
|
21
|
+
"KeywordIntentDetector",
|
|
22
|
+
"KeywordPatterns",
|
|
23
|
+
"QueryNormalizer",
|
|
24
|
+
"analyze_query",
|
|
25
|
+
"clarification_enforced",
|
|
26
|
+
"default_intent_detector",
|
|
27
|
+
"detection_to_intent_ir",
|
|
28
|
+
"ensure_intent_clear",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Intent clarification enforcement for low-confidence queries."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from pact_ir import IntentIR
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class IntentClarificationRequired(Exception):
|
|
11
|
+
"""Raised when IntentIR needs user clarification before planning."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, intent: IntentIR) -> None:
|
|
14
|
+
self.intent = intent
|
|
15
|
+
messages: list[str] = []
|
|
16
|
+
for ambiguity in intent.ambiguities:
|
|
17
|
+
messages.append(ambiguity.message)
|
|
18
|
+
if intent.confidence < 0.5:
|
|
19
|
+
messages.append(f"confidence {intent.confidence:.2f} below threshold 0.5")
|
|
20
|
+
super().__init__("; ".join(messages) or "intent needs clarification")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def clarification_enforced() -> bool:
|
|
24
|
+
return os.getenv("NLP2CMD_ENFORCE_CLARIFICATION", "0").strip().lower() in {
|
|
25
|
+
"1",
|
|
26
|
+
"true",
|
|
27
|
+
"yes",
|
|
28
|
+
"on",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def ensure_intent_clear(intent: IntentIR, *, enforced: bool | None = None) -> None:
|
|
33
|
+
"""Raise IntentClarificationRequired when clarification is required."""
|
|
34
|
+
if enforced is None:
|
|
35
|
+
enforced = clarification_enforced()
|
|
36
|
+
if enforced and intent.needs_clarification():
|
|
37
|
+
raise IntentClarificationRequired(intent)
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "keyword_intent_detector_config.v1",
|
|
3
|
+
"domain_boosters": {
|
|
4
|
+
"sql": [
|
|
5
|
+
"tabel",
|
|
6
|
+
"tabela",
|
|
7
|
+
"table",
|
|
8
|
+
"kolumna",
|
|
9
|
+
"column",
|
|
10
|
+
"baz",
|
|
11
|
+
"baza",
|
|
12
|
+
"database",
|
|
13
|
+
"sql",
|
|
14
|
+
"where",
|
|
15
|
+
"join",
|
|
16
|
+
"tabeli",
|
|
17
|
+
"z tabeli",
|
|
18
|
+
"select",
|
|
19
|
+
"insert",
|
|
20
|
+
"update",
|
|
21
|
+
"delete",
|
|
22
|
+
"SELECT",
|
|
23
|
+
"INSERT",
|
|
24
|
+
"UPDATE",
|
|
25
|
+
"DELETE"
|
|
26
|
+
],
|
|
27
|
+
"shell": [
|
|
28
|
+
"list_processes",
|
|
29
|
+
"process",
|
|
30
|
+
"reboot",
|
|
31
|
+
"service_start",
|
|
32
|
+
"service_restart",
|
|
33
|
+
"service_stop",
|
|
34
|
+
"service_status",
|
|
35
|
+
"open_url",
|
|
36
|
+
"search_web",
|
|
37
|
+
"file_operation",
|
|
38
|
+
"find",
|
|
39
|
+
"archive",
|
|
40
|
+
"disk",
|
|
41
|
+
"system_maintenance",
|
|
42
|
+
"development",
|
|
43
|
+
"security",
|
|
44
|
+
"process_management",
|
|
45
|
+
"find",
|
|
46
|
+
"list",
|
|
47
|
+
"znajd\u017a",
|
|
48
|
+
"plik",
|
|
49
|
+
"pliki",
|
|
50
|
+
"u\u017cytkownik",
|
|
51
|
+
"u\u017cytkownika",
|
|
52
|
+
"poka\u017c",
|
|
53
|
+
"pokaz"
|
|
54
|
+
],
|
|
55
|
+
"docker": [
|
|
56
|
+
"docker",
|
|
57
|
+
"doker",
|
|
58
|
+
"dokcer",
|
|
59
|
+
"kontener",
|
|
60
|
+
"container",
|
|
61
|
+
"obraz",
|
|
62
|
+
"image",
|
|
63
|
+
"compose",
|
|
64
|
+
"dockerfile",
|
|
65
|
+
"ker\u00f3w",
|
|
66
|
+
"k\u00f3r\u00f3w",
|
|
67
|
+
"dker\u00f3w",
|
|
68
|
+
"dkor\u00f3w",
|
|
69
|
+
"logi",
|
|
70
|
+
"logs"
|
|
71
|
+
],
|
|
72
|
+
"kubernetes": [
|
|
73
|
+
"kubernetes",
|
|
74
|
+
"k8s",
|
|
75
|
+
"kubectl",
|
|
76
|
+
"pod",
|
|
77
|
+
"deployment",
|
|
78
|
+
"namespace",
|
|
79
|
+
"helm",
|
|
80
|
+
"cluster",
|
|
81
|
+
"node",
|
|
82
|
+
"service"
|
|
83
|
+
],
|
|
84
|
+
"git": [
|
|
85
|
+
"git",
|
|
86
|
+
"repo",
|
|
87
|
+
"repository",
|
|
88
|
+
"commit",
|
|
89
|
+
"branch",
|
|
90
|
+
"ga\u0142\u0105\u017a",
|
|
91
|
+
"merge",
|
|
92
|
+
"push",
|
|
93
|
+
"pull",
|
|
94
|
+
"clone"
|
|
95
|
+
],
|
|
96
|
+
"dql": [
|
|
97
|
+
"entity",
|
|
98
|
+
"graph",
|
|
99
|
+
"node",
|
|
100
|
+
"edge",
|
|
101
|
+
"relation"
|
|
102
|
+
],
|
|
103
|
+
"browser": [
|
|
104
|
+
"przegl\u0105dark",
|
|
105
|
+
"browser",
|
|
106
|
+
"strona",
|
|
107
|
+
"website",
|
|
108
|
+
"kliknij",
|
|
109
|
+
"click",
|
|
110
|
+
"formularz",
|
|
111
|
+
"form",
|
|
112
|
+
"przycisk",
|
|
113
|
+
"button",
|
|
114
|
+
"link",
|
|
115
|
+
"url",
|
|
116
|
+
"google",
|
|
117
|
+
"github",
|
|
118
|
+
"amazon",
|
|
119
|
+
"szukaj",
|
|
120
|
+
"wyszukaj",
|
|
121
|
+
"wpisz",
|
|
122
|
+
"type"
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"priority_intents": {
|
|
126
|
+
"sql": [
|
|
127
|
+
"delete",
|
|
128
|
+
"update",
|
|
129
|
+
"insert",
|
|
130
|
+
"show_tables",
|
|
131
|
+
"aggregate",
|
|
132
|
+
"select"
|
|
133
|
+
],
|
|
134
|
+
"shell": [
|
|
135
|
+
"find",
|
|
136
|
+
"list_processes",
|
|
137
|
+
"process",
|
|
138
|
+
"reboot",
|
|
139
|
+
"service_start",
|
|
140
|
+
"service_restart",
|
|
141
|
+
"service_stop",
|
|
142
|
+
"service_status",
|
|
143
|
+
"open_url",
|
|
144
|
+
"search_web",
|
|
145
|
+
"file_operation",
|
|
146
|
+
"archive",
|
|
147
|
+
"disk",
|
|
148
|
+
"system_maintenance",
|
|
149
|
+
"development",
|
|
150
|
+
"security",
|
|
151
|
+
"process_management",
|
|
152
|
+
"list_dirs",
|
|
153
|
+
"find"
|
|
154
|
+
],
|
|
155
|
+
"docker": [
|
|
156
|
+
"stop",
|
|
157
|
+
"prune",
|
|
158
|
+
"build",
|
|
159
|
+
"run",
|
|
160
|
+
"list",
|
|
161
|
+
"logs",
|
|
162
|
+
"exec",
|
|
163
|
+
"start",
|
|
164
|
+
"remove"
|
|
165
|
+
],
|
|
166
|
+
"kubernetes": [
|
|
167
|
+
"delete",
|
|
168
|
+
"scale",
|
|
169
|
+
"describe",
|
|
170
|
+
"logs"
|
|
171
|
+
],
|
|
172
|
+
"git": [
|
|
173
|
+
"reset",
|
|
174
|
+
"revert",
|
|
175
|
+
"merge",
|
|
176
|
+
"rebase",
|
|
177
|
+
"push",
|
|
178
|
+
"commit",
|
|
179
|
+
"stash"
|
|
180
|
+
],
|
|
181
|
+
"browser": [
|
|
182
|
+
"web_action",
|
|
183
|
+
"navigate",
|
|
184
|
+
"click",
|
|
185
|
+
"fill_form"
|
|
186
|
+
]
|
|
187
|
+
},
|
|
188
|
+
"fast_path": {
|
|
189
|
+
"browser_keywords": [
|
|
190
|
+
"przegl\u0105dark",
|
|
191
|
+
"browser",
|
|
192
|
+
"otw\u00f3rz stron\u0119",
|
|
193
|
+
"open url",
|
|
194
|
+
"open website",
|
|
195
|
+
"go to",
|
|
196
|
+
"navigate to"
|
|
197
|
+
],
|
|
198
|
+
"search_keywords": [
|
|
199
|
+
"szukaj w internecie",
|
|
200
|
+
"szukaj online",
|
|
201
|
+
"znajd\u017a w internecie",
|
|
202
|
+
"look up online"
|
|
203
|
+
],
|
|
204
|
+
"common_images": [
|
|
205
|
+
"nginx",
|
|
206
|
+
"redis",
|
|
207
|
+
"postgres",
|
|
208
|
+
"postgresql",
|
|
209
|
+
"mysql",
|
|
210
|
+
"mongo",
|
|
211
|
+
"mongodb",
|
|
212
|
+
"rabbitmq"
|
|
213
|
+
]
|
|
214
|
+
}
|
|
215
|
+
}
|