File size: 1,521 Bytes
b4856f1
2473009
b4856f1
752f5cc
b4856f1
 
 
 
 
 
 
 
 
752f5cc
b4856f1
 
752f5cc
b4856f1
752f5cc
b4856f1
 
 
eb6b502
b4856f1
 
752f5cc
b4856f1
752f5cc
b4856f1
 
eb6b502
 
b4856f1
 
752f5cc
b4856f1
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
vectorizationAgentGraph.py - Vectorization Agent Graph for text-to-vector conversion
"""

from langgraph.graph import StateGraph, END
from src.states.vectorizationAgentState import VectorizationAgentState
from src.nodes.vectorizationAgentNode import VectorizationAgentNode
from src.llms.groqllm import GroqLLM


class VectorizationGraphBuilder:
    def __init__(self, llm=None):
        self.llm = llm or GroqLLM().get_llm()

    def build_graph(self):
        node = VectorizationAgentNode(self.llm)

        graph = StateGraph(VectorizationAgentState)

        graph.add_node("detect_languages", node.detect_languages)
        graph.add_node("vectorize_texts", node.vectorize_texts)
        graph.add_node("anomaly_detection", node.run_anomaly_detection)
        graph.add_node("trending_detection", node.run_trending_detection)
        graph.add_node("generate_expert_summary", node.generate_expert_summary)
        graph.add_node("format_output", node.format_final_output)

        graph.set_entry_point("detect_languages")

        graph.add_edge("detect_languages", "vectorize_texts")
        graph.add_edge("vectorize_texts", "anomaly_detection")
        graph.add_edge("anomaly_detection", "trending_detection")
        graph.add_edge("trending_detection", "generate_expert_summary")
        graph.add_edge("generate_expert_summary", "format_output")
        graph.add_edge("format_output", END)

        return graph.compile()


llm = GroqLLM().get_llm()
graph = VectorizationGraphBuilder(llm).build_graph()