2023-04-27 15:22:26 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PipelineAI\n",
"\n",
2023-09-01 22:30:37 +00:00
">[PipelineAI](https://pipeline.ai) allows you to run your ML models at scale in the cloud. It also provides API access to [several LLM models](https://pipeline.ai).\n",
2023-04-27 15:22:26 +00:00
"\n",
2023-09-01 22:30:37 +00:00
"This notebook goes over how to use Langchain with [PipelineAI](https://docs.pipeline.ai/docs).\n",
"\n",
"## PipelineAI example\n",
"\n",
"[This example shows how PipelineAI integrated with LangChain](https://docs.pipeline.ai/docs/langchain) and it is created by PipelineAI."
2023-04-27 15:22:26 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-09-01 22:30:37 +00:00
"## Setup\n",
2023-04-27 15:22:26 +00:00
"The `pipeline-ai` library is required to use the `PipelineAI` API, AKA `Pipeline Cloud`. Install `pipeline-ai` using `pip install pipeline-ai`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Install the package\n",
"!pip install pipeline-ai"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-09-01 22:30:37 +00:00
"## Example\n",
"\n",
"### Imports"
2023-04-27 15:22:26 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from langchain.llms import PipelineAI\n",
"from langchain import PromptTemplate, LLMChain"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-09-01 22:30:37 +00:00
"### Set the Environment API Key\n",
2023-04-27 15:22:26 +00:00
"Make sure to get your API key from PipelineAI. Check out the [cloud quickstart guide](https://docs.pipeline.ai/docs/cloud-quickstart). You'll be given a 30 day free trial with 10 hours of serverless GPU compute to test different models."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"os.environ[\"PIPELINE_API_KEY\"] = \"YOUR_API_KEY_HERE\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create the PipelineAI instance\n",
"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:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"llm = PipelineAI(pipeline_key=\"YOUR_PIPELINE_KEY\", pipeline_kwargs={...})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-09-01 22:30:37 +00:00
"### Create a Prompt Template\n",
2023-04-27 15:22:26 +00:00
"We will create a prompt template for Question and Answer."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"template = \"\"\"Question: {question}\n",
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-09-01 22:30:37 +00:00
"### Initiate the LLMChain"
2023-04-27 15:22:26 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"llm_chain = LLMChain(prompt=prompt, llm=llm)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-09-01 22:30:37 +00:00
"### Run the LLMChain\n",
2023-04-27 15:22:26 +00:00
"Provide a question and run the LLMChain."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"question = \"What NFL team won the Super Bowl in the year Justin Beiber was born?\"\n",
"\n",
"llm_chain.run(question)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2023-09-01 22:30:37 +00:00
"version": "3.10.12"
2023-04-27 15:22:26 +00:00
},
"vscode": {
"interpreter": {
"hash": "a0a0263b650d907a3bfe41c0f8d6a63a071b884df3cfdc1579f00cdc1aed6b03"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}