基类:EventBaseLlamaPack
Arize-Phoenix LlamaPack 展示了如何通过追踪功能为您的 LlamaIndex 查询引擎添加监控。它会在后台启动 Phoenix,基于输入的节点列表构建索引,并在该索引上实例化并监控一个查询引擎,以便将每次查询的追踪数据发送至 Phoenix。
注意:使用此LlamaPack需要您通过OPENAI_API_KEY环境变量设置OpenAI API密钥。
workflows/handler.py 中的源代码llama_index/packs/arize_phoenix_query_engine/base.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 | class ArizePhoenixQueryEnginePack(BaseLlamaPack):
"""
The Arize-Phoenix LlamaPack show how to instrument your LlamaIndex query
engine with tracing. It launches Phoenix in the background, builds an index
over an input list of nodes, and instantiates and instruments a query engine
over that index so that trace data from each query is sent to Phoenix.
Note: Using this LlamaPack requires that your OpenAI API key is set via the
OPENAI_API_KEY environment variable.
"""
def __init__(
self,
nodes: List[TextNode],
**kwargs: Any,
) -> None:
"""
Initializes a new instance of ArizePhoenixQueryEnginePack.
Args:
nodes (List[TextNode]): An input list of nodes over which the index
will be built.
"""
try:
import phoenix as px
except ImportError:
raise ImportError(
"The arize-phoenix package could not be found. "
"Please install with `pip install arize-phoenix`."
)
self._session: "PhoenixSession" = px.launch_app()
set_global_handler("arize_phoenix")
self._index = VectorStoreIndex(nodes, **kwargs)
self._query_engine = self._index.as_query_engine()
def get_modules(self) -> Dict[str, Any]:
"""
Returns a dictionary containing the internals of the LlamaPack.
Returns:
Dict[str, Any]: A dictionary containing the internals of the
LlamaPack.
"""
return {
"session": self._session,
"session_url": self._session.url,
"index": self._index,
"query_engine": self._query_engine,
}
def run(self, *args: Any, **kwargs: Any) -> Any:
"""
Runs queries against the index.
Returns:
Any: A response from the query engine.
"""
return self._query_engine.query(*args, **kwargs)
|
get_modules
get_modules() -> Dict[str, Any]
返回一个包含 LlamaPack 内部结构的字典。
返回:
| 类型 |
描述 |
Dict[str, Any]
|
Dict[str, Any]: 一个包含内部结构的字典
|
Dict[str, Any]
|
|
workflows/handler.py 中的源代码llama_index/packs/arize_phoenix_query_engine/base.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 | def get_modules(self) -> Dict[str, Any]:
"""
Returns a dictionary containing the internals of the LlamaPack.
Returns:
Dict[str, Any]: A dictionary containing the internals of the
LlamaPack.
"""
return {
"session": self._session,
"session_url": self._session.url,
"index": self._index,
"query_engine": self._query_engine,
}
|
run
run(*args: Any, **kwargs: Any) -> Any
对索引运行查询。
返回:
workflows/handler.py 中的源代码llama_index/packs/arize_phoenix_query_engine/base.py
68
69
70
71
72
73
74
75
76 | def run(self, *args: Any, **kwargs: Any) -> Any:
"""
Runs queries against the index.
Returns:
Any: A response from the query engine.
"""
return self._query_engine.query(*args, **kwargs)
|