Files
agentic-soc-platform/Lib/llmapi.py
T

41 lines
1.5 KiB
Python
Raw Permalink Normal View History

2025-09-07 20:02:11 +08:00
from typing import Annotated, Any, Dict, List
2025-12-25 11:55:39 +08:00
from langchain_core.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate
2025-09-07 20:02:11 +08:00
from langgraph.graph import add_messages
from pydantic import BaseModel
2025-12-25 11:55:39 +08:00
from Lib.log import logger
2026-01-26 02:55:38 +08:00
from PLUGINS.SIRP.sirpmodel import CaseModel, AlertModel, ArtifactModel
2025-12-25 11:55:39 +08:00
2025-09-07 20:02:11 +08:00
2026-01-27 02:57:23 +08:00
class BaseAgentState(BaseModel):
2025-11-22 20:49:27 +08:00
messages: Annotated[List[Any], add_messages] = []
2026-01-26 02:55:38 +08:00
case: CaseModel = None
alert: AlertModel = None
artifact: ArtifactModel = None
2025-11-22 20:49:27 +08:00
temp_data: Dict[str, Any] = {}
analyze_result: Dict[str, Any] = {}
2025-12-25 11:55:39 +08:00
def load_system_prompt_template(template_path):
"""Load system prompt template"""
try:
with open(template_path, 'r', encoding='utf-8') as f:
system_prompt_template: SystemMessagePromptTemplate = SystemMessagePromptTemplate.from_template(f.read())
logger.debug(f"Loaded system prompt template from: {template_path}")
return system_prompt_template
except Exception as e:
logger.warning(f"Failed to load prompt template {template_path}: {str(e)}")
raise e
def load_human_prompt_template(template_path):
try:
with open(template_path, 'r', encoding='utf-8') as f:
human_prompt_template: HumanMessagePromptTemplate = HumanMessagePromptTemplate.from_template(f.read())
logger.debug(f"Loaded human prompt template from: {template_path}")
return human_prompt_template
except Exception as e:
logger.warning(f"Failed to load prompt template {template_path}: {str(e)}")
raise e