Add online mining v2 skill
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from online_mining_common import (
|
||||
build_client,
|
||||
compact_text,
|
||||
deep_parse,
|
||||
emit_error,
|
||||
emit_success,
|
||||
extract_case,
|
||||
load_json_payload,
|
||||
search_docs,
|
||||
source_config,
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
try:
|
||||
payload = load_json_payload()
|
||||
sources = payload.get("sources") or ["main", "pre_processing"]
|
||||
date = payload.get("date")
|
||||
sample_size = int(payload.get("sample_size") or 5)
|
||||
result: dict[str, object] = {}
|
||||
for source in sources:
|
||||
config = source_config(str(source))
|
||||
client = build_client(str(source))
|
||||
caps = client.field_caps(index=str(config["index"]), fields="*")
|
||||
fields = caps.get("fields", {})
|
||||
docs = search_docs(source=str(source), date=date, size=sample_size)
|
||||
cases = [extract_case(str(source), deep_parse(doc)) for doc in docs]
|
||||
interesting = [
|
||||
name
|
||||
for name in fields
|
||||
if any(
|
||||
token in name.lower()
|
||||
for token in [
|
||||
"request",
|
||||
"query",
|
||||
"session",
|
||||
"domain",
|
||||
"func",
|
||||
"device",
|
||||
"prompt",
|
||||
"planning",
|
||||
"dispatch",
|
||||
"excellent",
|
||||
"llm",
|
||||
"timestamp",
|
||||
]
|
||||
)
|
||||
]
|
||||
result[str(source)] = {
|
||||
"index": config["index"],
|
||||
"id_field": config["id_field"],
|
||||
"time_field": config["time_field"],
|
||||
"field_count": len(fields),
|
||||
"interesting_fields": sorted(interesting)[:200],
|
||||
"samples": [
|
||||
{
|
||||
key: compact_text(value, 600)
|
||||
for key, value in case.items()
|
||||
if key != "raw" and value not in (None, "", [], {})
|
||||
}
|
||||
for case in cases
|
||||
],
|
||||
}
|
||||
emit_success({"sources": result})
|
||||
return 0
|
||||
except Exception as exc: # noqa: BLE001
|
||||
emit_error(exc)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
||||
Reference in New Issue
Block a user