Insanely Fast LLM Hello World with LangChain and GPT

Anna C S Medeiros
2 min readMay 24, 2024

--

Get started with OpenAI API (and don't get left behind)

Photo by Appic on Unsplash

1. Create an OpenAI account

Click here to sign up.

It doesn't matter if you already have a Chat-GPT account, they aren't the same.

2. Add some credit, $1 is fine

Click here and then click on "Add to credit balance".

Each request to the API has a cost, so you will need to have some credit in your account. Cost is dependable on the model used, but as we are going to use GPT-3.5 it is quite affordable.

Cost estimated for this exercise: < $0.01

3. Create and copy your OPENAI_API_KEY

Click here and then click on “Create new secret key”.

Copy your OPENAI_API_KEY, we are going to need it as an environment variable.

4. Create your Python Environment

conda create -n my_env python=3.10

conda activate my_env

(my_env): pip install -U langchain-openai

5. Langchain Hello World

import os
from langchain_openai import OpenAI

os.environ['OPENAI_API_KEY'] = 'my-copied-api'


llm = OpenAI(temperature=0.9) # 0 is less creativity, 1 is maximum creativity

prompt = "What would be a good name for a cute dog that looks like a cat?"

print(llm.invoke(prompt)) # BTW it answered me "Furry Purrkins" LOL

That's all folks! My objective was to help you get started as fast as possible, there are tons of other things to try out, and understand, such as the usage tiers but let's get around to that in the next posts!

Thanks for reading!

Give it some claps to make others find it, too! Also, Make sure you follow me on Medium to not miss anything. Let’s connect on LinkedIn.

--

--

Anna C S Medeiros
Anna C S Medeiros

Written by Anna C S Medeiros

Senior Data Scientist @ Vsoft | GenAI | Computer Vision | NLP | LLM