AnyLlmQuestion
Sends a message to the LLM. If any search results have been added to the conversation, they are added to the LLM workspace thread's context just before the latest message is added. The pending search results buffer is then cleared.
- Type
- python
- Pack
- AnythingLLM
Source
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401
from datetime import datetime
import uuid
def main():
try:
args = demisto.args()
question = args.get("question", "")
mode = args.get("mode", "")
if mode == "" or question == "":
raise Exception("The question or mode parameters were not provided")
inci = demisto.incident()["CustomFields"]
workspace = inci["anythingllmworkspace"]
context = inci.get("anythingllmnewcontext", "")
t = inci.get("anythingllmcurthread", "")
if t == "":
threads = {}
else:
threads = json.loads(t)
thread = threads.get(workspace, "")
if thread == "":
thread_uuid = str(uuid.uuid4())
threads[workspace] = thread_uuid
execute_command("anyllm-workspace-thread-new", {"workspace": workspace, "thread": thread_uuid})
execute_command("setIncident", {"customFields": {"anythingllmcurthread": json.dumps(threads)}})
else:
thread_uuid = threads[workspace]
now = datetime.now().strftime("%Y %B %d %I:%M%p")
results = execute_command(
"anyllm-workspace-thread-chat",
{"message": f"{context}\n{question}", "mode": mode, "workspace": inci["anythingllmworkspace"], "thread": thread_uuid},
)
convo = f"{inci.get('anythingllmconversation', '')} \n\n##### {now} [{mode}]: {question}\n\n{results['textResponse']}\n"
convo += "\n**Embedded Chunks Used**\n"
for s in results["sources"]:
convo += f"* {s['score']:0.2f}, {s['title']}\n"
execute_command("setIncident", {"customFields": {"anythingllmconversation": convo, "anythingllmnewcontext": ""}})
except Exception as ex:
demisto.error(traceback.format_exc())
return_error(f"AnyLlmQuestion: error is - {ex}")
if __name__ in ("__main__", "__builtin__", "builtins"):
main()
README
Sends a message to the LLM. If any search results have been added to the conversation, they are added to the LLM workspace thread’s context just before the latest message is added. The pending search results buffer is then cleared
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
Inputs
| Argument Name | Description |
|---|---|
| question | The question or message to send to the LLM |
| mode | “chat” mode uses the LLMs full training data and “query” mode requires some results found in the embedded documents in addition to the LLM’s conversation context |
Outputs
There are no outputs for this script.