diff --git a/.doctrees/apis/components/_autosummary/components.agent.react.doctree b/.doctrees/apis/components/_autosummary/components.agent.react.doctree index 486116f50..7e1317500 100644 Binary files a/.doctrees/apis/components/_autosummary/components.agent.react.doctree and b/.doctrees/apis/components/_autosummary/components.agent.react.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.api_client.anthropic_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.anthropic_client.doctree deleted file mode 100644 index 0101f44dc..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.api_client.anthropic_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.api_client.google_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.google_client.doctree deleted file mode 100644 index d966f79c3..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.api_client.google_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.api_client.groq_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.groq_client.doctree deleted file mode 100644 index 93adb0a35..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.api_client.groq_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.api_client.openai_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.openai_client.doctree deleted file mode 100644 index c99d7ede3..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.api_client.openai_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.api_client.transformers_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.transformers_client.doctree deleted file mode 100644 index 4f62a145d..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.api_client.transformers_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.data_process.data_components.doctree b/.doctrees/apis/components/_autosummary/components.data_process.data_components.doctree index 99f3b41cc..eecace9b2 100644 Binary files a/.doctrees/apis/components/_autosummary/components.data_process.data_components.doctree and b/.doctrees/apis/components/_autosummary/components.data_process.data_components.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.data_process.document_splitter.doctree b/.doctrees/apis/components/_autosummary/components.data_process.document_splitter.doctree deleted file mode 100644 index 31fc48856..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.data_process.document_splitter.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.data_process.text_splitter.doctree b/.doctrees/apis/components/_autosummary/components.data_process.text_splitter.doctree index 72d5ca295..71199436f 100644 Binary files a/.doctrees/apis/components/_autosummary/components.data_process.text_splitter.doctree and b/.doctrees/apis/components/_autosummary/components.data_process.text_splitter.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.memory.memory.doctree b/.doctrees/apis/components/_autosummary/components.memory.memory.doctree index 562c283b1..96aed50d6 100644 Binary files a/.doctrees/apis/components/_autosummary/components.memory.memory.doctree and b/.doctrees/apis/components/_autosummary/components.memory.memory.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.model_client.anthropic_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.anthropic_client.doctree deleted file mode 100644 index 6d11e536e..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.model_client.anthropic_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.model_client.cohere_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.cohere_client.doctree deleted file mode 100644 index 031ef2d57..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.model_client.cohere_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.model_client.google_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.google_client.doctree deleted file mode 100644 index db9e06aa0..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.model_client.google_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.model_client.groq_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.groq_client.doctree deleted file mode 100644 index 8e5e20c1e..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.model_client.groq_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.model_client.openai_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.openai_client.doctree deleted file mode 100644 index b1914bc94..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.model_client.openai_client.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.model_client.transformers_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.transformers_client.doctree index 8a4e8a608..91b1092d9 100644 Binary files a/.doctrees/apis/components/_autosummary/components.model_client.transformers_client.doctree and b/.doctrees/apis/components/_autosummary/components.model_client.transformers_client.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.model_client.utils.doctree b/.doctrees/apis/components/_autosummary/components.model_client.utils.doctree index 0c99dc29a..5d89079dc 100644 Binary files a/.doctrees/apis/components/_autosummary/components.model_client.utils.doctree and b/.doctrees/apis/components/_autosummary/components.model_client.utils.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.output_parsers.outputs.doctree b/.doctrees/apis/components/_autosummary/components.output_parsers.outputs.doctree index 9e42d59d6..01db20189 100644 Binary files a/.doctrees/apis/components/_autosummary/components.output_parsers.outputs.doctree and b/.doctrees/apis/components/_autosummary/components.output_parsers.outputs.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.reasoning.chain_of_thought.doctree b/.doctrees/apis/components/_autosummary/components.reasoning.chain_of_thought.doctree index 62a2750f5..23cdf92b8 100644 Binary files a/.doctrees/apis/components/_autosummary/components.reasoning.chain_of_thought.doctree and b/.doctrees/apis/components/_autosummary/components.reasoning.chain_of_thought.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.retriever.bm25_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.bm25_retriever.doctree index 02f12493b..38e2ae705 100644 Binary files a/.doctrees/apis/components/_autosummary/components.retriever.bm25_retriever.doctree and b/.doctrees/apis/components/_autosummary/components.retriever.bm25_retriever.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.retriever.faiss_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.faiss_retriever.doctree deleted file mode 100644 index e4ddf88eb..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.retriever.faiss_retriever.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.retriever.llm_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.llm_retriever.doctree index 31d5bed98..89a03c356 100644 Binary files a/.doctrees/apis/components/_autosummary/components.retriever.llm_retriever.doctree and b/.doctrees/apis/components/_autosummary/components.retriever.llm_retriever.doctree differ diff --git a/.doctrees/apis/components/_autosummary/components.retriever.postgres_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.postgres_retriever.doctree deleted file mode 100644 index b25e95c96..000000000 Binary files a/.doctrees/apis/components/_autosummary/components.retriever.postgres_retriever.doctree and /dev/null differ diff --git a/.doctrees/apis/components/_autosummary/components.retriever.reranker_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.reranker_retriever.doctree index 77d6e94a9..21b5bbf42 100644 Binary files a/.doctrees/apis/components/_autosummary/components.retriever.reranker_retriever.doctree and b/.doctrees/apis/components/_autosummary/components.retriever.reranker_retriever.doctree differ diff --git a/.doctrees/apis/components/components.agent.doctree b/.doctrees/apis/components/components.agent.doctree index d0842cd39..4a77c50fa 100644 Binary files a/.doctrees/apis/components/components.agent.doctree and b/.doctrees/apis/components/components.agent.doctree differ diff --git a/.doctrees/apis/components/components.data_process.data_components.doctree b/.doctrees/apis/components/components.data_process.data_components.doctree index a60821a00..9bd8b4983 100644 Binary files a/.doctrees/apis/components/components.data_process.data_components.doctree and b/.doctrees/apis/components/components.data_process.data_components.doctree differ diff --git a/.doctrees/apis/components/components.data_process.doctree b/.doctrees/apis/components/components.data_process.doctree index 9e4e3e709..0b77d57df 100644 Binary files a/.doctrees/apis/components/components.data_process.doctree and b/.doctrees/apis/components/components.data_process.doctree differ diff --git a/.doctrees/apis/components/components.data_process.document_splitter.doctree b/.doctrees/apis/components/components.data_process.document_splitter.doctree deleted file mode 100644 index a0628bd34..000000000 Binary files a/.doctrees/apis/components/components.data_process.document_splitter.doctree and /dev/null differ diff --git a/.doctrees/apis/components/components.data_process.text_splitter.doctree b/.doctrees/apis/components/components.data_process.text_splitter.doctree index d8b87e145..623be3364 100644 Binary files a/.doctrees/apis/components/components.data_process.text_splitter.doctree and b/.doctrees/apis/components/components.data_process.text_splitter.doctree differ diff --git a/.doctrees/apis/components/components.memory.doctree b/.doctrees/apis/components/components.memory.doctree index 7ec837428..1c76a9bbf 100644 Binary files a/.doctrees/apis/components/components.memory.doctree and b/.doctrees/apis/components/components.memory.doctree differ diff --git a/.doctrees/apis/components/components.memory.memory.doctree b/.doctrees/apis/components/components.memory.memory.doctree index 3d720adc9..01980cec3 100644 Binary files a/.doctrees/apis/components/components.memory.memory.doctree and b/.doctrees/apis/components/components.memory.memory.doctree differ diff --git a/.doctrees/apis/components/components.model_client.doctree b/.doctrees/apis/components/components.model_client.doctree index 01456837e..cde8ee131 100644 Binary files a/.doctrees/apis/components/components.model_client.doctree and b/.doctrees/apis/components/components.model_client.doctree differ diff --git a/.doctrees/apis/components/components.model_client.utils.doctree b/.doctrees/apis/components/components.model_client.utils.doctree index c257171ce..f16206eb5 100644 Binary files a/.doctrees/apis/components/components.model_client.utils.doctree and b/.doctrees/apis/components/components.model_client.utils.doctree differ diff --git a/.doctrees/apis/components/components.output_parsers.doctree b/.doctrees/apis/components/components.output_parsers.doctree index eca769ce9..1576c9da4 100644 Binary files a/.doctrees/apis/components/components.output_parsers.doctree and b/.doctrees/apis/components/components.output_parsers.doctree differ diff --git a/.doctrees/apis/components/components.reasoning.doctree b/.doctrees/apis/components/components.reasoning.doctree index 7175f30af..84a200fce 100644 Binary files a/.doctrees/apis/components/components.reasoning.doctree and b/.doctrees/apis/components/components.reasoning.doctree differ diff --git a/.doctrees/apis/components/components.retriever.doctree b/.doctrees/apis/components/components.retriever.doctree index 97458929b..6c27b101d 100644 Binary files a/.doctrees/apis/components/components.retriever.doctree and b/.doctrees/apis/components/components.retriever.doctree differ diff --git a/.doctrees/apis/components/index.doctree b/.doctrees/apis/components/index.doctree index a5fec8f50..77de0a55b 100644 Binary files a/.doctrees/apis/components/index.doctree and b/.doctrees/apis/components/index.doctree differ diff --git a/.doctrees/apis/core/core.base_data_class.doctree b/.doctrees/apis/core/core.base_data_class.doctree index af9aa2076..485abdfdf 100644 Binary files a/.doctrees/apis/core/core.base_data_class.doctree and b/.doctrees/apis/core/core.base_data_class.doctree differ diff --git a/.doctrees/apis/core/core.component.doctree b/.doctrees/apis/core/core.component.doctree index 525540494..e8e99c73d 100644 Binary files a/.doctrees/apis/core/core.component.doctree and b/.doctrees/apis/core/core.component.doctree differ diff --git a/.doctrees/apis/core/core.data_components.doctree b/.doctrees/apis/core/core.data_components.doctree deleted file mode 100644 index 623085f24..000000000 Binary files a/.doctrees/apis/core/core.data_components.doctree and /dev/null differ diff --git a/.doctrees/apis/core/core.db.doctree b/.doctrees/apis/core/core.db.doctree index 79f65e847..feaeb5c5d 100644 Binary files a/.doctrees/apis/core/core.db.doctree and b/.doctrees/apis/core/core.db.doctree differ diff --git a/.doctrees/apis/core/core.default_prompt_template.doctree b/.doctrees/apis/core/core.default_prompt_template.doctree index 0fa4b0eb8..797421bbf 100644 Binary files a/.doctrees/apis/core/core.default_prompt_template.doctree and b/.doctrees/apis/core/core.default_prompt_template.doctree differ diff --git a/.doctrees/apis/core/core.document_splitter.doctree b/.doctrees/apis/core/core.document_splitter.doctree deleted file mode 100644 index 3a4536687..000000000 Binary files a/.doctrees/apis/core/core.document_splitter.doctree and /dev/null differ diff --git a/.doctrees/apis/core/core.embedder.doctree b/.doctrees/apis/core/core.embedder.doctree index f550d0f7f..f1a7a205f 100644 Binary files a/.doctrees/apis/core/core.embedder.doctree and b/.doctrees/apis/core/core.embedder.doctree differ diff --git a/.doctrees/apis/core/core.func_tool.doctree b/.doctrees/apis/core/core.func_tool.doctree index d422c5421..d2b248afb 100644 Binary files a/.doctrees/apis/core/core.func_tool.doctree and b/.doctrees/apis/core/core.func_tool.doctree differ diff --git a/.doctrees/apis/core/core.functional.doctree b/.doctrees/apis/core/core.functional.doctree index 8909f3904..662c4fc36 100644 Binary files a/.doctrees/apis/core/core.functional.doctree and b/.doctrees/apis/core/core.functional.doctree differ diff --git a/.doctrees/apis/core/core.generator.doctree b/.doctrees/apis/core/core.generator.doctree index 81796e752..1b471549a 100644 Binary files a/.doctrees/apis/core/core.generator.doctree and b/.doctrees/apis/core/core.generator.doctree differ diff --git a/.doctrees/apis/core/core.memory.doctree b/.doctrees/apis/core/core.memory.doctree deleted file mode 100644 index fa7082323..000000000 Binary files a/.doctrees/apis/core/core.memory.doctree and /dev/null differ diff --git a/.doctrees/apis/core/core.model_client.doctree b/.doctrees/apis/core/core.model_client.doctree index 3efcf212b..57ae74bd1 100644 Binary files a/.doctrees/apis/core/core.model_client.doctree and b/.doctrees/apis/core/core.model_client.doctree differ diff --git a/.doctrees/apis/core/core.parameter.doctree b/.doctrees/apis/core/core.parameter.doctree index 911340e82..02c26fc4d 100644 Binary files a/.doctrees/apis/core/core.parameter.doctree and b/.doctrees/apis/core/core.parameter.doctree differ diff --git a/.doctrees/apis/core/core.prompt_builder.doctree b/.doctrees/apis/core/core.prompt_builder.doctree index 8e21d38e9..20e521cd7 100644 Binary files a/.doctrees/apis/core/core.prompt_builder.doctree and b/.doctrees/apis/core/core.prompt_builder.doctree differ diff --git a/.doctrees/apis/core/core.retriever.doctree b/.doctrees/apis/core/core.retriever.doctree index bbeb3bd37..3940ce780 100644 Binary files a/.doctrees/apis/core/core.retriever.doctree and b/.doctrees/apis/core/core.retriever.doctree differ diff --git a/.doctrees/apis/core/core.string_parser.doctree b/.doctrees/apis/core/core.string_parser.doctree index 4b3bc0905..a4a037ca2 100644 Binary files a/.doctrees/apis/core/core.string_parser.doctree and b/.doctrees/apis/core/core.string_parser.doctree differ diff --git a/.doctrees/apis/core/core.tokenizer.doctree b/.doctrees/apis/core/core.tokenizer.doctree index 31b616991..c3f0ce168 100644 Binary files a/.doctrees/apis/core/core.tokenizer.doctree and b/.doctrees/apis/core/core.tokenizer.doctree differ diff --git a/.doctrees/apis/core/core.tool_manager.doctree b/.doctrees/apis/core/core.tool_manager.doctree index 69f24c968..0fa4a5738 100644 Binary files a/.doctrees/apis/core/core.tool_manager.doctree and b/.doctrees/apis/core/core.tool_manager.doctree differ diff --git a/.doctrees/apis/core/core.types.doctree b/.doctrees/apis/core/core.types.doctree index c263c906d..0cd02a67e 100644 Binary files a/.doctrees/apis/core/core.types.doctree and b/.doctrees/apis/core/core.types.doctree differ diff --git a/.doctrees/apis/core/index.doctree b/.doctrees/apis/core/index.doctree index f2fc4b8ca..4e1a1b016 100644 Binary files a/.doctrees/apis/core/index.doctree and b/.doctrees/apis/core/index.doctree differ diff --git a/.doctrees/apis/eval/eval.answer_match_acc.doctree b/.doctrees/apis/eval/eval.answer_match_acc.doctree index 9d627dd56..29f279755 100644 Binary files a/.doctrees/apis/eval/eval.answer_match_acc.doctree and b/.doctrees/apis/eval/eval.answer_match_acc.doctree differ diff --git a/.doctrees/apis/eval/eval.evaluators.doctree b/.doctrees/apis/eval/eval.evaluators.doctree deleted file mode 100644 index 49b6b37a6..000000000 Binary files a/.doctrees/apis/eval/eval.evaluators.doctree and /dev/null differ diff --git a/.doctrees/apis/eval/eval.llm_as_judge.doctree b/.doctrees/apis/eval/eval.llm_as_judge.doctree index 1cb9617ad..0abea0b37 100644 Binary files a/.doctrees/apis/eval/eval.llm_as_judge.doctree and b/.doctrees/apis/eval/eval.llm_as_judge.doctree differ diff --git a/.doctrees/apis/eval/eval.retriever_recall.doctree b/.doctrees/apis/eval/eval.retriever_recall.doctree index cead7f31c..26174bf0b 100644 Binary files a/.doctrees/apis/eval/eval.retriever_recall.doctree and b/.doctrees/apis/eval/eval.retriever_recall.doctree differ diff --git a/.doctrees/apis/eval/eval.retriever_relevance.doctree b/.doctrees/apis/eval/eval.retriever_relevance.doctree index 867bd209f..851131bc5 100644 Binary files a/.doctrees/apis/eval/eval.retriever_relevance.doctree and b/.doctrees/apis/eval/eval.retriever_relevance.doctree differ diff --git a/.doctrees/apis/index.doctree b/.doctrees/apis/index.doctree index d64381639..4cdadf9ac 100644 Binary files a/.doctrees/apis/index.doctree and b/.doctrees/apis/index.doctree differ diff --git a/.doctrees/apis/optim/optim.few_shot_optimizer.doctree b/.doctrees/apis/optim/optim.few_shot_optimizer.doctree index a5008e8ec..3a487c5dd 100644 Binary files a/.doctrees/apis/optim/optim.few_shot_optimizer.doctree and b/.doctrees/apis/optim/optim.few_shot_optimizer.doctree differ diff --git a/.doctrees/apis/optim/optim.llm_augment.doctree b/.doctrees/apis/optim/optim.llm_augment.doctree index d6eebc969..6adb43c92 100644 Binary files a/.doctrees/apis/optim/optim.llm_augment.doctree and b/.doctrees/apis/optim/optim.llm_augment.doctree differ diff --git a/.doctrees/apis/optim/optim.llm_optimizer.doctree b/.doctrees/apis/optim/optim.llm_optimizer.doctree index 391a08565..5c4cf30b1 100644 Binary files a/.doctrees/apis/optim/optim.llm_optimizer.doctree and b/.doctrees/apis/optim/optim.llm_optimizer.doctree differ diff --git a/.doctrees/apis/optim/optim.optimizer.doctree b/.doctrees/apis/optim/optim.optimizer.doctree index 89db50769..259f0b5b9 100644 Binary files a/.doctrees/apis/optim/optim.optimizer.doctree and b/.doctrees/apis/optim/optim.optimizer.doctree differ diff --git a/.doctrees/apis/optim/optim.sampler.doctree b/.doctrees/apis/optim/optim.sampler.doctree index 3de5bd607..b97437789 100644 Binary files a/.doctrees/apis/optim/optim.sampler.doctree and b/.doctrees/apis/optim/optim.sampler.doctree differ diff --git a/.doctrees/apis/tracing/tracing.decorators.doctree b/.doctrees/apis/tracing/tracing.decorators.doctree index 5dace6b6d..9417f1e1f 100644 Binary files a/.doctrees/apis/tracing/tracing.decorators.doctree and b/.doctrees/apis/tracing/tracing.decorators.doctree differ diff --git a/.doctrees/apis/tracing/tracing.generator_call_logger.doctree b/.doctrees/apis/tracing/tracing.generator_call_logger.doctree index f4193fec8..c3597174d 100644 Binary files a/.doctrees/apis/tracing/tracing.generator_call_logger.doctree and b/.doctrees/apis/tracing/tracing.generator_call_logger.doctree differ diff --git a/.doctrees/apis/tracing/tracing.generator_state_logger.doctree b/.doctrees/apis/tracing/tracing.generator_state_logger.doctree index cc7bc5c3c..c9391cfe9 100644 Binary files a/.doctrees/apis/tracing/tracing.generator_state_logger.doctree and b/.doctrees/apis/tracing/tracing.generator_state_logger.doctree differ diff --git a/.doctrees/apis/utils/index.doctree b/.doctrees/apis/utils/index.doctree index adbdb1a82..45d9eaeef 100644 Binary files a/.doctrees/apis/utils/index.doctree and b/.doctrees/apis/utils/index.doctree differ diff --git a/.doctrees/apis/utils/utils.config.doctree b/.doctrees/apis/utils/utils.config.doctree index cff12b7f0..7c0075abd 100644 Binary files a/.doctrees/apis/utils/utils.config.doctree and b/.doctrees/apis/utils/utils.config.doctree differ diff --git a/.doctrees/apis/utils/utils.file_io.doctree b/.doctrees/apis/utils/utils.file_io.doctree index c7a41d7ae..a664ab1a3 100644 Binary files a/.doctrees/apis/utils/utils.file_io.doctree and b/.doctrees/apis/utils/utils.file_io.doctree differ diff --git a/.doctrees/apis/utils/utils.lazy_import.doctree b/.doctrees/apis/utils/utils.lazy_import.doctree index b4706b362..527f3f890 100644 Binary files a/.doctrees/apis/utils/utils.lazy_import.doctree and b/.doctrees/apis/utils/utils.lazy_import.doctree differ diff --git a/.doctrees/apis/utils/utils.logger.doctree b/.doctrees/apis/utils/utils.logger.doctree index f4dec1c27..abb7d6eb4 100644 Binary files a/.doctrees/apis/utils/utils.logger.doctree and b/.doctrees/apis/utils/utils.logger.doctree differ diff --git a/.doctrees/apis/utils/utils.registry.doctree b/.doctrees/apis/utils/utils.registry.doctree index 2c9b5ea54..7deb99787 100644 Binary files a/.doctrees/apis/utils/utils.registry.doctree and b/.doctrees/apis/utils/utils.registry.doctree differ diff --git a/.doctrees/apis/utils/utils.serialization.doctree b/.doctrees/apis/utils/utils.serialization.doctree index f8efa1c1d..7aa4c32e5 100644 Binary files a/.doctrees/apis/utils/utils.serialization.doctree and b/.doctrees/apis/utils/utils.serialization.doctree differ diff --git a/.doctrees/apis/utils/utils.setup_env.doctree b/.doctrees/apis/utils/utils.setup_env.doctree index d6dc1b86e..eb4abbdc4 100644 Binary files a/.doctrees/apis/utils/utils.setup_env.doctree and b/.doctrees/apis/utils/utils.setup_env.doctree differ diff --git a/.doctrees/developer_notes/component.doctree b/.doctrees/developer_notes/component.doctree index 6be9eea90..1f9dbd195 100644 Binary files a/.doctrees/developer_notes/component.doctree and b/.doctrees/developer_notes/component.doctree differ diff --git a/.doctrees/developer_notes/db.doctree b/.doctrees/developer_notes/db.doctree index ab705c8d2..f013ab8c9 100644 Binary files a/.doctrees/developer_notes/db.doctree and b/.doctrees/developer_notes/db.doctree differ diff --git a/.doctrees/developer_notes/generator.doctree b/.doctrees/developer_notes/generator.doctree index 1bdb32220..c734dfbdd 100644 Binary files a/.doctrees/developer_notes/generator.doctree and b/.doctrees/developer_notes/generator.doctree differ diff --git a/.doctrees/environment.pickle b/.doctrees/environment.pickle index b88e6e2af..b7788bc51 100644 Binary files a/.doctrees/environment.pickle and b/.doctrees/environment.pickle differ diff --git a/.doctrees/get_started/installation.doctree b/.doctrees/get_started/installation.doctree index a1c4e8944..70f2a4331 100644 Binary files a/.doctrees/get_started/installation.doctree and b/.doctrees/get_started/installation.doctree differ diff --git a/_images/database.png b/_images/database.png deleted file mode 100644 index b7903a894..000000000 Binary files a/_images/database.png and /dev/null differ diff --git a/_modules/components/agent/react.html b/_modules/components/agent/react.html index 646a03811..eba7485ed 100644 --- a/_modules/components/agent/react.html +++ b/_modules/components/agent/react.html @@ -29,7 +29,7 @@ - + @@ -499,7 +499,7 @@

Source code for components.agent.react

 
 
 
-[docs] +[docs] class ReActAgent(Component): __doc__ = r"""ReActAgent uses generator as a planner that runs multiple and sequential functional call steps to generate the final response. @@ -575,7 +575,7 @@

Source code for components.agent.react

             func=self._finish,
             answer="final answer: 'answer'",
         )
-        output_parser = JsonOutputParser(data_class=ouput_data_class, example=example)
+        output_parser = JsonOutputParser(data_class=ouput_data_class, examples=example)
         prompt_kwargs = {
             "tools": self.tool_manager.yaml_definitions,
             "output_format_str": output_parser.format_instructions(),
@@ -631,7 +631,7 @@ 

Source code for components.agent.react

         self.tool_manager = ToolManager(tools=tools)
 
 
-[docs] +[docs] def reset(self): r"""Reset the agent to start a new query.""" self.step_history = []
@@ -700,7 +700,7 @@

Source code for components.agent.react

         return response
 
 
-[docs] +[docs] def call( self, input: str, @@ -738,7 +738,7 @@

Source code for components.agent.react

 
 
 if __name__ == "__main__":
-    from components.model_client import GroqAPIClient
+    from lightrag.components.model_client import GroqAPIClient
     from lightrag.core.types import ModelClientType
     from lightrag.utils import setup_env  # noqa
 
diff --git a/_modules/components/data_process/data_components.html b/_modules/components/data_process/data_components.html
index d54fb0624..b2ae43967 100644
--- a/_modules/components/data_process/data_components.html
+++ b/_modules/components/data_process/data_components.html
@@ -29,7 +29,7 @@
 
     
     
-    
+    
     
     
   
diff --git a/_modules/components/data_process/text_splitter.html b/_modules/components/data_process/text_splitter.html
index b84a4a58b..aceb3adab 100644
--- a/_modules/components/data_process/text_splitter.html
+++ b/_modules/components/data_process/text_splitter.html
@@ -29,7 +29,7 @@
 
     
     
-    
+    
     
     
   
@@ -441,24 +441,17 @@ 

Source code for components.data_process.text_splitter

DocumentSplitterOutputType = List[Document] # customizable seperators map -SEPARATORS = { - "page": "\f", - "passage": "\n\n", - "word": " ", - "sentence": ".", - "token": "", -} +SEPARATORS = {"page": "\f", "passage": "\n\n", "word": " ", "sentence": ".", "token": ""} DEFAULT_CHUNK_SIZE = 800 DEFAULT_CHUNK_OVERLAP = 200 tokenizer = Tokenizer() -
[docs] class TextSplitter(Component): - """ + """ Text Splitter for Chunking Documents ``TextSplitter`` first utilizes ``split_by`` to specify the text-splitting criterion and breaks the long text into smaller texts. @@ -467,11 +460,11 @@

Source code for components.data_process.text_splitter

**Splitting Types** - ``TextSplitter`` supports 2 types of splitting. - + ``TextSplitter`` supports 2 types of splitting. + * **Type 1:** Specify the exact text splitting point such as space<" "> and periods<".">. It is intuitive, for example, split_by "word": - :: + :: "Hello, world!" -> ["Hello, " ,"world!"] @@ -485,7 +478,7 @@

Source code for components.data_process.text_splitter

Tokenizer reflects the real token numbers the models take in and helps the developers control budgets. **Definitions** - + * **split_by** specifies the split rule, i.e. the smallest unit during splitting. We support ``"word"``, ``"sentence"``, ``"page"``, ``"passage"``, and ``"token"``. The splitter utilizes the corresponding separator from the ``SEPARATORS`` dictionary. For Type 1 splitting, we apply ``Python str.split()`` to break the text. @@ -494,16 +487,16 @@

Source code for components.data_process.text_splitter

.. note:: For option ``token``, its separator is "" because we directly split by a tokenizer, instead of text point. - * **chunk_size** is the the maximum number of units in each chunk. + * **chunk_size** is the the maximum number of units in each chunk. * **chunk_overlap** is the number of units that each chunk should overlap. Including context at the borders prevents sudden meaning shift in text between sentences/context, especially in sentiment analysis. - + * **Splitting Details** - Type 1: - The ``TextSplitter`` utilizes Python's ``str.split(separator)`` method. - Developers can refer to - + Type 1: + The ``TextSplitter`` utilizes Python's ``str.split(separator)`` method. + Developers can refer to + .. code-block:: none { @@ -513,30 +506,30 @@

Source code for components.data_process.text_splitter

"sentence": "." } for exact points of text division. - + .. note:: Developers need to determine how to assign text to each data chunk for the embedding and retrieval tasks. Type 2: We implement a tokenizer using ``cl100k_base`` encoding that aligns with how models see text in the form of tokens. E.g. "tiktoken is great!" -> ["t", "ik", "token", " is", " great", "!"] This helps developers control the token usage and budget better. - + * **Merge Details** Type 1/Type 2 create a list of split texts. ``TextSplitter`` then reattaches the specified separator to each piece of the split text, except for the last segment. This approach maintains the original spacing and punctuation, which is critical in contexts like natural language processing where text formatting can impact interpretations and outcomes. E.g. "hello world!" split by "word" will be kept as "hello " and "world!" - + * **Customization** - You can also customize the ``SEPARATORS``. For example, by defining ``SEPARATORS`` = {"question": "?"} and setting ``split_by`` = "question", the document will be split at each ``?``, ideal for processing text structured + You can also customize the ``SEPARATORS``. For example, by defining ``SEPARATORS`` = {"question": "?"} and setting ``split_by`` = "question", the document will be split at each ``?``, ideal for processing text structured as a series of questions. If you need to customize :class:`tokenizer <lightrag.core.tokenizer.Tokenizer>`, please check `Reference <https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb>`_. - + * **Integration with Other Document Types** This functionality is ideal for segmenting texts into sentences, words, pages, or passages, which can then be processed further for NLP applications. For **PDFs**, developers will need to extract the text before using the splitter. Libraries like ``PyPDF2`` or ``PDFMiner`` can be utilized for this purpose. ``LightRAG``'s future implementations will introduce splitters for ``JSON``, ``HTML``, ``markdown``, and ``code``. - + Example: - + .. code-block:: python from lightrag.components.data_process.text_splitter import TextSplitter @@ -566,20 +559,19 @@

Source code for components.data_process.text_splitter

# Document(id=ca0af45b-4f88-49b5-97db-163da9868ea4, text='text. Even more text to ', meta_data=None, vector=[], parent_doc_id=doc1, order=1, score=None) # Document(id=e7b617b2-3927-4248-afce-ec0fc247ac8b, text='to illustrate.', meta_data=None, vector=[], parent_doc_id=doc1, order=2, score=None) """ - def __init__( self, split_by: Literal["word", "sentence", "page", "passage", "token"] = "word", chunk_size: int = DEFAULT_CHUNK_SIZE, chunk_overlap: int = DEFAULT_CHUNK_OVERLAP, - batch_size: int = 1000, + batch_size: int = 1000 ): """ Initializes the TextSplitter with the specified parameters for text splitting. Args: - split_by (str): The specific criterion to use for splitting the text. - Valid options are 'word' to split by ' ', 'sentence' to split by '.', + split_by (str): The specific criterion to use for splitting the text. + Valid options are 'word' to split by ' ', 'sentence' to split by '.', 'page' to split by '\\f', 'passage' to split by '\\n\\n'. chunk_size (int): The size of chunks to generate after splitting. Must be greater than 0. chunk_overlap (int): The number of characters of overlap between chunks. Must be non-negative @@ -592,36 +584,26 @@

Source code for components.data_process.text_splitter

super().__init__() self.split_by = split_by - assert ( - split_by in SEPARATORS - ), f"Invalid options for split_by. You must select from {list(SEPARATORS.keys())}." - - assert ( - chunk_overlap < chunk_size - ), f"chunk_overlap can't be larger than or equal to chunk_size. Received chunk_size: {chunk_size}, chunk_overlap: {chunk_overlap}" - - assert ( - chunk_size > 0 - ), f"chunk_size must be greater than 0. Received value: {chunk_size}" + assert split_by in SEPARATORS, f"Invalid options for split_by. You must select from {list(SEPARATORS.keys())}." + + assert chunk_overlap < chunk_size, f"chunk_overlap can't be larger than or equal to chunk_size. Received chunk_size: {chunk_size}, chunk_overlap: {chunk_overlap}" + + assert chunk_size > 0, f"chunk_size must be greater than 0. Received value: {chunk_size}" self.chunk_size = chunk_size - assert ( - chunk_overlap >= 0 - ), f"chunk_overlap must be non-negative. Received value: {chunk_overlap}" + assert chunk_overlap >= 0, f"chunk_overlap must be non-negative. Received value: {chunk_overlap}" self.chunk_overlap = chunk_overlap self.batch_size = batch_size - - log.info( - f"Initialized TextSplitter with split_by={self.split_by}, chunk_size={self.chunk_size}, chunk_overlap={self.chunk_overlap}, batch_size={self.batch_size}" - ) + + log.info(f"Initialized TextSplitter with split_by={self.split_by}, chunk_size={self.chunk_size}, chunk_overlap={self.chunk_overlap}, batch_size={self.batch_size}")
[docs] def split_text(self, text: str) -> List[str]: """ Splits the provided text into chunks. - + Splits based on the specified split_by, chunk size, and chunk overlap settings. Args: @@ -630,15 +612,11 @@

Source code for components.data_process.text_splitter

Returns: List[str]: A list of text chunks. """ - log.info( - f"Splitting text with split_by: {self.split_by}, chunk_size: {self.chunk_size}, chunk_overlap: {self.chunk_overlap}" - ) + log.info(f"Splitting text with split_by: {self.split_by}, chunk_size: {self.chunk_size}, chunk_overlap: {self.chunk_overlap}") separator = SEPARATORS[self.split_by] splits = self._split_text_into_units(text, separator) log.info(f"Text split into {len(splits)} parts.") - chunks = self._merge_units_to_chunks( - splits, self.chunk_size, self.chunk_overlap, separator - ) + chunks = self._merge_units_to_chunks(splits, self.chunk_size, self.chunk_overlap, separator) log.info(f"Text merged into {len(chunks)} chunks.") return chunks
@@ -648,13 +626,13 @@

Source code for components.data_process.text_splitter

def call(self, documents: DocumentSplitterInputType) -> DocumentSplitterOutputType: """ Process the splitting task on a list of documents in batch. - + Batch processes a list of documents, splitting each document's text according to the configured split_by, chunk size, and chunk overlap. Args: documents (List[Document]): A list of Document objects to process. - + Returns: List[Document]: A list of new Document objects, each containing a chunk of text from the original documents. @@ -662,29 +640,20 @@

Source code for components.data_process.text_splitter

TypeError: If 'documents' is not a list or contains non-Document objects. ValueError: If any document's text is None. """ - - if not isinstance(documents, list) or any( - not isinstance(doc, Document) for doc in documents - ): + + if not isinstance(documents, list) or any(not isinstance(doc, Document) for doc in documents): log.error("Input should be a list of Documents.") raise TypeError("Input should be a list of Documents.") - + split_docs = [] # Using range and batch_size to create batches - for start_idx in tqdm( - range(0, len(documents), self.batch_size), - desc="Splitting Documents in Batches", - ): - batch_docs = documents[start_idx : start_idx + self.batch_size] - + for start_idx in tqdm(range(0, len(documents), self.batch_size), desc="Splitting Documents in Batches"): + batch_docs = documents[start_idx:start_idx + self.batch_size] + for doc in batch_docs: if not isinstance(doc, Document): - log.error( - f"Each item in documents should be an instance of Document, but got {type(doc).__name__}." - ) - raise TypeError( - f"Each item in documents should be an instance of Document, but got {type(doc).__name__}." - ) + log.error(f"Each item in documents should be an instance of Document, but got {type(doc).__name__}.") + raise TypeError(f"Each item in documents should be an instance of Document, but got {type(doc).__name__}.") if doc.text is None: log.error(f"Text should not be None. Doc id: {doc.id}") @@ -693,25 +662,22 @@

Source code for components.data_process.text_splitter

text_splits = self.split_text(doc.text) meta_data = deepcopy(doc.meta_data) - split_docs.extend( - [ - Document( - text=txt, - meta_data=meta_data, - parent_doc_id=f"{doc.id}", - order=i, - vector=[], - ) - for i, txt in enumerate(text_splits) - ] - ) - log.info( - f"Processed {len(documents)} documents into {len(split_docs)} split documents." - ) + split_docs.extend([ + Document( + text=txt, + meta_data=meta_data, + parent_doc_id=f"{doc.id}", + order=i, + vector=[], + ) + for i, txt in enumerate(text_splits) + ]) + log.info(f"Processed {len(documents)} documents into {len(split_docs)} split documents.") return split_docs
- - def _split_text_into_units(self, text: str, separator: str) -> List[str]: + + def _split_text_into_units( + self, text: str, separator: str) -> List[str]: """Split text based on the specified separator.""" if self.split_by == "token": splits = tokenizer.encode(text) @@ -719,7 +685,7 @@

Source code for components.data_process.text_splitter

splits = text.split(separator) log.info(f"Text split by '{separator}' into {len(splits)} parts.") return splits - + def _merge_units_to_chunks( self, splits: List[str], chunk_size: int, chunk_overlap: int, separator: str ) -> List[str]: @@ -727,47 +693,45 @@

Source code for components.data_process.text_splitter

Merge split text chunks based on the specified chunk size and overlap. """ chunks = [] - # we use a window to get the text for each trunk, the window size is chunk_size, step is chunk_size - chunk_overlap + # we use a window to get the text for each trunk, the window size is chunk_size, step is chunk_size - chunk_overlap step = chunk_size - chunk_overlap idx = 0 - + for idx in range(0, len(splits), step): # 1. if the window exceeds the list of splitted string, break and process the last chunk # 2. if the window ends exactly the same with the splits, then break and treat the splits[idx:len(splits)] as the last chunk - if idx + chunk_size >= len(splits): + if idx+chunk_size >= len(splits): break - current_splits = splits[idx : idx + chunk_size] + current_splits = splits[idx:idx+chunk_size] # add the separator between each unit and merge the string # this won't be the last chunk, so we need to add the separator at the end if self.split_by == "token": - chunk = current_splits # if token, then keep the original form + chunk = current_splits # if token, then keep the original form else: chunk = separator.join(current_splits) + separator chunks.append(chunk) - + if idx < len(splits): if self.split_by == "token": last_chunk = splits[idx:] # if token, then keep the original form else: - last_chunk = separator.join( - splits[idx:] - ) # if not token, then join into string + last_chunk = separator.join(splits[idx:]) # if not token, then join into string if len(last_chunk) > 0: chunks.append(last_chunk) - - if self.split_by == "token": + + if self.split_by=="token": # decode each chunk here chunks = [tokenizer.decode(chunk) for chunk in chunks] - + log.info(f"Merged into {len(chunks)} chunks.") return chunks - + def _extra_repr(self) -> str: s = f"split_by={self.split_by}, chunk_size={self.chunk_size}, chunk_overlap={self.chunk_overlap}" return s
- - + + # test the execution llamaindex and langchain
diff --git a/_modules/components/memory/memory.html b/_modules/components/memory/memory.html index 52e4917c6..e1d3b4043 100644 --- a/_modules/components/memory/memory.html +++ b/_modules/components/memory/memory.html @@ -29,7 +29,7 @@ - + diff --git a/_modules/components/model_client/anthropic_client.html b/_modules/components/model_client/anthropic_client.html deleted file mode 100644 index f0b2dcb14..000000000 --- a/_modules/components/model_client/anthropic_client.html +++ /dev/null @@ -1,617 +0,0 @@ - - - - - - - - - - components.model_client.anthropic_client — LightRAG documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
-
-
-
-
- -
- -
- - - - - -
-
- - - - - -
- - - - - - - - - - - -
- -
- - -
-
- -
-
- -
- -
- - - - -
- -
- - -
-
- - - - - -
- -

Source code for components.model_client.anthropic_client

-"""Anthropic ModelClient integration."""
-
-import os
-from typing import Dict, Optional, Any
-
-
-import anthropic
-from anthropic import (
-    RateLimitError,
-    APITimeoutError,
-    InternalServerError,
-    UnprocessableEntityError,
-    BadRequestError,
-)
-from anthropic.types import Message
-
-
-import backoff
-
-
-from lightrag.core.model_client import ModelClient
-from lightrag.core.types import ModelType
-
-from lightrag.utils.lazy_import import safe_import, OptionalPackages
-
-safe_import(OptionalPackages.ANTHROPIC.value[0], OptionalPackages.ANTHROPIC.value[1])
-
-
-
-[docs] -class AnthropicAPIClient(ModelClient): - __doc__ = r"""A component wrapper for the Anthropic API client. - - Visit https://docs.anthropic.com/en/docs/intro-to-claude for more api details. - """ - - def __init__(self, api_key: Optional[str] = None): - r"""It is recommended to set the ANTHROPIC_API_KEY environment variable instead of passing it as an argument.""" - super().__init__() - self._api_key = api_key - self.sync_client = self.init_sync_client() - self.async_client = None # only initialize if the async call is called - self.tested_llm_models = ["claude-3-opus-20240229"] - -
-[docs] - def init_sync_client(self): - api_key = self._api_key or os.getenv("ANTHROPIC_API_KEY") - if not api_key: - raise ValueError("Environment variable ANTHROPIC_API_KEY must be set") - return anthropic.Anthropic(api_key=api_key)
- - -
-[docs] - def init_async_client(self): - api_key = self._api_key or os.getenv("ANTHROPIC_API_KEY") - if not api_key: - raise ValueError("Environment variable ANTHROPIC_API_KEY must be set") - return anthropic.AsyncAnthropic(api_key=api_key)
- - -
-[docs] - def parse_chat_completion(self, completion: Message) -> str: - print(f"completion: {completion}") - return completion.content[0].text
- - -
-[docs] - def convert_inputs_to_api_kwargs( - self, - input: Optional[Any] = None, - model_kwargs: Dict = {}, - model_type: ModelType = ModelType.UNDEFINED, - ) -> dict: - api_kwargs = model_kwargs.copy() - if model_type == ModelType.LLM: - api_kwargs["messages"] = [ - {"role": "user", "content": input}, - ] - if input and input != "": - api_kwargs["system"] = input - else: - raise ValueError(f"Model type {model_type} not supported") - return api_kwargs
- - -
-[docs] - @backoff.on_exception( - backoff.expo, - ( - APITimeoutError, - InternalServerError, - RateLimitError, - UnprocessableEntityError, - BadRequestError, - ), - max_time=5, - ) - def call(self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED): - """ - kwargs is the combined input and model_kwargs - """ - if model_type == ModelType.EMBEDDER: - raise ValueError(f"Model type {model_type} not supported") - elif model_type == ModelType.LLM: - return self.sync_client.messages.create(**api_kwargs) - else: - raise ValueError(f"model_type {model_type} is not supported")
- - -
-[docs] - @backoff.on_exception( - backoff.expo, - ( - APITimeoutError, - InternalServerError, - RateLimitError, - UnprocessableEntityError, - BadRequestError, - ), - max_time=5, - ) - async def acall( - self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED - ): - """ - kwargs is the combined input and model_kwargs - """ - if self.async_client is None: - self.async_client = self.init_async_client() - if model_type == ModelType.EMBEDDER: - raise ValueError(f"Model type {model_type} not supported") - elif model_type == ModelType.LLM: - return await self.async_client.messages.create(**api_kwargs) - else: - raise ValueError(f"model_type {model_type} is not supported")
-
- -
- -
- - - - - -
- -
-
-
- -
- - - - -
-
- -
- -
-
-
- - - - - -
- - -
- - \ No newline at end of file diff --git a/_modules/components/model_client/cohere_client.html b/_modules/components/model_client/cohere_client.html deleted file mode 100644 index fdb1eb4c1..000000000 --- a/_modules/components/model_client/cohere_client.html +++ /dev/null @@ -1,617 +0,0 @@ - - - - - - - - - - components.model_client.cohere_client — LightRAG documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
-
-
-
-
- -
- -
- - - - - -
-
- - - - - -
- - - - - - - - - - - -
- -
- - -
-
- -
-
- -
- -
- - - - -
- -
- - -
-
- - - - - -
- -

Source code for components.model_client.cohere_client

-"""Cohere ModelClient integration."""
-
-import os
-from typing import Dict, Optional, Any
-import backoff
-from lightrag.utils.lazy_import import safe_import, OptionalPackages
-
-safe_import(OptionalPackages.COHERE.value[0], OptionalPackages.COHERE.value[1])
-import cohere
-from cohere import (
-    BadRequestError,
-    InternalServerError,
-)
-
-
-from lightrag.core.model_client import ModelClient
-from lightrag.core.types import ModelType
-
-
-
-[docs] -class CohereAPIClient(ModelClient): - __doc__ = r"""A component wrapper for the Cohere API. - - Visit https://docs.cohere.com/ for more api details. - - References: - - Cohere reranker: https://docs.cohere.com/reference/rerank - - Tested Cohere models: 6/16/2024 - - rerank-english-v3.0, rerank-multilingual-v3.0, rerank-english-v2.0, rerank-multilingual-v2.0 - """ - - def __init__(self, api_key: Optional[str] = None): - r"""It is recommended to set the GROQ_API_KEY environment variable instead of passing it as an argument. - - Args: - api_key (Optional[str], optional): Groq API key. Defaults to None. - """ - super().__init__() - self._api_key = api_key - self.init_sync_client() - - self.async_client = None # only initialize if the async call is called - -
-[docs] - def init_sync_client(self): - api_key = self._api_key or os.getenv("COHERE_API_KEY") - if not api_key: - raise ValueError("Environment variable COHERE_API_KEY must be set") - self.sync_client = cohere.Client(api_key=api_key)
- - -
-[docs] - def init_async_client(self): - api_key = self._api_key or os.getenv("COHERE_API_KEY") - if not api_key: - raise ValueError("Environment variable COHERE_API_KEY must be set") - self.async_client = cohere.AsyncClient(api_key=api_key)
- - -
-[docs] - def convert_inputs_to_api_kwargs( - self, - input: Optional[Any] = None, # for retriever, it is a list of string. - model_kwargs: Dict = {}, - model_type: ModelType = ModelType.UNDEFINED, - ) -> Dict: - r""" - For rerank model, expect model_kwargs to have the following keys: - model: str, - query: str, - documents: List[str], - top_n: int, - """ - final_model_kwargs = model_kwargs.copy() - if model_type == ModelType.RERANKER: - final_model_kwargs["query"] = input - assert "model" in final_model_kwargs, "model must be specified" - assert "documents" in final_model_kwargs, "documents must be specified" - assert "top_k" in final_model_kwargs, "top_k must be specified" - - # convert top_k to the api specific, which is top_n - final_model_kwargs["top_n"] = final_model_kwargs.pop("top_k") - return final_model_kwargs - else: - raise ValueError(f"model_type {model_type} is not supported")
- - -
-[docs] - @backoff.on_exception( - backoff.expo, - ( - BadRequestError, - InternalServerError, - ), - max_time=5, - ) - def call(self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED): - assert ( - "model" in api_kwargs - ), f"model must be specified in api_kwargs: {api_kwargs}" - if ( - model_type == ModelType.RERANKER - ): # query -> # scores for top_k documents, index for the top_k documents, return as tuple - - response = self.sync_client.rerank(**api_kwargs) - top_k_scores = [result.relevance_score for result in response.results] - top_k_indices = [result.index for result in response.results] - return top_k_indices, top_k_scores - else: - raise ValueError(f"model_type {model_type} is not supported")
- - -
-[docs] - @backoff.on_exception( - backoff.expo, - ( - BadRequestError, - InternalServerError, - ), - max_time=5, - ) - async def acall( - self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED - ): - if self.async_client is None: - self.init_async_client() - assert "model" in api_kwargs, "model must be specified" - if model_type == ModelType.RERANKER: - response = await self.async_client.rerank(**api_kwargs) - top_k_scores = [result.relevance_score for result in response.results] - top_k_indices = [result.index for result in response.results] - return top_k_indices, top_k_scores - else: - raise ValueError(f"model_type {model_type} is not supported")
-
- -
- -
- - - - - -
- -
-
-
- -
- - - - -
-
- -
- -
-
-
- - - - - -
- - -
- - \ No newline at end of file diff --git a/_modules/components/model_client/groq_client.html b/_modules/components/model_client/groq_client.html deleted file mode 100644 index fbe2132ec..000000000 --- a/_modules/components/model_client/groq_client.html +++ /dev/null @@ -1,618 +0,0 @@ - - - - - - - - - - components.model_client.groq_client — LightRAG documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
-
-
-
-
- -
- -
- - - - - -
-
- - - - - -
- - - - - - - - - - - -
- -
- - -
-
- -
-
- -
- -
- - - - -
- -
- - -
-
- - - - - -
- -

Source code for components.model_client.groq_client

-"""Groq ModelClient integration."""
-
-import os
-from typing import Dict, Sequence, Optional, Any
-import backoff
-
-
-from groq import Groq, AsyncGroq
-from groq import (
-    APITimeoutError,
-    InternalServerError,
-    RateLimitError,
-    UnprocessableEntityError,
-)
-
-
-from lightrag.core.model_client import ModelClient
-from lightrag.core.types import ModelType
-from lightrag.utils.lazy_import import safe_import, OptionalPackages
-
-safe_import(OptionalPackages.GROQ.value[0], OptionalPackages.GROQ.value[1])
-
-
-
-[docs] -class GroqAPIClient(ModelClient): - __doc__ = r"""A component wrapper for the Groq API client. - - Visit https://console.groq.com/docs/ for more api details. - Check https://console.groq.com/docs/models for the available models. - - Tested Groq models: 4/22/2024 - - llama3-8b-8192 - - llama3-70b-8192 - - mixtral-8x7b-32768 - - gemma-7b-it - """ - - def __init__(self, api_key: Optional[str] = None): - r"""It is recommended to set the GROQ_API_KEY environment variable instead of passing it as an argument. - - Args: - api_key (Optional[str], optional): Groq API key. Defaults to None. - """ - super().__init__() - self._api_key = api_key - self.init_sync_client() - - self.async_client = None # only initialize if the async call is called - -
-[docs] - def init_sync_client(self): - api_key = self._api_key or os.getenv("GROQ_API_KEY") - if not api_key: - raise ValueError("Environment variable GROQ_API_KEY must be set") - self.sync_client = Groq(api_key=api_key)
- - -
-[docs] - def init_async_client(self): - api_key = self._api_key or os.getenv("GROQ_API_KEY") - if not api_key: - raise ValueError("Environment variable GROQ_API_KEY must be set") - self.async_client = AsyncGroq(api_key=api_key)
- - -
-[docs] - def parse_chat_completion(self, completion: Any) -> str: - """ - Parse the completion to a string output. - """ - return completion.choices[0].message.content
- - -
-[docs] - def convert_inputs_to_api_kwargs( - self, - input: Optional[Any] = None, - model_kwargs: Dict = {}, - model_type: ModelType = ModelType.UNDEFINED, - ) -> Dict: - final_model_kwargs = model_kwargs.copy() - if model_type == ModelType.LLM: - messages: Sequence[Dict[str, str]] = [] - if input is not None and input != "": - messages.append({"role": "system", "content": input}) - final_model_kwargs["messages"] = messages - else: - raise ValueError(f"model_type {model_type} is not supported") - return final_model_kwargs
- - -
-[docs] - @backoff.on_exception( - backoff.expo, - ( - APITimeoutError, - InternalServerError, - RateLimitError, - UnprocessableEntityError, - ), - max_time=5, - ) - def call(self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED): - assert ( - "model" in api_kwargs - ), f"model must be specified in api_kwargs: {api_kwargs}" - if model_type == ModelType.LLM: - completion = self.sync_client.chat.completions.create(**api_kwargs) - return completion - else: - raise ValueError(f"model_type {model_type} is not supported")
- - -
-[docs] - @backoff.on_exception( - backoff.expo, - ( - APITimeoutError, - InternalServerError, - RateLimitError, - UnprocessableEntityError, - ), - max_time=5, - ) - async def acall( - self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED - ): - if self.async_client is None: - self.init_async_client() - assert "model" in api_kwargs, "model must be specified" - if model_type == ModelType.LLM: - completion = await self.async_client.chat.completions.create(**api_kwargs) - return completion - else: - raise ValueError(f"model_type {model_type} is not supported")
-
- -
- -
- - - - - -
- -
-
-
- -
- - - - -
-
- -
- -
-
-
- - - - - -
- - -
- - \ No newline at end of file diff --git a/_modules/components/model_client/openai_client.html b/_modules/components/model_client/openai_client.html deleted file mode 100644 index 976dc5a15..000000000 --- a/_modules/components/model_client/openai_client.html +++ /dev/null @@ -1,746 +0,0 @@ - - - - - - - - - - components.model_client.openai_client — LightRAG documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
-
-
-
-
- -
- -
- - - - - -
-
- - - - - -
- - - - - - - - - - - -
- -
- - -
-
- -
-
- -
- -
- - - - -
- -
- - -
-
- - - - - -
- -

Source code for components.model_client.openai_client

-"""OpenAI ModelClient integration."""
-
-import os
-from typing import Dict, Sequence, Optional, List, Any, TypeVar, Callable
-
-import logging
-
-from openai import OpenAI, AsyncOpenAI
-from openai import (
-    APITimeoutError,
-    InternalServerError,
-    RateLimitError,
-    UnprocessableEntityError,
-    BadRequestError,
-)
-
-from lightrag.utils.lazy_import import safe_import, OptionalPackages
-
-
-from lightrag.core.model_client import ModelClient
-from lightrag.core.types import ModelType, EmbedderOutput, TokenLogProb
-from lightrag.components.model_client.utils import parse_embedding_response
-
-
-safe_import(OptionalPackages.OPENAI.value[0], OptionalPackages.OPENAI.value[1])
-
-
-from openai.types import Completion, CreateEmbeddingResponse
-
-
-import backoff
-
-log = logging.getLogger(__name__)
-T = TypeVar("T")
-
-
-# completion parsing functions and you can combine them into one singple chat completion parser
-
-[docs] -def get_first_message_content(completion: Completion) -> str: - r"""When we only need the content of the first message. - It is the default parser for chat completion.""" - return completion.choices[0].message.content
- - - -
-[docs] -def get_all_messages_content(completion: Completion) -> List[str]: - r"""When the n > 1, get all the messages content.""" - return [c.message.content for c in completion.choices]
- - - -
-[docs] -def get_probabilities(completion: Completion) -> List[List[TokenLogProb]]: - r"""Get the probabilities of each token in the completion.""" - log_probs = [] - for c in completion.choices: - content = c.logprobs.content - print(content) - log_probs_for_choice = [] - for openai_token_logprob in content: - token = openai_token_logprob.token - logprob = openai_token_logprob.logprob - log_probs_for_choice.append(TokenLogProb(token=token, logprob=logprob)) - log_probs.append(log_probs_for_choice) - return log_probs
- - - -
-[docs] -class OpenAIClient(ModelClient): - __doc__ = r"""A component wrapper for the OpenAI API client. - - Support both embedding and chat completion API. - - Users (1) simplify use ``Embedder`` and ``Generator`` components by passing OpenAIClient() as the model_client. - (2) can use this as an example to create their own API client or extend this class(copying and modifing the code) in their own project. - - Note: - We suggest users not to use `response_format` to enforce output data type or `tools` and `tool_choice` in your model_kwargs when calling the API. - We do not know how OpenAI is doing the formating or what prompt they have added. - Instead - - use :ref:`OutputParser<components-output_parsers>` for response parsing and formating. - - Args: - api_key (Optional[str], optional): OpenAI API key. Defaults to None. - chat_completion_parser (Callable[[Completion], Any], optional): A function to parse the chat completion to a str. Defaults to None. - Default is `get_first_message_content`. - - References: - - Embeddings models: https://platform.openai.com/docs/guides/embeddings - - Chat models: https://platform.openai.com/docs/guides/text-generation - - OpenAI docs: https://platform.openai.com/docs/introduction - """ - - def __init__( - self, - api_key: Optional[str] = None, - chat_completion_parser: Callable[[Completion], Any] = None, - ): - r"""It is recommended to set the OPENAI_API_KEY environment variable instead of passing it as an argument. - - Args: - api_key (Optional[str], optional): OpenAI API key. Defaults to None. - """ - super().__init__() - self._api_key = api_key - self.sync_client = self.init_sync_client() - self.async_client = None # only initialize if the async call is called - self.chat_completion_parser = ( - chat_completion_parser or get_first_message_content - ) - -
-[docs] - def init_sync_client(self): - api_key = self._api_key or os.getenv("OPENAI_API_KEY") - if not api_key: - raise ValueError("Environment variable OPENAI_API_KEY must be set") - return OpenAI(api_key=api_key)
- - -
-[docs] - def init_async_client(self): - api_key = self._api_key or os.getenv("OPENAI_API_KEY") - if not api_key: - raise ValueError("Environment variable OPENAI_API_KEY must be set") - return AsyncOpenAI(api_key=api_key)
- - -
-[docs] - def parse_chat_completion(self, completion: Completion) -> Any: - """Parse the completion to a str.""" - log.debug(f"completion: {completion}") - return self.chat_completion_parser(completion)
- - # return completion.choices[0].message.content - -
-[docs] - def parse_embedding_response( - self, response: CreateEmbeddingResponse - ) -> EmbedderOutput: - r"""Parse the embedding response to a structure LightRAG components can understand. - - Should be called in ``Embedder``. - """ - try: - return parse_embedding_response(response) - except Exception as e: - log.error(f"Error parsing the embedding response: {e}") - return EmbedderOutput(data=[], error=str(e), raw_response=response)
- - -
-[docs] - def convert_inputs_to_api_kwargs( - self, - input: Optional[Any] = None, - model_kwargs: Dict = {}, - model_type: ModelType = ModelType.UNDEFINED, - ) -> Dict: - r""" - Specify the API input type and output api_kwargs that will be used in _call and _acall methods. - Convert the Component's standard input, and system_input(chat model) and model_kwargs into API-specific format - """ - final_model_kwargs = model_kwargs.copy() - if model_type == ModelType.EMBEDDER: - if isinstance(input, str): - input = [input] - # convert input to input - assert isinstance(input, Sequence), "input must be a sequence of text" - final_model_kwargs["input"] = input - elif model_type == ModelType.LLM: - # convert input to messages - messages: List[Dict[str, str]] = [] - if input is not None and input != "": - messages.append({"role": "system", "content": input}) - assert isinstance( - messages, Sequence - ), "input must be a sequence of messages" - final_model_kwargs["messages"] = messages - else: - raise ValueError(f"model_type {model_type} is not supported") - return final_model_kwargs
- - -
-[docs] - @backoff.on_exception( - backoff.expo, - ( - APITimeoutError, - InternalServerError, - RateLimitError, - UnprocessableEntityError, - BadRequestError, - ), - max_time=5, - ) - def call(self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED): - """ - kwargs is the combined input and model_kwargs - """ - log.info(f"api_kwargs: {api_kwargs}") - if model_type == ModelType.EMBEDDER: - return self.sync_client.embeddings.create(**api_kwargs) - elif model_type == ModelType.LLM: - return self.sync_client.chat.completions.create(**api_kwargs) - else: - raise ValueError(f"model_type {model_type} is not supported")
- - -
-[docs] - @backoff.on_exception( - backoff.expo, - ( - APITimeoutError, - InternalServerError, - RateLimitError, - UnprocessableEntityError, - BadRequestError, - ), - max_time=5, - ) - async def acall( - self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED - ): - """ - kwargs is the combined input and model_kwargs - """ - if self.async_client is None: - self.async_client = self.init_async_client() - if model_type == ModelType.EMBEDDER: - return await self.async_client.embeddings.create(**api_kwargs) - elif model_type == ModelType.LLM: - return await self.async_client.chat.completions.create(**api_kwargs) - else: - raise ValueError(f"model_type {model_type} is not supported")
- - -
-[docs] - @classmethod - def from_dict(cls: type[T], data: Dict[str, Any]) -> T: - obj = super().from_dict(data) - # recreate the existing clients - obj.sync_client = obj.init_sync_client() - obj.async_client = obj.init_async_client() - return obj
- - -
-[docs] - def to_dict(self) -> Dict[str, Any]: - r"""Convert the component to a dictionary.""" - # TODO: not exclude but save yes or no for recreating the clients - exclude = [ - "sync_client", - "async_client", - ] # unserializable object - output = super().to_dict(exclude=exclude) - return output
-
- -
- -
- - - - - -
- -
-
-
- -
- - - - -
-
- -
- -
-
-
- - - - - -
- - -
- - \ No newline at end of file diff --git a/_modules/components/model_client/transformers_client.html b/_modules/components/model_client/transformers_client.html index 04abf4967..aebd472b8 100644 --- a/_modules/components/model_client/transformers_client.html +++ b/_modules/components/model_client/transformers_client.html @@ -29,7 +29,7 @@ - + @@ -422,7 +422,7 @@

Source code for components.model_client.transformers_client

AutoTokenizer, AutoModel, AutoModelForSequenceClassification, - AutoModelForCausalLM, + AutoModelForCausalLM ) from lightrag.core.model_client import ModelClient @@ -653,7 +653,6 @@

Source code for components.model_client.transformers_client

raise ValueError(f"model {model_name} is not supported")
-
[docs] class TransformerLLM: @@ -664,7 +663,7 @@

Source code for components.model_client.transformers_client

if model_name is not None: self.init_model(model_name=model_name) - +
[docs] def init_model(self, model_name: str): @@ -673,85 +672,57 @@

Source code for components.model_client.transformers_client

self.model = AutoModelForCausalLM.from_pretrained(model_name) # register the model self.models[model_name] = self.model - self.device = "cuda" if torch.cuda.is_available() else "cpu" + self.device = 'cuda' if torch.cuda.is_available() else 'cpu' log.info(f"Done loading model {model_name}") # Set pad token if it's not already set if self.tokenizer.pad_token is None: self.tokenizer.pad_token = self.tokenizer.eos_token # common fallback - self.model.config.pad_token_id = ( - self.tokenizer.eos_token_id - ) # ensure consistency in the model config + self.model.config.pad_token_id = self.tokenizer.eos_token_id # ensure consistency in the model config except Exception as e: log.error(f"Error loading model {model_name}: {e}") raise e
- +
[docs] def parse_chat_completion(self, input_text: str, response: str): - parsed_response = response.replace( - input_text, "" - ).strip() # Safely handle cases where input_text might not be in response - + parsed_response = response.replace(input_text, "").strip() # Safely handle cases where input_text might not be in response + return parsed_response if parsed_response else response
- +
[docs] - def call( - self, - input_text: str, - skip_special_tokens: bool = True, - clean_up_tokenization_spaces: bool = False, - max_length: int = 150, - ): + def call(self, input_text: str, skip_special_tokens: bool = True, clean_up_tokenization_spaces: bool = False, max_length: int = 150): if not self.model: log.error("Model is not initialized.") raise ValueError("Model is not initialized.") - + # Ensure tokenizer has pad token; set it if not if self.tokenizer.pad_token is None: self.tokenizer.pad_token = self.tokenizer.eos_token - self.model.config.pad_token_id = ( - self.tokenizer.eos_token_id - ) # Sync model config pad token id + self.model.config.pad_token_id = self.tokenizer.eos_token_id # Sync model config pad token id # Process inputs with attention mask and padding - inputs = self.tokenizer(input_text, return_tensors="pt", padding=True).to( - self.device - ) + inputs = self.tokenizer(input_text, return_tensors="pt", padding=True).to(self.device) # inputs = self.tokenizer(input_text, return_tensors="pt", padding="longest", truncation=True).to(self.device) with torch.no_grad(): # Ensures no gradients are calculated to save memory and computations generate_ids = self.model.generate( - inputs["input_ids"], - attention_mask=inputs["attention_mask"], - max_length=max_length, # Control the output length more precisely - ) - response = self.tokenizer.decode( - generate_ids[0], - skip_special_tokens=skip_special_tokens, - clean_up_tokenization_spaces=clean_up_tokenization_spaces, + inputs['input_ids'], + attention_mask=inputs['attention_mask'], + max_length=max_length # Control the output length more precisely ) + response = self.tokenizer.decode(generate_ids[0], skip_special_tokens=skip_special_tokens, clean_up_tokenization_spaces=clean_up_tokenization_spaces) parsed_response = self.parse_chat_completion(input_text, response) return parsed_response
- def __call__( - self, - input_text: str, - skip_special_tokens: bool = True, - clean_up_tokenization_spaces: bool = False, - max_length: int = 150, - ): - return self.call( - input_text, - skip_special_tokens=skip_special_tokens, - clean_up_tokenization_spaces=clean_up_tokenization_spaces, - max_length=max_length, - )
- + def __call__(self, input_text: str, skip_special_tokens: bool = True, clean_up_tokenization_spaces: bool = False, max_length: int = 150): + return self.call(input_text, skip_special_tokens=skip_special_tokens, clean_up_tokenization_spaces=clean_up_tokenization_spaces, max_length=max_length)
+ + # def call(self, input_text: str, skip_special_tokens: bool = True, clean_up_tokenization_spaces: bool = False): # if not self.model: # log.error("Model is not initialized.") @@ -764,8 +735,8 @@

Source code for components.model_client.transformers_client

# def __call__(self, input_text: str, skip_special_tokens: bool = True, clean_up_tokenization_spaces: bool = False): # return self.call(input_text, skip_special_tokens=skip_special_tokens, clean_up_tokenization_spaces=clean_up_tokenization_spaces) - - + +
[docs] class TransformersClient(ModelClient): @@ -781,7 +752,9 @@

Source code for components.model_client.transformers_client

"BAAI/bge-reranker-base": { "type": ModelType.RERANKER, }, - "HuggingFaceH4/zephyr-7b-beta": {"type": ModelType.LLM}, + "HuggingFaceH4/zephyr-7b-beta": { + "type": ModelType.LLM + } } def __init__(self, model_name: Optional[str] = None) -> None: @@ -810,7 +783,7 @@

Source code for components.model_client.transformers_client

def init_reranker_client(self): return TransformerReranker()
- +
[docs] def init_llm_client(self): @@ -854,7 +827,7 @@

Source code for components.model_client.transformers_client

scores, api_kwargs["top_k"] ) return top_k_indices, top_k_scores - elif ( # LLM + elif ( # LLM model_type == ModelType.LLM and "model" in api_kwargs and api_kwargs["model"] == "HuggingFaceH4/zephyr-7b-beta" diff --git a/_modules/components/model_client/utils.html b/_modules/components/model_client/utils.html index 081ba2985..bdfbbe7f4 100644 --- a/_modules/components/model_client/utils.html +++ b/_modules/components/model_client/utils.html @@ -29,7 +29,7 @@ - + diff --git a/_modules/components/output_parsers/outputs.html b/_modules/components/output_parsers/outputs.html index aa910d2c6..ba1ef1339 100644 --- a/_modules/components/output_parsers/outputs.html +++ b/_modules/components/output_parsers/outputs.html @@ -29,7 +29,7 @@ - + diff --git a/apis/components/_autosummary/components.api_client.openai_client.html b/_modules/components/reasoning/chain_of_thought.html similarity index 55% rename from apis/components/_autosummary/components.api_client.openai_client.html rename to _modules/components/reasoning/chain_of_thought.html index 4e70c2518..b085d1dca 100644 --- a/apis/components/_autosummary/components.api_client.openai_client.html +++ b/_modules/components/reasoning/chain_of_thought.html @@ -6,9 +6,8 @@ - - - components.api_client.openai_client — LightRAG documentation + + components.reasoning.chain_of_thought — LightRAG documentation @@ -30,7 +29,7 @@ - + @@ -48,7 +47,7 @@ - + @@ -169,7 +168,7 @@ @@ -252,10 +251,6 @@ - -
@@ -305,7 +300,7 @@ @@ -391,7 +386,10 @@ - + + + +
@@ -408,10 +406,112 @@
-
-

components.api_client.openai_client#

-
- +

Source code for components.reasoning.chain_of_thought

+"""
+https://arxiv.org/abs/2201.11903, published in Jan, 2023
+
+Chain of the thought(CoT) is to mimic a step-by-step thought process for arriving at the answer. You can achieve it in two ways:
+1. Add instructions such as "Let's think step-by-step to answer this question".
+2. Add few-shot examples such as
+'
+Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now?
+A: Roger started with 5 balls. 2 cansof 3 tennis balls each is 6 tennis balls. 5 + 6 = 11. The answer is 11.
+'
+
+NOTE: CoT can be helpful for more complicated task, it also varies from task to task and model to model.
+For instance, CoT might already be supported in gpt3.5+ api calls.
+
+Benchmark it with and without CoT to see if it helps.
+"""
+
+from typing import Dict, Optional
+
+from core.component import Component
+from core.generator import Generator
+from core.string_parser import JsonParser
+from core.model_client import ModelClient
+from core.default_prompt_template import DEFAULT_LIGHTRAG_SYSTEM_PROMPT
+
+
+COT_TASK_DESC_STR_BASIC = (
+    "You are a helpful assistant. Let's think step-by-step to answer user's query."
+)
+# Using triple quotes to include JSON-like structure more cleanly
+COT_TASK_DESC_STR_WITH_JSON_OUTPUT = f"""
+{COT_TASK_DESC_STR_BASIC} Output JSON format: {{"thought": "<The thought process to answer the query>", "answer": "<The answer to the query>"}}
+"""
+
+
+# ChainOfThought will just be a generator with preset_prompt_kwargs of the task_desc_str = COT_TASK_DESC_STR
+# additional you can ask it to generate a json with "thought" and "anwer" keys and use jsonParser
+
+
+
+[docs] +class CoTGenerator(Generator): + r""" + CoTGenerator is a subclass of Generator with default task_desc_str preset for Chain of Thought. + Output will be string. + It is exactly the same as using a Generator. + Example: + ``` + cot = CoTGenerator(model_client=model_client, model_kwargs={"model": model}) + ``` + """ + + def __init__( + self, + *, + model_client: ModelClient, + model_kwargs: Dict = {}, + template: Optional[str] = None, + preset_prompt_kwargs: Optional[Dict] = None, + output_processors: Optional[Component] = None, + ) -> None: + + super().__init__( + model_client=model_client, + model_kwargs=model_kwargs, + template=template or DEFAULT_LIGHTRAG_SYSTEM_PROMPT, + preset_prompt_kwargs=preset_prompt_kwargs + or {"task_desc_str": COT_TASK_DESC_STR_BASIC}, + output_processors=output_processors, + )
+ + + +
+[docs] +class CoTGeneratorWithJsonOutput(Generator): + r""" + CoTGeneratorWithJsonOutput is a subclass of Generator with default task_desc_str preset for Chain of Thought. + Output will be parsed as JSON with "thought" and "answer" keys. + Example: + ``` + cot = CoTGeneratorWithJsonOutput(model_client=model_client, model_kwargs={"model": model}) + ``` + """ + + def __init__( + self, + *, + model_client: ModelClient, + model_kwargs: Dict = {}, + template: Optional[str] = None, + preset_prompt_kwargs: Optional[Dict] = None, + output_processors: Optional[Component] = None, + ) -> None: + + super().__init__( + model_client=model_client, + model_kwargs=model_kwargs, + template=template or DEFAULT_LIGHTRAG_SYSTEM_PROMPT, + preset_prompt_kwargs=preset_prompt_kwargs + or {"task_desc_str": COT_TASK_DESC_STR_WITH_JSON_OUTPUT}, + output_processors=output_processors or JsonParser(), + )
+ +
@@ -429,20 +529,6 @@ -
-