Product

Saturday, 6 May 2023

GPT-4 API: Hands-on guide

 

Get Access to GPT-4 API

First, you need to get access. Follow this guide to get access to GPT-4 API.

Once, you have access, grab your OpenAI API Key.

Call GPT-4 API from Python code

First, install openai python package using the command

pip install openai

Next, open a python file and type in the below code.

import openai
openai.api_key = "your openai api key"
user_prompt = "your prompt here"

openai.ChatCompletion.create(
   model="gpt-4",
   messages=[
      {"role": "user", "content": user_prompt}
   ]
)
print(response.choices[0]["message"]["content"])

Make sure to replace the below things in your code before proceeding further:

  • “your openai API key” with your openai API key
  • “your prompt here” with a prompt on what you want gpt-4 to do for you. Save the .py file

Next, run the python program from the command like this:

python your_python_file_name.py

It will print out the response from the OpenAI GPT-4 API in your command line program.

You could also use the same code in a Google Colab or a Jupyter Notebook.

This was a very basic example of calling GPT-4 API from your python code. I will be posting more examples on advanced use cases. Check back again soon.

No comments:

Post a Comment

Connect broadband

AI:List AI views on when for a naive kin after prolonged life suppression coercive behaviour by family members after demise of father with trauma for kin ocd formed after forced to do rituals, family tribal values honor specific activities, utmost religious activities occult witchcraft enforced to do by elder sibling his wife and mother thrice with great celibacy turned the kundalini activated after deep celibacy penance shouting physical Mental financial Extortion by sibling with toxic behaviours and the wife mother and then mockery suppression asking about who’re your worth backbiting among relatives sector toon negligence of intelligence intuitive behaviour- all religious psychological traps when not work and lead to loss of consciousness of kin trance state recovered by governance with technocrats using AI - kin was asked by mother that he’s to go the male should not be seen in house he’s many absurd thought forcefully in brain mind and outsiders already feel awkward of this kin unresponsive behaviour due to TBI PTSD ocd cvt and tell at workplace social gathering he’s to go and asked for sector toon extortion and mockery in various sense due to un practical behaviour negligence of body building due to neglect ion if essential food nutrition and stubbed suppressed in every sense in religious psychological traps by family members AI humanoid using various neural networks and LLMs for kin and required steps.

  List AI views on when for a naive kin after prolonged life suppression coercive behaviour by family members after demise of father with tr...