模块
LLMS
Pipelineai Example

PipelineAI允许您在云中规模运行您的ML模型。它还提供API访问多个LLM模型 (opens in a new tab)

这个笔记本介绍了如何使用PipelineAI (opens in a new tab)来使用Langchain。

安装pipeline-ai#

使用pip install pipeline-ai安装pipeline-ai库是使用PipelineAI API,也称为Pipeline Cloud所必需的。

# Install the package
!pip install pipeline-ai

导入#

import os
from langchain.llms import PipelineAI
from langchain import PromptTemplate, LLMChain

设置环境API密钥#

Make sure to get your API key from PipelineAI. Check out the cloud quickstart guide (opens in a new tab). You’ll be given a 30 day free trial with 10 hours of serverless GPU compute to test different models.

os.environ["PIPELINE_API_KEY"] = "YOUR_API_KEY_HERE"

Create the PipelineAI instance#

When instantiating PipelineAI, you need to specify the id or tag of the pipeline you want to use, e.g. pipeline_key = "public/gpt-j:base". You then have the option of passing additional pipeline-specific keyword arguments:

llm = PipelineAI(pipeline_key="YOUR_PIPELINE_KEY", pipeline_kwargs={...})

Create a Prompt Template#

We will create a prompt template for Question and Answer.

template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

Initiate the LLMChain#

llm_chain = LLMChain(prompt=prompt, llm=llm)

Run the LLMChain#

提供一个问题并运行LLMChain。

question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

llm_chain.run(question)