跳至主要内容

PromptLayer OpenAI

危险

此模块已弃用,不再受支持。以下文档在 0.2.0 及更高版本中将不起作用。

LangChain 与 PromptLayer 集成,用于记录和调试提示和响应。若要添加对 PromptLayer 的支持

  1. 在此处创建 PromptLayer 帐户:https://promptlayer.com
  2. 创建 API 令牌,并将其作为 promptLayerApiKey 参数传递给 PromptLayerOpenAI 构造函数,或传递给 PROMPTLAYER_API_KEY 环境变量。
import { PromptLayerOpenAI } from "langchain/llms/openai";

const model = new PromptLayerOpenAI({
temperature: 0.9,
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.OPENAI_API_KEY
promptLayerApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.PROMPTLAYER_API_KEY
});
const res = await model.invoke(
"What would be a good company name a company that makes colorful socks?"
);

Azure PromptLayerOpenAI

LangChain 还与 PromptLayer 集成,适用于 Azure 托管的 OpenAI 实例

import { PromptLayerOpenAI } from "langchain/llms/openai";

const model = new PromptLayerOpenAI({
temperature: 0.9,
azureOpenAIApiKey: "YOUR-AOAI-API-KEY", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY
azureOpenAIApiInstanceName: "YOUR-AOAI-INSTANCE-NAME", // In Node.js defaults to process.env.AZURE_OPENAI_API_INSTANCE_NAME
azureOpenAIApiDeploymentName: "YOUR-AOAI-DEPLOYMENT-NAME", // In Node.js defaults to process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME
azureOpenAIApiCompletionsDeploymentName:
"YOUR-AOAI-COMPLETIONS-DEPLOYMENT-NAME", // In Node.js defaults to process.env.AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME
azureOpenAIApiEmbeddingsDeploymentName:
"YOUR-AOAI-EMBEDDINGS-DEPLOYMENT-NAME", // In Node.js defaults to process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME
azureOpenAIApiVersion: "YOUR-AOAI-API-VERSION", // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION
azureOpenAIBasePath: "YOUR-AZURE-OPENAI-BASE-PATH", // In Node.js defaults to process.env.AZURE_OPENAI_BASE_PATH
promptLayerApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.PROMPTLAYER_API_KEY
});
const res = await model.invoke(
"What would be a good company name a company that makes colorful socks?"
);

请求和响应将在 PromptLayer 仪表板 中记录。

注意:在流式模式下,PromptLayer 不会记录响应。


此页面是否有用?


您也可以在 GitHub 上留下详细的反馈 GitHub.