- AI Authority
- Posts
- Turning ChatGPT Into a Meteorologist in Minutes š¦ļø
Turning ChatGPT Into a Meteorologist in Minutes š¦ļø
Discover how we're transforming ChatGPT into your personal weatherbot, forecasting weather and advising on plant care right at your fingertips.
Good morning, AI explorers!
Welcome to a freshly re-imagined edition of AI Authority.
Our mission ā to empower you to navigate the AI universe in a more impactful way!
We're evolving our newsletter to bring you:
Practical, actionable insights to help you harness the power of AI
Dynamic tools to utilize in your AI journey
Comprehensive, step-by-step guides that demystify complex processes
šļø In this edition: Build your own app in minutes that leverages AI
Everything you need to know ā¬ļø
Learn one new skill in the AI world:
š§ ChatGPT Meets Meteorology: Your Personal Weatherbot Guide
Did you ever wish you had your own personal meteorologist at your fingertips to forecast the weather? Maybe to provide advice on how to care for your precious plants?
Today, we're turning that wish into a reality by transforming ChatGPT, OpenAI's language model, into your personal bot-meteorologist. Letās dive in:
āļø What Is an API?
How can ChatGPT possibly know the weather when its knowledge cut-off is 2021? Thatās where APIs come in.
Think of APIs as the secret language of software. They're a bunch of rules and protocols, allowing online applications to talk and exchange notes.
OpenAI's API is a particularly powerful one, enabling us to leverage its machine-learning wizardry in our applications. And the free Weather API will give ChatGPT all the information it needs to become the perfect meteorologist.
š Launching Our Weatherbot: Step-by-Step
Step 1: Getting Set Up āļø
First, you need to set up your Python environment, which is the place youāre going to write or paste code into. The simplest place to start is Online Python.
Once youāve set up your environment, install OpenAIās Python library by pasting the following code into the āTerminalā:
pip install openai
Step 2: Secret Handshake ā API Key š
Next, we need a secret password, called the API key, that OpenAI uses to know it's you. It's like a secret handshake. You can get this from OpenAIās official website and must include it when sending a message (API request).
Hang onto this, weāll use it later. And be careful not to share this key with anyone.
Step 3: Small Talk with OpenAI š£ļø
Now that youāve set up your Python environment, installed OpenAIās library, and grabbed your secret API key, you can ask OpenAI questions! For example, you can ask it to respond to a simple "Hello!" greeting.
Just paste the following code into your main.py file and replace OPENAI_API_KEY with your actual API key:
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
completion = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(completion.choices[0].message)
Step 4: Weatherbot in Action āļø
The last step is to add the Weather API and send that information to ChatGPT so it can be your meteorologist.
Youāll need to install Pythonās requests library, which is done the exact same way as the OpenAI library ā āpip install requestsā. Then, add your Weather API key, which can be found here, the same way you added your OpenAI API key.
Now that you know the basics, you can ask ChatGPT to write the code necessary to turn ChatGPT (or GPT-4) into your own personal weatherman.
Hereās that code:
import requests
import openai
# Add your OpenAI and weather API keys here
OPENAI_API_KEY = "your-openai-key"
WEATHER_API_KEY = "your-weather-key"
openai.api_key = OPENAI_API_KEY
def get_weather(location):
"""Get the weather forecast for the given location."""
response = requests.get(f"http://api.weatherapi.com/v1/forecast.json?key={WEATHER_API_KEY}&q={location}&days=1")
forecast = response.json()
# Extract the temperature for the day
temperature = forecast['forecast']['forecastday'][0]['day']['avgtemp_c']
return temperature
def ask_gpt_weather(location):
"""Ask GPT about the weather in the given location."""
temperature = get_weather(location)
message = f"The temperature today in {location} is {temperature}C. How is the weather there?"
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a knowledgeable assistant."},
{"role": "user", "content": message},
]
)
return response['choices'][0]['message']['content'].strip()
def main():
"""Main function to run the app."""
location = input("What's your location? ")
gpt_response = ask_gpt_weather(location)
print(gpt_response)
if __name__ == "__main__":
main()
Congrats, youāve successfully used the OpenAI and Weather APIs to create a fun app that expands ChatGPTās knowledge base!
If you run into any problems, or have any questions or comments, about this process, reach out to us on X (Twitter).
š° Some of the top headlines in AI that caught our eye:
ā Op-Ed: AI May Take Doctorās Roles Sooner Rather Than Later (link)
ā AI Art Showdown: How Midjourney, Stable Diffusion, SDXL Stack Up (link)
ā Dell is All In On Generative AI (link)
ā AI Search of Neanderthal Proteins Resurrects Extinct Antibiotics (link)
ā Walmart Using AI to Streamline Organization (link)
šØ Three of our favorite tweets, threads, AI generations and more:
How to use custom parameters in Midjourney to save time and resurface your favorite settings via @nickfloats:
Most people don't know this, but you can create custom parameters in Midjourney.
Say you put "--ar 16:9 --stylize 150 --weird 25 --style raw" at the end of every cinematic prompt.
You can create a parameter called --cinematic that automatically adds those settings.
Here's how
ā Nick St. Pierre (@nickfloats)
2:52 PM ā¢ Jul 31, 2023
An entire movie trailer created using AI tools. Check out the impressive video, and the stack of platforms Marco used for each step:
šš š¬ MOVIE TRAILER: EXO-19
(Midjourney + Runway)ššš§ (CRANK up your sound and put your headphones on!!)
-----
They came in peace.
To a World undiscovered.
In search of a new beginning.
But, what they encounter ... could lead to their end.-----
STYLE: Techno-Natureā¦ twitter.com/i/web/status/1ā¦ā Marco | AI Digital Explorer (@ai_artworkgen)
2:59 PM ā¢ Jul 30, 2023
Much of the mainstream sentiment around AI thinks it only copies/rearranges what already exists.
But research shows that ChatGPT is already in the top 1% of creative thinking:
Not many people expected this:
Research from the University of Montana placed ChatGPT in the top 1% for original creative thinking.
They had ChatGPT take the Torrance Tests of Creative Thinking (TTCT) and compared the scores with 2,700 college students. The TTCT uses promptsā¦ twitter.com/i/web/status/1ā¦
ā Santiago (@svpino)
3:02 PM ā¢ Jul 29, 2023
Thatās all for today!
If you havenāt already, subscribe to receive AI Authority in your inbox. And share it with an AI-curious friend!