| 76 | |
| 77 | |
| 78 | class TestGraph(AbstractGraph): |
| 79 | def __init__(self, prompt: str, config: dict): |
| 80 | super().__init__(prompt, config) |
| 81 | |
| 82 | def _create_graph(self) -> BaseGraph: |
| 83 | fetch_node = FetchNode( |
| 84 | input="url| local_dir", |
| 85 | output=["doc"], |
| 86 | node_config={ |
| 87 | "llm_model": self.llm_model, |
| 88 | "force": self.config.get("force", False), |
| 89 | "cut": self.config.get("cut", True), |
| 90 | "loader_kwargs": self.config.get("loader_kwargs", {}), |
| 91 | "browser_base": self.config.get("browser_base"), |
| 92 | }, |
| 93 | ) |
| 94 | parse_node = ParseNode( |
| 95 | input="doc", |
| 96 | output=["parsed_doc"], |
| 97 | node_config={"llm_model": self.llm_model, "chunk_size": self.model_token}, |
| 98 | ) |
| 99 | return BaseGraph( |
| 100 | nodes=[fetch_node, parse_node], |
| 101 | edges=[ |
| 102 | (fetch_node, parse_node), |
| 103 | ], |
| 104 | entry_point=fetch_node, |
| 105 | graph_name=self.__class__.__name__, |
| 106 | ) |
| 107 | |
| 108 | def run(self) -> str: |
| 109 | inputs = {"user_prompt": self.prompt, self.input_key: self.source} |
| 110 | self.final_state, self.execution_info = self.graph.execute(inputs) |
| 111 | |
| 112 | return self.final_state.get("answer", "No answer found.") |
| 113 | |
| 114 | |
| 115 | class TestAbstractGraph: |
no outgoing calls