PipelineAI
PipelineAI allows you to run your ML models at scale in the cloud. It also provides API access to several LLM models.
This notebook goes over how to use Langchain with PipelineAI.
PipelineAI exampleโ
This example shows how PipelineAI integrated with LangChain and it is created by PipelineAI.
Setupโ
The pipeline-ai
library is required to use the PipelineAI
API, AKA Pipeline Cloud
. Install pipeline-ai
using pip install pipeline-ai
.
# Install the package
%pip install --upgrade --quiet pipeline-ai
Exampleโ
Importsโ
import os
from langchain_community.llms import PipelineAI
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import PromptTemplate
Set the Environment API Keyโ
Make sure to get your API key from PipelineAI. Check out the cloud quickstart guide. 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.from_template(template)
Initiate the LLMChainโ
llm_chain = prompt | llm | StrOutputParser()
Run the LLMChainโ
Provide a question and run the LLMChain.
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.invoke(question)
Relatedโ
- LLM conceptual guide
- LLM how-to guides