Pandas
PandasQueryEngine #
基类:EventBaseQueryEngine
Pandas 查询引擎。
将自然语言转换为Pandas Python代码。
警告:此工具允许智能体访问 eval 函数。
在运行此工具的机器上可能执行任意代码。
不建议在生产环境中使用此工具,且需要严格沙箱或虚拟机隔离
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
df
|
DataFrame
|
要使用的Pandas数据框。 |
required |
instruction_str
|
Optional[str]
|
要使用的指令字符串。 |
None
|
instruction_parser
|
Optional[PandasInstructionParser]
|
输出解析器 用于接收pandas查询输出字符串并返回字符串。 默认使用PandasInstructionParser,接收pandas DataFrame 以及任意输出kwargs作为参数。 例如kwargs["max_colwidth"] = [int] 用于设置文本长度 该长度决定了在str(df)过程中每列可显示的文本量。若数据框中可能存在长文本 请将其设置为更大的数值。 |
None
|
pandas_prompt
|
Optional[BasePromptTemplate]
|
要使用的Pandas提示。 |
None
|
output_kwargs
|
dict
|
PandasInstructionParser 的额外输出处理器关键字参数。 |
None
|
head
|
int
|
表格上下文中显示的行数。 |
5
|
verbose
|
bool
|
是否打印详细输出。 |
False
|
llm
|
Optional[大语言模型]
|
使用的语言模型。 |
None
|
synthesize_response
|
bool
|
是否根据查询结果合成响应。默认为 False。 |
False
|
response_synthesis_prompt
|
Optional[BasePromptTemplate]
|
用于查询的响应合成基础提示模板。默认为 DEFAULT_RESPONSE_SYNTHESIS_PROMPT。 |
None
|
示例:
pip install llama-index-experimental
import pandas as pd
from llama_index.experimental.query_engine.pandas import PandasQueryEngine
df = pd.DataFrame(
{
"city": ["Toronto", "Tokyo", "Berlin"],
"population": [2930000, 13960000, 3645000]
}
)
query_engine = PandasQueryEngine(df=df, verbose=True)
response = query_engine.query("What is the population of Tokyo?")
workflows/handler.py 中的源代码llama_index/experimental/query_engine/pandas/pandas_query_engine.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
Pandas指令解析器 #
基类:EventBaseOutputParser
Pandas 指令解析器。
此“输出解析器”接收 pandas 指令(以 Python 代码形式)并执行它们以返回输出。
workflows/handler.py 中的源代码llama_index/experimental/query_engine/pandas/output_parser.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
parse #
parse(output: str) -> Any
以编程方式解析、验证并纠正错误。
workflows/handler.py 中的源代码llama_index/experimental/query_engine/pandas/output_parser.py
94 95 96 | |
Polars查询引擎 #
基类:EventBaseQueryEngine
Polars 查询引擎。
将自然语言转换为Polars Python代码。
警告:此工具允许智能体访问 eval 函数。
在运行此工具的机器上可能执行任意代码。
不建议在生产环境中使用此工具,且需要严格沙箱或虚拟机隔离
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
df
|
DataFrame
|
要使用的 Polars 数据框。 |
required |
instruction_str
|
Optional[str]
|
要使用的指令字符串。 |
None
|
instruction_parser
|
Optional[PolarsInstructionParser]
|
输出解析器 接收 polars 查询输出字符串并返回字符串。 默认使用 PolarsInstructionParser,接收 polars DataFrame 以及任意输出 kwargs 作为参数。 |
None
|
polars_prompt
|
Optional[BasePromptTemplate]
|
要使用的Polars提示。 |
None
|
output_kwargs
|
dict
|
PolarsInstructionParser 的额外输出处理器参数。 |
None
|
head
|
int
|
表格上下文中显示的行数。 |
5
|
verbose
|
bool
|
是否打印详细输出。 |
False
|
llm
|
Optional[大语言模型]
|
使用的语言模型。 |
None
|
synthesize_response
|
bool
|
是否根据查询结果合成响应。默认为 False。 |
False
|
response_synthesis_prompt
|
Optional[BasePromptTemplate]
|
用于查询的响应合成基础提示模板。默认为 DEFAULT_RESPONSE_SYNTHESIS_PROMPT。 |
None
|
示例:
pip install llama-index-experimental polars
import polars as pl
from llama_index.experimental.query_engine.polars import PolarsQueryEngine
df = pl.DataFrame(
{
"city": ["Toronto", "Tokyo", "Berlin"],
"population": [2930000, 13960000, 3645000]
}
)
query_engine = PolarsQueryEngine(df=df, verbose=True)
response = query_engine.query("What is the population of Tokyo?")
workflows/handler.py 中的源代码llama_index/experimental/query_engine/polars/polars_query_engine.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
Polars指令解析器 #
基类:EventBaseOutputParser
Polars 指令解析器。
此'输出解析器'接收polars指令(以Python代码形式)并执行它们以返回输出。
workflows/handler.py 中的源代码llama_index/experimental/query_engine/polars/output_parser.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
parse #
parse(output: str) -> Any
以编程方式解析、验证并纠正错误。
workflows/handler.py 中的源代码llama_index/experimental/query_engine/polars/output_parser.py
104 105 106 | |
JSONalyzeQueryEngine #
基类:EventBaseQueryEngine
JSON列表结构数据分析查询引擎。
将自然语言统计查询转换为内存中SQLite查询的SQL语句。
list_of_dict(List[Dict[str, Any]]): 用于查询的字典列表。 jsonalyze_prompt (BasePromptTemplate): 要使用的JSONalyze提示模板。 use_async (bool): 是否使用异步模式。 analyzer (Callable): 执行查询的分析器。 sql_parser (BaseSQLParser): 确保从大语言模型输出中解析出有效SQL的SQL解析器。 synthesize_response (bool): 是否合成响应。 response_synthesis_prompt (BasePromptTemplate): 要使用的响应合成提示模板。 table_name (str): 要使用的表名。 verbose (bool): 是否打印详细输出。
workflows/handler.py 中的源代码llama_index/experimental/query_engine/jsonalyze/jsonalyze_query_engine.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
选项: 成员:- PandasQueryEngine