Files
langchain/docs/modules/models/llms/integrations/deepinfra_example.ipynb
leo-gan 5420a0e404 updated langchain/docs/modules/models/llms/integrations/ notebooks (#3041)
- Updated `langchain/docs/modules/models/llms/integrations/` notebooks:
added links to the original sites, the install information, etc.
- Added the `nlpcloud` notebook.
- Removed "Example" from Titles of some notebooks, so all notebook
titles are consistent.
2023-04-17 20:25:32 -07:00

3.8 KiB

DeepInfra

DeepInfra provides several LLMs.

This notebook goes over how to use Langchain with DeepInfra.

Imports

In [1]:
import os
from langchain.llms import DeepInfra
from langchain import PromptTemplate, LLMChain

Set the Environment API Key

Make sure to get your API key from DeepInfra. You have to Login and get a new token.

You are given a 1 hour free of serverless GPU compute to test different models. (see here) You can print your token with deepctl auth token

In [2]:
# get a new token: https://deepinfra.com/login?from=%2Fdash

from getpass import getpass

DEEPINFRA_API_TOKEN = getpass()
 ········
In [3]:
os.environ["DEEPINFRA_API_TOKEN"] = DEEPINFRA_API_TOKEN

Create the DeepInfra instance

Make sure to deploy your model first via deepctl deploy create -m google/flat-t5-xl (see here)

In [ ]:
llm = DeepInfra(model_id="DEPLOYED MODEL ID")

Create a Prompt Template

We will create a prompt template for Question and Answer.

In [ ]:
template = """Question: {question}

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

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

Initiate the LLMChain

In [ ]:
llm_chain = LLMChain(prompt=prompt, llm=llm)

Run the LLMChain

Provide a question and run the LLMChain.

In [ ]:
question = "What NFL team won the Super Bowl in 2015?"

llm_chain.run(question)