PromptLayer is a platform for prompt engineering. It also helps with the LLM observability to visualize requests, version prompts, and track usage. While在本指南中,我们将介绍如何设置PromptLayerdoes have LLMs that integrate directly with LangChain (e.g.PromptLayerOpenAI), using a callback is the recommended way to integratePromptLayerwith LangChain.
PromptLayerCallbackHandler。
更多信息请参阅 PromptLayer 文档。
安装与设置
获取 API 凭证
如果您还没有 PromptLayer 帐号,请在 promptlayer.com 创建一个。然后点击导航栏中的设置齿轮获取 API 密钥,并将其设置为名为PROMPTLAYER_API_KEY 的环境变量。
用法
开始使用PromptLayerCallbackHandler 相当简单,它接受两个可选参数:
pl_tags- 可选字符串列表,将在 PromptLayer 中作为标签跟踪。pl_id_callback- 可选函数,接收promptlayer_request_id作为参数。该 ID 可用于 PromptLayer 的所有跟踪功能,用于跟踪元数据、得分和提示使用情况。
简单的 OpenAI 示例
在这个简单示例中,我们将PromptLayerCallbackHandler 与 ChatOpenAI 一起使用,并添加名为 chatopenai 的 PromptLayer 标签:
GPT4All 示例
完整示例
在此示例中,我们释放PromptLayer 更强大的功能。
PromptLayer 允许您以可视化方式创建、版本化和跟踪提示模板。使用 Prompt Registry,我们可以以编程方式获取名为 example 的提示模板。
我们还定义了一个 pl_id_callback 函数,它接收 promptlayer_request_id,记录得分、元数据并关联所使用的提示模板。有关跟踪的更多信息,请参阅我们的文档。