ragflow-cli-myfbee-test 0.27.2.dev0__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.
parser.py ADDED
@@ -0,0 +1,940 @@
1
+ #
2
+ # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ from lark import Transformer
18
+
19
+ GRAMMAR = r"""
20
+ start: command
21
+
22
+ command: sql_command | meta_command
23
+
24
+ sql_command: login_user
25
+ | ping_server
26
+ | list_services
27
+ | show_service
28
+ | startup_service
29
+ | shutdown_service
30
+ | restart_service
31
+ | register_user
32
+ | list_users
33
+ | show_user
34
+ | drop_user
35
+ | alter_user
36
+ | create_user
37
+ | activate_user
38
+ | list_datasets
39
+ | list_agents
40
+ | create_role
41
+ | drop_role
42
+ | alter_role
43
+ | list_roles
44
+ | show_role
45
+ | grant_permission
46
+ | revoke_permission
47
+ | alter_user_role
48
+ | show_user_permission
49
+ | show_version
50
+ | grant_admin
51
+ | revoke_admin
52
+ | set_variable
53
+ | show_variable
54
+ | list_variables
55
+ | list_configs
56
+ | list_environments
57
+ | generate_key
58
+ | list_keys
59
+ | drop_key
60
+ | show_current_user
61
+ | set_default_llm
62
+ | set_default_vlm
63
+ | set_default_embedding
64
+ | set_default_reranker
65
+ | set_default_asr
66
+ | set_default_tts
67
+ | reset_default_llm
68
+ | reset_default_vlm
69
+ | reset_default_embedding
70
+ | reset_default_reranker
71
+ | reset_default_asr
72
+ | reset_default_tts
73
+ | create_model_provider
74
+ | drop_model_provider
75
+ | create_user_dataset_with_parser
76
+ | create_user_dataset_with_pipeline
77
+ | drop_user_dataset
78
+ | list_user_datasets
79
+ | list_user_dataset_files
80
+ | list_user_dataset_documents
81
+ | list_user_datasets_metadata
82
+ | list_user_documents_metadata_summary
83
+ | list_user_agents
84
+ | list_user_chats
85
+ | create_user_chat
86
+ | drop_user_chat
87
+ | create_dataset_table
88
+ | drop_dataset_table
89
+ | create_metadata_table
90
+ | drop_metadata_table
91
+ | list_user_model_providers
92
+ | list_user_default_models
93
+ | parse_dataset_docs
94
+ | parse_dataset_sync
95
+ | parse_dataset_async
96
+ | import_docs_into_dataset
97
+ | search_on_datasets
98
+ | get_chunk
99
+ | list_chunks
100
+ | insert_dataset_from_file
101
+ | insert_metadata_from_file
102
+ | update_chunk
103
+ | set_metadata
104
+ | remove_tags
105
+ | remove_chunks
106
+ | create_chat_session
107
+ | drop_chat_session
108
+ | list_chat_sessions
109
+ | chat_on_session
110
+ | list_server_configs
111
+ | show_fingerprint
112
+ | set_license
113
+ | set_license_config
114
+ | show_license
115
+ | generate_nav_for_dataset
116
+ | navigation_search
117
+ | check_license
118
+ | benchmark
119
+
120
+ // meta command definition
121
+ meta_command: "\\" meta_command_name [meta_args]
122
+
123
+ COMMA: ","
124
+
125
+ meta_command_name: /[a-zA-Z?]+/
126
+ meta_args: (meta_arg)+
127
+
128
+ meta_arg: /[^\s"',]+/ | quoted_string
129
+
130
+ // command definition
131
+
132
+ LOGIN: "LOGIN"i
133
+ REGISTER: "REGISTER"i
134
+ LIST: "LIST"i
135
+ SERVICES: "SERVICES"i
136
+ SHOW: "SHOW"i
137
+ CREATE: "CREATE"i
138
+ SERVICE: "SERVICE"i
139
+ SHUTDOWN: "SHUTDOWN"i
140
+ STARTUP: "STARTUP"i
141
+ RESTART: "RESTART"i
142
+ USERS: "USERS"i
143
+ DROP: "DROP"i
144
+ USER: "USER"i
145
+ ALTER: "ALTER"i
146
+ ACTIVE: "ACTIVE"i
147
+ ADMIN: "ADMIN"i
148
+ PASSWORD: "PASSWORD"i
149
+ DATASET_TABLE: "DATASET TABLE"i
150
+ DATASET: "DATASET"i
151
+ DATASETS: "DATASETS"i
152
+ OF: "OF"i
153
+ AGENTS: "AGENTS"i
154
+ ROLE: "ROLE"i
155
+ ROLES: "ROLES"i
156
+ DESCRIPTION: "DESCRIPTION"i
157
+ GRANT: "GRANT"i
158
+ REVOKE: "REVOKE"i
159
+ ALL: "ALL"i
160
+ PERMISSION: "PERMISSION"i
161
+ TO: "TO"i
162
+ FROM: "FROM"i
163
+ FOR: "FOR"i
164
+ RESOURCES: "RESOURCES"i
165
+ ON: "ON"i
166
+ SET: "SET"i
167
+ RESET: "RESET"i
168
+ VERSION: "VERSION"i
169
+ VAR: "VAR"i
170
+ VARS: "VARS"i
171
+ CONFIGS: "CONFIGS"i
172
+ ENVS: "ENVS"i
173
+ KEY: "KEY"i
174
+ KEYS: "KEYS"i
175
+ GENERATE: "GENERATE"i
176
+ NAVIGATION: "NAVIGATION"i
177
+ MODE: "MODE"i
178
+ TOPK: "TOPK"i
179
+ MODEL: "MODEL"i
180
+ MODELS: "MODELS"i
181
+ PROVIDER: "PROVIDER"i
182
+ PROVIDERS: "PROVIDERS"i
183
+ DEFAULT: "DEFAULT"i
184
+ CHATS: "CHATS"i
185
+ CHAT: "CHAT"i
186
+ FILES: "FILES"i
187
+ DOCUMENT: "DOCUMENT"i
188
+ DOCUMENTS: "DOCUMENTS"i
189
+ METADATA: "METADATA"i
190
+ SUMMARY: "SUMMARY"i
191
+ AS: "AS"i
192
+ PARSE: "PARSE"i
193
+ IMPORT: "IMPORT"i
194
+ INTO: "INTO"i
195
+ IN: "IN"i
196
+ WITH: "WITH"i
197
+ VECTOR: "VECTOR"i
198
+ SIZE: "SIZE"i
199
+ PARSER: "PARSER"i
200
+ PIPELINE: "PIPELINE"i
201
+ SEARCH: "SEARCH"i
202
+ EXPLORE: "EXPLORE"i
203
+ CURRENT: "CURRENT"i
204
+ LLM: "LLM"i
205
+ VLM: "VLM"i
206
+ EMBEDDING: "EMBEDDING"i
207
+ RERANKER: "RERANKER"i
208
+ ASR: "ASR"i
209
+ TTS: "TTS"i
210
+ ASYNC: "ASYNC"i
211
+ SYNC: "SYNC"i
212
+ BENCHMARK: "BENCHMARK"i
213
+ PING: "PING"i
214
+ SESSION: "SESSION"i
215
+ SESSIONS: "SESSIONS"i
216
+ SERVER: "SERVER"i
217
+ FINGERPRINT: "FINGERPRINT"i
218
+ LICENSE: "LICENSE"i
219
+ CHECK: "CHECK"i
220
+ CONFIG: "CONFIG"i
221
+ INDEX: "INDEX"i
222
+ TABLE: "TABLE"i
223
+ CHUNK: "CHUNK"i
224
+ CHUNKS: "CHUNKS"i
225
+ GET: "GET"i
226
+ INSERT: "INSERT"i
227
+ PAGE: "PAGE"i
228
+ KEYWORDS: "KEYWORDS"i
229
+ AVAILABLE: "AVAILABLE"i
230
+ FILE: "FILE"i
231
+ UPDATE: "UPDATE"i
232
+ REMOVE: "REMOVE"i
233
+ TAGS: "TAGS"i
234
+
235
+ login_user: LOGIN USER quoted_string (PASSWORD quoted_string)? ";"
236
+ list_services: LIST SERVICES ";"
237
+ show_service: SHOW SERVICE NUMBER ";"
238
+ startup_service: STARTUP SERVICE NUMBER ";"
239
+ shutdown_service: SHUTDOWN SERVICE NUMBER ";"
240
+ restart_service: RESTART SERVICE NUMBER ";"
241
+
242
+ register_user: REGISTER USER quoted_string AS quoted_string PASSWORD quoted_string ";"
243
+ list_users: LIST USERS ";"
244
+ drop_user: DROP USER quoted_string ";"
245
+ alter_user: ALTER USER PASSWORD quoted_string quoted_string ";"
246
+ show_user: SHOW USER quoted_string ";"
247
+ create_user: CREATE USER quoted_string quoted_string ";"
248
+ activate_user: ALTER USER ACTIVE quoted_string status ";"
249
+
250
+ list_datasets: LIST DATASETS OF quoted_string ";"
251
+ list_agents: LIST AGENTS OF quoted_string ";"
252
+
253
+ create_role: CREATE ROLE identifier [DESCRIPTION quoted_string] ";"
254
+ drop_role: DROP ROLE identifier ";"
255
+ alter_role: ALTER ROLE identifier SET DESCRIPTION quoted_string ";"
256
+ list_roles: LIST ROLES ";"
257
+ show_role: SHOW ROLE identifier ";"
258
+
259
+ grant_permission: GRANT identifier_list ON identifier TO ROLE identifier ";"
260
+ revoke_permission: REVOKE identifier_list ON identifier FROM ROLE identifier ";"
261
+ alter_user_role: ALTER USER quoted_string SET ROLE identifier ";"
262
+ show_user_permission: SHOW USER PERMISSION quoted_string ";"
263
+
264
+ show_version: SHOW VERSION ";"
265
+
266
+ grant_admin: GRANT ADMIN quoted_string ";"
267
+ revoke_admin: REVOKE ADMIN quoted_string ";"
268
+
269
+ generate_key: GENERATE KEY FOR USER quoted_string ";"
270
+ list_keys: LIST KEYS OF quoted_string ";"
271
+ drop_key: DROP KEY quoted_string OF quoted_string ";"
272
+
273
+ set_variable: SET VAR identifier variable_value ";"
274
+ show_variable: SHOW VAR identifier ";"
275
+ list_variables: LIST VARS ";"
276
+ list_configs: LIST CONFIGS ";"
277
+ list_environments: LIST ENVS ";"
278
+
279
+ show_fingerprint: SHOW FINGERPRINT ";"
280
+ set_license: SET LICENSE quoted_string ";"
281
+ set_license_config: SET LICENSE CONFIG NUMBER NUMBER ";"
282
+ show_license: SHOW LICENSE ";"
283
+ check_license: CHECK LICENSE ";"
284
+
285
+ list_server_configs: LIST SERVER CONFIGS ";"
286
+
287
+ benchmark: BENCHMARK NUMBER NUMBER user_statement
288
+
289
+ user_statement: ping_server
290
+ | show_current_user
291
+ | create_model_provider
292
+ | drop_model_provider
293
+ | set_default_llm
294
+ | set_default_vlm
295
+ | set_default_embedding
296
+ | set_default_reranker
297
+ | set_default_asr
298
+ | set_default_tts
299
+ | reset_default_llm
300
+ | reset_default_vlm
301
+ | reset_default_embedding
302
+ | reset_default_reranker
303
+ | reset_default_asr
304
+ | reset_default_tts
305
+ | create_user_dataset_with_parser
306
+ | create_user_dataset_with_pipeline
307
+ | drop_user_dataset
308
+ | list_user_datasets
309
+ | list_user_dataset_files
310
+ | list_user_agents
311
+ | list_user_chats
312
+ | create_user_chat
313
+ | drop_user_chat
314
+ | list_user_model_providers
315
+ | list_user_default_models
316
+ | import_docs_into_dataset
317
+ | search_on_datasets
318
+ | update_chunk
319
+ | set_metadata
320
+ | remove_tags
321
+ | create_chat_session
322
+ | drop_chat_session
323
+ | list_chat_sessions
324
+ | chat_on_session
325
+
326
+ ping_server: PING ";"
327
+ show_current_user: SHOW CURRENT USER ";"
328
+ create_model_provider: CREATE MODEL PROVIDER quoted_string quoted_string ";"
329
+ drop_model_provider: DROP MODEL PROVIDER quoted_string ";"
330
+ set_default_llm: SET DEFAULT LLM quoted_string ";"
331
+ set_default_vlm: SET DEFAULT VLM quoted_string ";"
332
+ set_default_embedding: SET DEFAULT EMBEDDING quoted_string ";"
333
+ set_default_reranker: SET DEFAULT RERANKER quoted_string ";"
334
+ set_default_asr: SET DEFAULT ASR quoted_string ";"
335
+ set_default_tts: SET DEFAULT TTS quoted_string ";"
336
+
337
+ reset_default_llm: RESET DEFAULT LLM ";"
338
+ reset_default_vlm: RESET DEFAULT VLM ";"
339
+ reset_default_embedding: RESET DEFAULT EMBEDDING ";"
340
+ reset_default_reranker: RESET DEFAULT RERANKER ";"
341
+ reset_default_asr: RESET DEFAULT ASR ";"
342
+ reset_default_tts: RESET DEFAULT TTS ";"
343
+
344
+ list_user_datasets: LIST DATASETS ";"
345
+ create_user_dataset_with_parser: CREATE DATASET quoted_string WITH EMBEDDING quoted_string PARSER quoted_string ";"
346
+ create_user_dataset_with_pipeline: CREATE DATASET quoted_string WITH EMBEDDING quoted_string PIPELINE quoted_string ";"
347
+ drop_user_dataset: DROP DATASET quoted_string ";"
348
+ list_user_dataset_files: LIST FILES OF DATASET quoted_string ";"
349
+ list_user_dataset_documents: LIST DOCUMENTS OF DATASET quoted_string ";"
350
+ list_user_datasets_metadata: LIST METADATA OF DATASETS quoted_string (COMMA quoted_string)* ";"
351
+ list_user_documents_metadata_summary: LIST METADATA SUMMARY OF DATASET quoted_string (DOCUMENTS quoted_string (COMMA quoted_string)*)? ";"
352
+ list_user_agents: LIST AGENTS ";"
353
+ list_user_chats: LIST CHATS ";"
354
+ create_user_chat: CREATE CHAT quoted_string ";"
355
+ drop_user_chat: DROP CHAT quoted_string ";"
356
+ create_chat_session: CREATE CHAT quoted_string SESSION ";"
357
+ drop_chat_session: DROP CHAT quoted_string SESSION quoted_string ";"
358
+ list_chat_sessions: LIST CHAT quoted_string SESSIONS ";"
359
+ chat_on_session: CHAT quoted_string ON quoted_string SESSION quoted_string ";"
360
+ list_user_model_providers: LIST MODEL PROVIDERS ";"
361
+ list_user_default_models: LIST DEFAULT MODELS ";"
362
+ import_docs_into_dataset: IMPORT quoted_string INTO DATASET quoted_string ";"
363
+ search_on_datasets: SEARCH quoted_string ON DATASETS quoted_string ";"
364
+ get_chunk: GET CHUNK quoted_string ";"
365
+ list_chunks: LIST CHUNKS OF DOCUMENT quoted_string ("PAGE" NUMBER)? ("SIZE" NUMBER)? ("KEYWORDS" quoted_string)? ("AVAILABLE" NUMBER)? ";"
366
+ set_metadata: SET METADATA OF DOCUMENT quoted_string TO quoted_string ";"
367
+ remove_tags: REMOVE TAGS quoted_string (COMMA quoted_string)* FROM DATASET quoted_string ";"
368
+ remove_chunks: REMOVE CHUNKS quoted_string (COMMA quoted_string)* FROM DOCUMENT quoted_string ";"
369
+ | REMOVE ALL CHUNKS FROM DOCUMENT quoted_string ";"
370
+
371
+ parse_dataset_docs: PARSE quoted_string OF DATASET quoted_string ";"
372
+ parse_dataset_sync: PARSE DATASET quoted_string SYNC ";"
373
+ parse_dataset_async: PARSE DATASET quoted_string ASYNC ";"
374
+
375
+ // Internal CLI only for GO
376
+ create_dataset_table: CREATE DATASET TABLE quoted_string VECTOR SIZE NUMBER ";"
377
+ drop_dataset_table: DROP DATASET TABLE quoted_string ";"
378
+ create_metadata_table: CREATE METADATA TABLE ";"
379
+ drop_metadata_table: DROP METADATA TABLE ";"
380
+ insert_dataset_from_file: INSERT DATASET FROM FILE quoted_string ";"
381
+ insert_metadata_from_file: INSERT METADATA FROM FILE quoted_string ";"
382
+ generate_nav_for_dataset: GENERATE NAVIGATION OF DATASET quoted_string ";"
383
+ navigation_search: NAVIGATION SEARCH quoted_string IN DATASET quoted_string MODE quoted_string (TOPK NUMBER)? ";"
384
+ update_chunk: UPDATE CHUNK quoted_string OF DATASET quoted_string SET quoted_string ";"
385
+
386
+ identifier_list: identifier (COMMA identifier)*
387
+
388
+ identifier: WORD
389
+ variable_value: WORD | NUMBER | QUOTED_STRING
390
+ quoted_string: QUOTED_STRING
391
+ status: ON | WORD
392
+
393
+ QUOTED_STRING: /'[^']+'/ | /"[^"]+"/
394
+ WORD: /[a-zA-Z0-9_\-\.]+/
395
+ NUMBER: /[0-9]+/
396
+
397
+ %import common.WS
398
+ %ignore WS
399
+ """
400
+
401
+
402
+ class RAGFlowCLITransformer(Transformer):
403
+ def start(self, items):
404
+ return items[0]
405
+
406
+ def command(self, items):
407
+ return items[0]
408
+
409
+ def login_user(self, items):
410
+ email = items[2].children[0].strip("'\"")
411
+ if len(items) == 5:
412
+ # With password: LOGIN USER email PASSWORD password
413
+ password = items[4].children[0].strip("'\"")
414
+ return {"type": "login_user", "email": email, "password": password}
415
+ else:
416
+ # Without password: LOGIN USER email
417
+ return {"type": "login_user", "email": email}
418
+
419
+ def ping_server(self, items):
420
+ return {"type": "ping_server"}
421
+
422
+ def list_services(self, items):
423
+ result = {"type": "list_services"}
424
+ return result
425
+
426
+ def show_service(self, items):
427
+ service_id = int(items[2])
428
+ return {"type": "show_service", "number": service_id}
429
+
430
+ def startup_service(self, items):
431
+ service_id = int(items[2])
432
+ return {"type": "startup_service", "number": service_id}
433
+
434
+ def shutdown_service(self, items):
435
+ service_id = int(items[2])
436
+ return {"type": "shutdown_service", "number": service_id}
437
+
438
+ def restart_service(self, items):
439
+ service_id = int(items[2])
440
+ return {"type": "restart_service", "number": service_id}
441
+
442
+ def register_user(self, items):
443
+ user_name: str = items[2].children[0].strip("'\"")
444
+ nickname: str = items[4].children[0].strip("'\"")
445
+ password: str = items[6].children[0].strip("'\"")
446
+ return {"type": "register_user", "user_name": user_name, "nickname": nickname, "password": password}
447
+
448
+ def list_users(self, items):
449
+ return {"type": "list_users"}
450
+
451
+ def show_user(self, items):
452
+ user_name = items[2]
453
+ return {"type": "show_user", "user_name": user_name}
454
+
455
+ def drop_user(self, items):
456
+ user_name = items[2]
457
+ return {"type": "drop_user", "user_name": user_name}
458
+
459
+ def alter_user(self, items):
460
+ user_name = items[3]
461
+ new_password = items[4]
462
+ return {"type": "alter_user", "user_name": user_name, "password": new_password}
463
+
464
+ def create_user(self, items):
465
+ user_name = items[2]
466
+ password = items[3]
467
+ return {"type": "create_user", "user_name": user_name, "password": password, "role": "user"}
468
+
469
+ def activate_user(self, items):
470
+ user_name = items[3]
471
+ activate_status = items[4]
472
+ return {"type": "activate_user", "activate_status": activate_status, "user_name": user_name}
473
+
474
+ def list_datasets(self, items):
475
+ user_name = items[3]
476
+ return {"type": "list_datasets", "user_name": user_name}
477
+
478
+ def list_agents(self, items):
479
+ user_name = items[3]
480
+ return {"type": "list_agents", "user_name": user_name}
481
+
482
+ def create_role(self, items):
483
+ role_name = items[2]
484
+ if len(items) > 4:
485
+ description = items[4]
486
+ return {"type": "create_role", "role_name": role_name, "description": description}
487
+ else:
488
+ return {"type": "create_role", "role_name": role_name}
489
+
490
+ def drop_role(self, items):
491
+ role_name = items[2]
492
+ return {"type": "drop_role", "role_name": role_name}
493
+
494
+ def alter_role(self, items):
495
+ role_name = items[2]
496
+ description = items[5]
497
+ return {"type": "alter_role", "role_name": role_name, "description": description}
498
+
499
+ def list_roles(self, items):
500
+ return {"type": "list_roles"}
501
+
502
+ def show_role(self, items):
503
+ role_name = items[2]
504
+ return {"type": "show_role", "role_name": role_name}
505
+
506
+ def grant_permission(self, items):
507
+ action_list = items[1]
508
+ resource = items[3]
509
+ role_name = items[6]
510
+ return {"type": "grant_permission", "role_name": role_name, "resource": resource, "actions": action_list}
511
+
512
+ def revoke_permission(self, items):
513
+ action_list = items[1]
514
+ resource = items[3]
515
+ role_name = items[6]
516
+ return {"type": "revoke_permission", "role_name": role_name, "resource": resource, "actions": action_list}
517
+
518
+ def alter_user_role(self, items):
519
+ user_name = items[2]
520
+ role_name = items[5]
521
+ return {"type": "alter_user_role", "user_name": user_name, "role_name": role_name}
522
+
523
+ def show_user_permission(self, items):
524
+ user_name = items[3]
525
+ return {"type": "show_user_permission", "user_name": user_name}
526
+
527
+ def show_version(self, items):
528
+ return {"type": "show_version"}
529
+
530
+ def grant_admin(self, items):
531
+ user_name = items[2]
532
+ return {"type": "grant_admin", "user_name": user_name}
533
+
534
+ def revoke_admin(self, items):
535
+ user_name = items[2]
536
+ return {"type": "revoke_admin", "user_name": user_name}
537
+
538
+ def generate_key(self, items):
539
+ user_name = items[4]
540
+ return {"type": "generate_key", "user_name": user_name}
541
+
542
+ def list_keys(self, items):
543
+ user_name = items[3]
544
+ return {"type": "list_keys", "user_name": user_name}
545
+
546
+ def drop_key(self, items):
547
+ key = items[2]
548
+ user_name = items[4]
549
+ return {"type": "drop_key", "key": key, "user_name": user_name}
550
+
551
+ def set_variable(self, items):
552
+ var_name = items[2]
553
+ var_value = items[3]
554
+ return {"type": "set_variable", "var_name": var_name, "var_value": var_value}
555
+
556
+ def show_variable(self, items):
557
+ var_name = items[2]
558
+ return {"type": "show_variable", "var_name": var_name}
559
+
560
+ def list_variables(self, items):
561
+ return {"type": "list_variables"}
562
+
563
+ def list_configs(self, items):
564
+ return {"type": "list_configs"}
565
+
566
+ def list_environments(self, items):
567
+ return {"type": "list_environments"}
568
+
569
+ def show_fingerprint(self, items):
570
+ return {"type": "show_fingerprint"}
571
+
572
+ def set_license(self, items):
573
+ license = items[2].children[0].strip("'\"")
574
+ return {"type": "set_license", "license": license}
575
+
576
+ def set_license_config(self, items):
577
+ value1: int = int(items[3])
578
+ value2: int = int(items[4])
579
+ return {"type": "set_license_config", "value1": value1, "value2": value2}
580
+
581
+ def show_license(self, items):
582
+ return {"type": "show_license"}
583
+
584
+ def check_license(self, items):
585
+ return {"type": "check_license"}
586
+
587
+ def list_server_configs(self, items):
588
+ return {"type": "list_server_configs"}
589
+
590
+ def create_model_provider(self, items):
591
+ provider_name = items[3].children[0].strip("'\"")
592
+ provider_key = items[4].children[0].strip("'\"")
593
+ return {"type": "create_model_provider", "provider_name": provider_name, "provider_key": provider_key}
594
+
595
+ def drop_model_provider(self, items):
596
+ provider_name = items[3].children[0].strip("'\"")
597
+ return {"type": "drop_model_provider", "provider_name": provider_name}
598
+
599
+ def show_current_user(self, items):
600
+ return {"type": "show_current_user"}
601
+
602
+ def set_default_llm(self, items):
603
+ llm_id = items[3].children[0].strip("'\"")
604
+ return {"type": "set_default_model", "model_type": "llm_id", "model_id": llm_id}
605
+
606
+ def set_default_vlm(self, items):
607
+ vlm_id = items[3].children[0].strip("'\"")
608
+ return {"type": "set_default_model", "model_type": "img2txt_id", "model_id": vlm_id}
609
+
610
+ def set_default_embedding(self, items):
611
+ embedding_id = items[3].children[0].strip("'\"")
612
+ return {"type": "set_default_model", "model_type": "embd_id", "model_id": embedding_id}
613
+
614
+ def set_default_reranker(self, items):
615
+ reranker_id = items[3].children[0].strip("'\"")
616
+ return {"type": "set_default_model", "model_type": "reranker_id", "model_id": reranker_id}
617
+
618
+ def set_default_asr(self, items):
619
+ asr_id = items[3].children[0].strip("'\"")
620
+ return {"type": "set_default_model", "model_type": "asr_id", "model_id": asr_id}
621
+
622
+ def set_default_tts(self, items):
623
+ tts_id = items[3].children[0].strip("'\"")
624
+ return {"type": "set_default_model", "model_type": "tts_id", "model_id": tts_id}
625
+
626
+ def reset_default_llm(self, items):
627
+ return {"type": "reset_default_model", "model_type": "llm_id"}
628
+
629
+ def reset_default_vlm(self, items):
630
+ return {"type": "reset_default_model", "model_type": "img2txt_id"}
631
+
632
+ def reset_default_embedding(self, items):
633
+ return {"type": "reset_default_model", "model_type": "embd_id"}
634
+
635
+ def reset_default_reranker(self, items):
636
+ return {"type": "reset_default_model", "model_type": "reranker_id"}
637
+
638
+ def reset_default_asr(self, items):
639
+ return {"type": "reset_default_model", "model_type": "asr_id"}
640
+
641
+ def reset_default_tts(self, items):
642
+ return {"type": "reset_default_model", "model_type": "tts_id"}
643
+
644
+ def list_user_datasets(self, items):
645
+ return {"type": "list_user_datasets"}
646
+
647
+ def create_user_dataset_with_parser(self, items):
648
+ dataset_name = items[2].children[0].strip("'\"")
649
+ embedding = items[5].children[0].strip("'\"")
650
+ parser_type = items[7].children[0].strip("'\"")
651
+ return {"type": "create_user_dataset", "dataset_name": dataset_name, "embedding": embedding, "parser_type": parser_type}
652
+
653
+ def create_user_dataset_with_pipeline(self, items):
654
+ dataset_name = items[2].children[0].strip("'\"")
655
+ embedding = items[5].children[0].strip("'\"")
656
+ pipeline = items[7].children[0].strip("'\"")
657
+ return {"type": "create_user_dataset", "dataset_name": dataset_name, "embedding": embedding, "pipeline": pipeline}
658
+
659
+ def drop_user_dataset(self, items):
660
+ dataset_name = items[2].children[0].strip("'\"")
661
+ return {"type": "drop_user_dataset", "dataset_name": dataset_name}
662
+
663
+ def list_user_dataset_files(self, items):
664
+ dataset_name = items[4].children[0].strip("'\"")
665
+ return {"type": "list_user_dataset_files", "dataset_name": dataset_name}
666
+
667
+ def list_user_dataset_documents(self, items):
668
+ dataset_name = items[4].children[0].strip("'\"")
669
+ return {"type": "list_user_dataset_documents", "dataset_name": dataset_name}
670
+
671
+ def list_user_datasets_metadata(self, items):
672
+ dataset_names = []
673
+ dataset_names.append(items[4].children[0].strip("'\""))
674
+ for i in range(5, len(items)):
675
+ if items[i] and hasattr(items[i], "children") and items[i].children:
676
+ dataset_names.append(items[i].children[0].strip("'\""))
677
+ return {"type": "list_user_datasets_metadata", "dataset_names": dataset_names}
678
+
679
+ def list_user_documents_metadata_summary(self, items):
680
+ dataset_name = items[5].children[0].strip("'\"")
681
+ doc_ids = []
682
+ if len(items) > 6 and items[6] == "DOCUMENTS":
683
+ for i in range(7, len(items)):
684
+ if items[i] and hasattr(items[i], "children") and items[i].children:
685
+ doc_id = items[i].children[0].strip("'\"")
686
+ doc_ids.append(doc_id)
687
+ return {"type": "list_user_documents_metadata_summary", "dataset_name": dataset_name, "document_ids": doc_ids}
688
+
689
+ def list_user_agents(self, items):
690
+ return {"type": "list_user_agents"}
691
+
692
+ def list_user_chats(self, items):
693
+ return {"type": "list_user_chats"}
694
+
695
+ def create_user_chat(self, items):
696
+ chat_name = items[2].children[0].strip("'\"")
697
+ return {"type": "create_user_chat", "chat_name": chat_name}
698
+
699
+ def drop_user_chat(self, items):
700
+ chat_name = items[2].children[0].strip("'\"")
701
+ return {"type": "drop_user_chat", "chat_name": chat_name}
702
+
703
+ def create_dataset_table(self, items):
704
+ dataset_name = None
705
+ vector_size = None
706
+ for i, item in enumerate(items):
707
+ if hasattr(item, "data") and item.data == "quoted_string":
708
+ dataset_name = item.children[0].strip("'\"")
709
+ if hasattr(item, "type") and item.type == "NUMBER":
710
+ if i > 0 and items[i - 1].type == "SIZE" and items[i - 2].type == "VECTOR":
711
+ vector_size = int(item)
712
+ return {"type": "create_dataset_table", "dataset_name": dataset_name, "vector_size": vector_size}
713
+
714
+ def drop_dataset_table(self, items):
715
+ dataset_name = None
716
+ for item in items:
717
+ if hasattr(item, "data") and item.data == "quoted_string":
718
+ dataset_name = item.children[0].strip("'\"")
719
+ return {"type": "drop_dataset_table", "dataset_name": dataset_name}
720
+
721
+ def create_metadata_table(self, items):
722
+ return {"type": "create_metadata_table"}
723
+
724
+ def drop_metadata_table(self, items):
725
+ return {"type": "drop_metadata_table"}
726
+
727
+ def list_user_model_providers(self, items):
728
+ return {"type": "list_user_model_providers"}
729
+
730
+ def list_user_default_models(self, items):
731
+ return {"type": "list_user_default_models"}
732
+
733
+ def parse_dataset_docs(self, items):
734
+ document_list_str = items[1].children[0].strip("'\"")
735
+ document_names = document_list_str.split(",")
736
+ if len(document_names) == 1:
737
+ document_names = document_names[0]
738
+ document_names = document_names.split(" ")
739
+ dataset_name = items[4].children[0].strip("'\"")
740
+ return {"type": "parse_dataset_docs", "dataset_name": dataset_name, "document_names": document_names}
741
+
742
+ def parse_dataset_sync(self, items):
743
+ dataset_name = items[2].children[0].strip("'\"")
744
+ return {"type": "parse_dataset", "dataset_name": dataset_name, "method": "sync"}
745
+
746
+ def parse_dataset_async(self, items):
747
+ dataset_name = items[2].children[0].strip("'\"")
748
+ return {"type": "parse_dataset", "dataset_name": dataset_name, "method": "async"}
749
+
750
+ def create_chat_session(self, items):
751
+ chat_name = items[2].children[0].strip("'\"")
752
+ return {"type": "create_chat_session", "chat_name": chat_name}
753
+
754
+ def drop_chat_session(self, items):
755
+ chat_name = items[2].children[0].strip("'\"")
756
+ session_id = items[4].children[0].strip("'\"")
757
+ return {"type": "drop_chat_session", "chat_name": chat_name, "session_id": session_id}
758
+
759
+ def list_chat_sessions(self, items):
760
+ chat_name = items[2].children[0].strip("'\"")
761
+ return {"type": "list_chat_sessions", "chat_name": chat_name}
762
+
763
+ def chat_on_session(self, items):
764
+ message = items[1].children[0].strip("'\"")
765
+ chat_name = items[3].children[0].strip("'\"")
766
+ session_id = items[5].children[0].strip("'\"")
767
+ return {"type": "chat_on_session", "message": message, "chat_name": chat_name, "session_id": session_id}
768
+
769
+ def import_docs_into_dataset(self, items):
770
+ document_list_str = items[1].children[0].strip("'\"")
771
+ document_paths = document_list_str.split(",")
772
+ if len(document_paths) == 1:
773
+ document_paths = document_paths[0]
774
+ document_paths = document_paths.split(" ")
775
+ dataset_name = items[4].children[0].strip("'\"")
776
+ return {"type": "import_docs_into_dataset", "dataset_name": dataset_name, "document_paths": document_paths}
777
+
778
+ def search_on_datasets(self, items):
779
+ question = items[1].children[0].strip("'\"")
780
+ datasets_str = items[4].children[0].strip("'\"")
781
+ datasets = datasets_str.split(",")
782
+ if len(datasets) == 1:
783
+ datasets = datasets[0]
784
+ datasets = datasets.split(" ")
785
+ return {"type": "search_on_datasets", "datasets": datasets, "question": question}
786
+
787
+ def get_chunk(self, items):
788
+ chunk_id = items[2].children[0].strip("'\"")
789
+ return {"type": "get_chunk", "chunk_id": chunk_id}
790
+
791
+ def insert_dataset_from_file(self, items):
792
+ file_path = items[4].children[0].strip("'\"")
793
+ return {"type": "insert_dataset_from_file", "file_path": file_path}
794
+
795
+ def insert_metadata_from_file(self, items):
796
+ file_path = items[4].children[0].strip("'\"")
797
+ return {"type": "insert_metadata_from_file", "file_path": file_path}
798
+
799
+ def generate_nav_for_dataset(self, items):
800
+ dataset_id = items[4].children[0].strip("'\"")
801
+ return {"type": "generate_nav_for_dataset", "dataset_id": dataset_id}
802
+
803
+ def navigation_search(self, items):
804
+ query = items[2].children[0].strip("'\"")
805
+ dataset_name = items[5].children[0].strip("'\"")
806
+ mode = items[7].children[0].strip("'\"")
807
+ topk = None
808
+ # If TOPK was specified, items will be longer.
809
+ if len(items) > 9:
810
+ try:
811
+ extra = items[8]
812
+ if hasattr(extra, "data"):
813
+ # group wrapper: extra.children = [TOPK, NUMBER]
814
+ topk = int(extra.children[1])
815
+ else:
816
+ # flattened: items[8] = TOPK, items[9] = NUMBER
817
+ topk = int(items[9])
818
+ except (ValueError, IndexError):
819
+ topk = None
820
+ return {
821
+ "type": "navigation_search",
822
+ "query": query,
823
+ "dataset_id": dataset_name,
824
+ "mode": mode,
825
+ "topk": topk,
826
+ }
827
+
828
+ def update_chunk(self, items):
829
+ def get_quoted_value(item):
830
+ if hasattr(item, "children") and item.children:
831
+ return item.children[0].strip("'\"")
832
+ return str(item).strip("'\"")
833
+
834
+ chunk_id = get_quoted_value(items[2])
835
+ dataset_name = get_quoted_value(items[5])
836
+ json_body = get_quoted_value(items[7])
837
+ return {"type": "update_chunk", "chunk_id": chunk_id, "dataset_name": dataset_name, "json_body": json_body}
838
+
839
+ def set_metadata(self, items):
840
+ doc_id = items[4].children[0].strip("'\"")
841
+ meta_json = items[6].children[0].strip("'\"")
842
+ return {"type": "set_metadata", "doc_id": doc_id, "meta": meta_json}
843
+
844
+ def remove_tags(self, items):
845
+ # items: REMOVE, TAGS, quoted_string(tag1), quoted_string(tag2), ..., FROM, DATASET, quoted_string(dataset_name), ";"
846
+ tags = []
847
+ # Start from index 2 (after TAGS keyword) and parse quoted strings until FROM
848
+ for i in range(2, len(items)):
849
+ item = items[i]
850
+ # Check for FROM token to stop
851
+ if hasattr(item, "type") and item.type == "FROM":
852
+ break
853
+ if hasattr(item, "children") and item.children:
854
+ tag = item.children[0].strip("'\"")
855
+ tags.append(tag)
856
+ # Find dataset_name: quoted_string after DATASET
857
+ dataset_name = None
858
+ for i, item in enumerate(items):
859
+ # Check if item is a DATASET token
860
+ if hasattr(item, "type") and item.type == "DATASET":
861
+ # Next item should be quoted_string
862
+ dataset_name = items[i + 1].children[0].strip("'\"")
863
+ break
864
+ return {"type": "remove_tags", "dataset_name": dataset_name, "tags": tags}
865
+
866
+ def remove_chunks(self, items):
867
+ # Handle two cases:
868
+ # 1. REMOVE CHUNKS quoted_string (COMMA quoted_string)* FROM DOCUMENT quoted_string ";"
869
+ # 2. REMOVE ALL CHUNKS FROM DOCUMENT quoted_string ";"
870
+
871
+ # Check if it's "REMOVE ALL CHUNKS"
872
+ for item in items:
873
+ if hasattr(item, "type") and item.type == "ALL":
874
+ # Find doc_id
875
+ for j, inner_item in enumerate(items):
876
+ if hasattr(inner_item, "type") and inner_item.type == "DOCUMENT":
877
+ doc_id = items[j + 1].children[0].strip("'\"")
878
+ return {"type": "remove_chunks", "doc_id": doc_id, "delete_all": True}
879
+
880
+ # Otherwise, we have chunk_ids
881
+ chunk_ids = []
882
+ doc_id = None
883
+ for i, item in enumerate(items):
884
+ if hasattr(item, "type") and item.type == "DOCUMENT":
885
+ doc_id = items[i + 1].children[0].strip("'\"")
886
+ elif hasattr(item, "children") and item.children:
887
+ val = item.children[0].strip("'\"")
888
+ # Skip if it's "FROM" or "DOCUMENT"
889
+ if val.upper() in ["FROM", "DOCUMENT"]:
890
+ continue
891
+ chunk_ids.append(val)
892
+
893
+ return {"type": "remove_chunks", "doc_id": doc_id, "chunk_ids": chunk_ids}
894
+
895
+ def list_chunks(self, items):
896
+ doc_id = items[4].children[0].strip("'\"")
897
+ result = {"type": "list_chunks", "doc_id": doc_id}
898
+
899
+ # Parse optional parameters: PAGE, SIZE, KEYWORDS, AVAILABLE
900
+ # items structure varies based on which params are present
901
+ for i, item in enumerate(items):
902
+ if str(item) == "PAGE":
903
+ result["page"] = int(items[i + 1])
904
+ elif str(item) == "SIZE":
905
+ result["size"] = int(items[i + 1])
906
+ elif str(item) == "KEYWORDS":
907
+ result["keywords"] = items[i + 1].children[0].strip("'\"")
908
+ elif str(item) == "AVAILABLE":
909
+ result["available_int"] = int(items[i + 1])
910
+
911
+ return result
912
+
913
+ def benchmark(self, items):
914
+ concurrency: int = int(items[1])
915
+ iterations: int = int(items[2])
916
+ command = items[3].children[0]
917
+ return {"type": "benchmark", "concurrency": concurrency, "iterations": iterations, "command": command}
918
+
919
+ def action_list(self, items):
920
+ return items
921
+
922
+ def meta_command(self, items):
923
+ command_name = str(items[0]).lower()
924
+ args = items[1:] if len(items) > 1 else []
925
+
926
+ # handle quoted parameter
927
+ parsed_args = []
928
+ for arg in args:
929
+ if hasattr(arg, "value"):
930
+ parsed_args.append(arg.value)
931
+ else:
932
+ parsed_args.append(str(arg))
933
+
934
+ return {"type": "meta", "command": command_name, "args": parsed_args}
935
+
936
+ def meta_command_name(self, items):
937
+ return items[0]
938
+
939
+ def meta_args(self, items):
940
+ return items