Files
2023-03-26 19:49:46 -07:00

3.1 KiB

GooseAI LLM Example

This notebook goes over how to use Langchain with GooseAI.

Install openai

The openai package is required to use the GooseAI API. Install openai using pip3 install openai.

In [ ]:
$ pip3 install openai

Imports

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

Set the Environment API Key

Make sure to get your API key from GooseAI. You are given $10 in free credits to test different models.

In [ ]:
os.environ["GOOSEAI_API_KEY"] = "YOUR_KEY_HERE"

Create the GooseAI instance

You can specify different parameters such as the model name, max tokens generated, temperature, etc.

In [ ]:
llm = GooseAI()

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 the year Justin Beiber was born?"

llm_chain.run(question)