PromptLayer OpenAI
危险
此模块已弃用,不再支持。以下文档在 v0.2.0 或更高版本中将不起作用。
LangChain 与 PromptLayer 集成以记录和调试提示和响应。要添加对 PromptLayer 的支持
- 在此处创建一个 PromptLayer 帐户:https://promptlayer.com。
- 创建 API 令牌,并将其作为
PromptLayerOpenAI
构造函数中的promptLayerApiKey
参数或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 不会记录响应。