Hi friends🙋♂️ welcome back to Blogs-with-Achu. This blog is different from all of my previous blogs, In this blog, we are going to interact with ChatGPT locally on our machine. Let’s get started:
Today’s blog agenda:
-
My reflections regarding ChatGPT.
-
Keep these points in mind.
-
Interact with ChatGpt using API
-
Summary.
1. My reflections regarding ChatGPT.
ChatGPT has revolutionized the field of Artificial Intelligence. I think everyone used it, it is awesome. I was so impressed, I have no words to describe it. Everything was fine for me, but one thing I was not happy with about OpenAI(The entity responsible for developing ChatGPT) is that the GPT model(GPT 3.5 and GPT-4) is not Open source (which means the code is not available to open, it is like a proprietary software like windows).
There are two features available as we know, GPT3.5 and GPT-4. GPT3.5 is free to use, for GPT-4 you need to pay $20/month. Till now I have used ChatGPT On their website. But once came to know their API called OpenAI API( it’s a powerful tool kit to interact with OpenAI Large Language Model called GPT-3.5 and GPT-4). Let’s see How we interact with that model.
2. Keep these points in mind.
There are a few things we need to consider before getting started with using OpenAI API keys.
-
Please note that OpenAI currently offers a $5 credit for new users, allowing you to start experimenting with their APIs at no cost. This credit is available for use during the first 3 months of your account. After the initial 3-month period, the pricing will transition to a pay-as-you-go model.
-
Make sure to securely store your Secret Key in a permanent location; it will only be visible during the creation process.
Don’t worry I think $5 credit is more than enough are testing smaller kinds of stuff.
3. Interact with ChatGpt using API
Visit the OpenAI website to get started click on me
Once you land, Click API Section to get started with OpenAI API Click here
You can see the Documentation, API Reference, Examples, and playground feature to play around with ChatGpt. once you log in you can see your account details in the right corner. There are many options available click view API key options.
I created a API key for Interaction with ChatGPT
Once you created your API Keys, Let’s dive into coding parts, Don’t worry about coding parts, it is simple and written in Python, so you easily understand them.
please install the OpenAI package, before get started
#pip install openai
import openai
#Enter your API key it start with sk
openai.api_key = 'sk-'
def task():
#In the prompt section give you question what ever it might be
prompt = 'who is the founder of jainism'
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "who is the founder of jainism."},
{"role": "assistant", "content": ""}
]
)
print(response.choices[0]['message']['content'])
if __name__ == '__main__':
task()
The output will be like this
How fascinating is this right?, The output is generated by the GPT 3.5 model, but this time we do not use their website, instead you used API to interact with the model, which is the best way to use ChatGPT.
please modify the prompt to get a different output, in case you face any issues Please mention that in the comment section.
4. Summary
This is just the beginning we can do a lot more stuff by using ChatGPT API keys, In the future we can see many projects and blogs related to LLM and Generative AI. If you find it useful please share it with your friends and let others also make use of it. Happy learning and happy reading! 📖
Regards
Achanandhi M👦