(self)
| 138 | convert_response_to_json_func: callable = convert_response_to_json |
| 139 | |
| 140 | def __post_init__(self): |
| 141 | _print_config = ",\n ".join([f"{k} = {v}" for k, v in asdict(self).items()]) |
| 142 | logger.debug(f"GraphRAG init with param:\n\n {_print_config}\n") |
| 143 | |
| 144 | self.tokenizer_wrapper = TokenizerWrapper( |
| 145 | tokenizer_type=self.tokenizer_type, |
| 146 | model_name=self.tiktoken_model_name if self.tokenizer_type == "tiktoken" else self.huggingface_model_name |
| 147 | ) |
| 148 | |
| 149 | if self.using_azure_openai: |
| 150 | # If there's no OpenAI API key, use Azure OpenAI |
| 151 | if self.best_model_func == gpt_4o_complete: |
| 152 | self.best_model_func = azure_gpt_4o_complete |
| 153 | if self.cheap_model_func == gpt_4o_mini_complete: |
| 154 | self.cheap_model_func = azure_gpt_4o_mini_complete |
| 155 | if self.embedding_func == openai_embedding: |
| 156 | self.embedding_func = azure_openai_embedding |
| 157 | logger.info( |
| 158 | "Switched the default openai funcs to Azure OpenAI if you didn't set any of it" |
| 159 | ) |
| 160 | |
| 161 | if self.using_amazon_bedrock: |
| 162 | self.best_model_func = create_amazon_bedrock_complete_function(self.best_model_id) |
| 163 | self.cheap_model_func = create_amazon_bedrock_complete_function(self.cheap_model_id) |
| 164 | self.embedding_func = amazon_bedrock_embedding |
| 165 | logger.info( |
| 166 | "Switched the default openai funcs to Amazon Bedrock" |
| 167 | ) |
| 168 | |
| 169 | if not os.path.exists(self.working_dir) and self.always_create_working_dir: |
| 170 | logger.info(f"Creating working directory {self.working_dir}") |
| 171 | os.makedirs(self.working_dir) |
| 172 | |
| 173 | self.full_docs = self.key_string_value_json_storage_cls( |
| 174 | namespace="full_docs", global_config=asdict(self) |
| 175 | ) |
| 176 | |
| 177 | self.text_chunks = self.key_string_value_json_storage_cls( |
| 178 | namespace="text_chunks", global_config=asdict(self) |
| 179 | ) |
| 180 | |
| 181 | self.llm_response_cache = ( |
| 182 | self.key_string_value_json_storage_cls( |
| 183 | namespace="llm_response_cache", global_config=asdict(self) |
| 184 | ) |
| 185 | if self.enable_llm_cache |
| 186 | else None |
| 187 | ) |
| 188 | |
| 189 | self.community_reports = self.key_string_value_json_storage_cls( |
| 190 | namespace="community_reports", global_config=asdict(self) |
| 191 | ) |
| 192 | self.chunk_entity_relation_graph = self.graph_storage_cls( |
| 193 | namespace="chunk_entity_relation", global_config=asdict(self) |
| 194 | ) |
| 195 | |
| 196 | self.embedding_func = limit_async_func_call(self.embedding_func_max_async)( |
| 197 | self.embedding_func |
nothing calls this directly
no test coverage detected