add system propmt
This commit is contained in:
parent
0fe58687f8
commit
d5a32a534f
|
|
@ -22,12 +22,13 @@ def chat():
|
|||
graph_id = data.get("graph_id")
|
||||
parent_node_id = data.get(
|
||||
"parent_node_id") # Получаем parent_node_id из запроса
|
||||
system_prompt = data.get("system_prompt")
|
||||
|
||||
if not message:
|
||||
return jsonify({"error": "Сообщение не может быть пустым."}, 400)
|
||||
|
||||
result = run_agent(message, graph_id,
|
||||
parent_node_id) # Передаем parent_node_id в run_agent
|
||||
parent_node_id, system_prompt) # Передаем parent_node_id в run_agent
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,3 +36,5 @@ class AgentState(BaseModel):
|
|||
# Оно используется для передачи контекста между узлами в пределах одного выполнения
|
||||
temporary_chat_history: List[Dict[str, Any]] = Field(
|
||||
[], description="Временная история чата, не сохраняемая в БД.")
|
||||
system_prompt: Optional[str] = Field(None,
|
||||
description="Системный промпт.")
|
||||
|
|
@ -140,7 +140,7 @@ def execute_command_node(state: AgentState) -> AgentState:
|
|||
|
||||
# Предполагаем, что используем Gemini для основного LLM и суммаризации/анализа
|
||||
# В реальной системе можно выбрать динамически
|
||||
DEFAULT_LLM_NAME = "gemini-2.5-flash"
|
||||
DEFAULT_LLM_NAME = "gemini-2.0-flash" #"gemini-2.5-flash"
|
||||
main_llm = get_llm(DEFAULT_LLM_NAME)
|
||||
|
||||
|
||||
|
|
@ -151,9 +151,12 @@ def call_llm_node(state: AgentState) -> AgentState:
|
|||
"""
|
||||
print("Выполняется узел: call_llm_node (для обычного чата)")
|
||||
try:
|
||||
# TODO: добавить в переписку ещё SystemMessage с системным промптом, типа: messages_for_llm.append(SystemMessage(content=msg["content"]))
|
||||
# Для обычного чата LLM использует текущую временную историю
|
||||
messages_for_llm = []
|
||||
|
||||
if state.system_prompt:
|
||||
messages_for_llm.append(SystemMessage(content=state.system_prompt))
|
||||
|
||||
# Для обычного чата LLM использует текущую временную историю
|
||||
for msg in state.temporary_chat_history: # Используем temporary_chat_history
|
||||
if msg["role"] == "user":
|
||||
messages_for_llm.append(HumanMessage(content=msg["content"]))
|
||||
|
|
|
|||
|
|
@ -92,7 +92,8 @@ app = workflow.compile()
|
|||
|
||||
def run_agent(user_input: str,
|
||||
existing_graph_id: Optional[str] = None,
|
||||
parent_node_id: Optional[str] = None) -> Dict[str, Any]:
|
||||
parent_node_id: Optional[str] = None,
|
||||
system_prompt: Optional[str] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
Запускает агента с заданным пользовательским вводом.
|
||||
Может продолжить существующий граф по graph_id.
|
||||
|
|
@ -100,7 +101,7 @@ def run_agent(user_input: str,
|
|||
"""
|
||||
|
||||
# ---------------------------------------------------- Initial State Setup ----------------------------------------------------------------
|
||||
initial_state = AgentState(input=user_input, parent_node_id=parent_node_id)
|
||||
initial_state = AgentState(input=user_input, parent_node_id=parent_node_id, system_prompt=system_prompt)
|
||||
|
||||
# Сохраняем исходные ID узлов и ребер для определения новых после выполнения графа
|
||||
original_node_ids: Set[str] = set()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user