class NLSQLTableQueryEngine(BaseSQLTableQueryEngine):
"""自然语言SQL表查询引擎。
阅读NLStructStoreQueryEngine的文档字符串,了解有关NL SQL的更多信息。
注意:任何文本到SQL的应用程序都应该意识到执行任意SQL查询可能存在安全风险。建议采取必要的预防措施,如使用受限角色、只读数据库、沙盒等。"""
def __init__(
self,
sql_database: SQLDatabase,
llm: Optional[LLM] = None,
text_to_sql_prompt: Optional[BasePromptTemplate] = None,
context_query_kwargs: Optional[dict] = None,
synthesize_response: bool = True,
response_synthesis_prompt: Optional[BasePromptTemplate] = None,
refine_synthesis_prompt: Optional[BasePromptTemplate] = None,
tables: Optional[Union[List[str], List[Table]]] = None,
service_context: Optional[ServiceContext] = None,
context_str_prefix: Optional[str] = None,
sql_only: bool = False,
callback_manager: Optional[CallbackManager] = None,
verbose: bool = False,
**kwargs: Any,
) -> None:
"""初始化参数。"""
# self._tables = tables
self._sql_retriever = NLSQLRetriever(
sql_database,
llm=llm,
text_to_sql_prompt=text_to_sql_prompt,
context_query_kwargs=context_query_kwargs,
tables=tables,
context_str_prefix=context_str_prefix,
service_context=service_context,
sql_only=sql_only,
callback_manager=callback_manager,
verbose=verbose,
)
super().__init__(
synthesize_response=synthesize_response,
response_synthesis_prompt=response_synthesis_prompt,
refine_synthesis_prompt=refine_synthesis_prompt,
llm=llm,
service_context=service_context,
callback_manager=callback_manager,
verbose=verbose,
**kwargs,
)
@property
def sql_retriever(self) -> NLSQLRetriever:
"""获取SQL检索器。"""
return self._sql_retriever