/
codein
/
aiaa_llm_app
Обзор
Документация
Войти
/
codein
/
aiaa_llm_app
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/llm_graph_app/graph.py
66 строк
2 KB
Sergey
feat: llm app example
11 май 2026, 23:31
11 май 2026, 23:31
512464c
Код
Авторство
О чём код?
from functools import partial from typing import Literal from langchain_gigachat import GigaChat from langgraph.graph import StateGraph, START, END from langgraph.graph.state import CompiledStateGraph from llm_graph_app.nodes import ( fill_schema, review_schema, human_interrupt, call_agent, analysis_declined, ) from llm_graph_app.schemas import IncidentSchema, ReviewSchema from llm_graph_app.states import InputState, OutputState, OverallState from react_agent.agent import create_log_analyze_agent model = GigaChat(model="GigaChat-2-Pro", verify_ssl_certs=False) model_with_incident_so = model.with_structured_output(IncidentSchema) model_with_feedback_so = model.with_structured_output(ReviewSchema) agent = create_log_analyze_agent(model) def ready_for_work(state: OverallState) -> Literal["yes", "one_more_attempt", "no"]: if state.review_schema.ready_for_work: return "yes" if state.review_attempts >= 0: return "one_more_attempt" return "no" def build_graph() -> CompiledStateGraph: graph = StateGraph( state_schema=OverallState, input_schema=InputState, output_schema=OutputState ) graph.add_node("fill_schema", partial(fill_schema, model_with_incident_so)) graph.add_node("review_schema", partial(review_schema, model_with_feedback_so)) graph.add_node("human_interrupt", human_interrupt) graph.add_node("call_agent", partial(call_agent, agent)) graph.add_node("analysis_declined", analysis_declined) graph.add_edge(START, "fill_schema") graph.add_edge("fill_schema", "review_schema") graph.add_conditional_edges( "review_schema", ready_for_work, { "yes": "call_agent", "one_more_attempt": "human_interrupt", "no": "analysis_declined", }, ) graph.add_edge("human_interrupt", "fill_schema") graph.add_edge("call_agent", END) return graph.compile() graph = build_graph()