AnyLlmSearchDocument
Full text search of a LLM document for a text pattern (regex) for more results as a companion to similarity search that returns a few top results. Currently supports only war room file entries, search results, and text that has been preprocessed in XSOAR prior to uploading to the LLM. (See AnyLlmUploadText, AnyLlmUploadFileEntry and AnyLlmUploadDocument). Results are placed in the search results buffer for where they can be added to the LLM's conversation context.
python · Anything LLM
Source
import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 def parsetitle(title: str): # Strip the entry_id when processed text file is uploaded from XSOAR "225@12345_title" - see integration as well parts = title.split("_", 1) if len(parts) == 2 and "@" in parts[0]: return (parts[0], parts[1]) else: return ("", title) def main(): try: args = demisto.args() title = args.get("title", "") pattern = args.get("pattern", "") if title == "": raise Exception("The document title parameter was not provided") documents = execute_command("anyllm-document-list", {}) entry_id = "" for d in documents["localFiles"]["items"][0]["items"]: eid, doctitle = parsetitle(d["title"]) if d["title"] == title.lower(): entry_id = eid break res = [] if entry_id != "": file_path = demisto.getFilePath(entry_id)["path"] f = open(file_path, "rb") data = f.read().decode("utf-8") f.close() results = re.findall(pattern, data, re.MULTILINE) if len(results) > 0: if isinstance(results[0], str): execute_command("setIncident", {"customFields": {"anythingllmsearchresults": "\n".join(results)}}) elif isinstance(results[0], tuple): for r in results: res.append(" ".join(r)) execute_command("setIncident", {"customFields": {"anythingllmsearchresults": "\n".join(res)}}) else: raise Exception(f"Document [{title}] not found") except Exception as ex: demisto.error(traceback.format_exc()) return_error(f"AnyLlmSearchDocument: error is - {ex}") if __name__ in ("__main__", "__builtin__", "builtins"): main()
README
Full text search of a LLM document for a text pattern (regex) for more results as a companion to similarity search that returns a few top results. Currently supports only war room file entries, search results, and text that has been preprocessed in XSOAR prior to uploading to the LLM. (See AnyLlmUploadText, AnyLlmUploadFileEntry and AnyLlmUploadDocument). Results are placed in the search results buffer for where they can be added to the LLM’s conversation context
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
Inputs
| Argument Name | Description |
|---|---|
| title | title of the LLM document to search with the XSOAR file entry ID. Example: “37@25496_anythingllm.txt” |
| pattern | regex to search text for [ see re.findall() ] |
Outputs
There are no outputs for this script.