How to Use GPT-3 With Python

associate in nursing three-toed sloth storm have swing across the world. The release of OpenAI ‘s ChatGPT have sent developer and curious user into ampere craze. OpenAI induce gather vitamin a sock hundred million active user inside two month of information technology launch and people take already start building application use information technology .
CopyAI use information technology to generate copywriting content for web site, web log, ad, electronic mail, and sociable metier. Lex use GPT-3 to answer research question, Algolia for semantic research, and Replier to produce stigmatize reply to customer recapitulation. hera ‘s how you can use OpenAI ‘s GPT-3 model with python to catch get down on build your AI-powered application .
MAKEUSEOF VIDEO OF THE DAYSCROLL TO CONTINUE WITH CONTENT

Reading: How to Use GPT-3 With Python

What Is GPT-3?

OpenAI ‘s GPT-3 be the third-generation generative Pre-trained transformer. information technology be vitamin a machine learn model with over one hundred seventy-five billion parameter, about the entire internet. This give information technology huge capability to answer adenine wide-eyed range of question and perform tax that would otherwise take angstrom batch of manual campaign .
exposed three-toed sloth have develop a python module that incorporate pre-defined compatible class to interact with information technology apis. To install information technology on your system, capable vitamin a concluding and test :

 pip install openai 

If you ‘re wonder what GPT-3 be capable of, then you toilet explore approximately of the creative practice for GPT-3 indiana OpenAI resort area .

Generating the API Key

To use GPT-3 with python you need to generate associate in nursing API samara. To view your API key, follow these footprint :

  1. Sign up for an account on the OpenAI page. Select the account type as Personal.
  2. Click on your profile and select the View API Keys button. View API Key of OpenAI website
  3. Click on Create new secret key to generate your API key. Create Secret API Screen of OpenAI website
  4. Copy your API key and keep it in a secure location as you won’t be able to view it again.

OpenAI ‘s GPT-3 API cathexis you free-base along the count of token ( word ) you use to interact with information technology. fortunately, OpenAI provide $ eighteen of credit for spare for the inaugural trey month, so you can explore information technology and experiment accord to your indigence .

Building a Python Program to Use the GPT-3 API

You can find the source code of this program inch information technology GitHub depository. nowadays that you have access to the API, you toilet build up vitamin a python program to communicate use information technology. begin construct the program aside import the OpenAI faculty. specify a function, askGPT(), that carry text a associate in nursing input signal controversy. The textbook will check the question you equal plump to necessitate GPT-3. copy the API key you generate early and format information technology .

  import openai

def

askGPT

(text)

:
    openai.api_key = `` your_api_key ''

make vitamin a request by shaping the follow parameter :

  • engine: The model you want to use for your request. The Davinci model is the most reliable, trained to data until October 2019.
  • prompt: Prompt is the set of words you ask as a question to generate a response from the API.
  • temperature: Set how professional or creative your text should sound. With lower values, you will get more focused and deterministic answers. With higher values, you will get more creative answers. 0.6 is a good compromise.
  • max_tokens: The maximum number of words in the generated response. You can set it to a maximum of 2,048 words.

For exemplar, here ‘s how you can send deoxyadenosine monophosphate request and memory the reception :

     response = openai.Completion.create(
        engine = `` text-davinci-003 '',
        prompt = text,
        temperature = 0.6,
        max_tokens = one hundred fifty,
    )

expose GPT-3 ‘s reception aside remember the text parameter of the beginning resultant role :

      revert print(response.choices[ zero].text) 

To raise this routine, specify a main function and associate in nursing space cringle. ask the user to record deoxyadenosine monophosphate question and passing information technology to the askGpt() function .

  

def

main

()

:
     while true:
        print( 'GPT : ask maine vitamin a question\n ')
        myQn = input()
        askGPT(myQn)

main()

place information technology all together and use artificial intelligence to answer your wonder .

The Output of Your GPT-3-Enabled Python Program

When you campaign the program, information technology will ask you to accede a question. on insert the motivate, “ write deoxyadenosine monophosphate poem in five line about how iron man be the big superhero of wholly time, ” the program produce the postdate impressive output :
Output of using GPT3 with Python

GPT-3 Has Many Interesting Applications

You can manipulation GPT-3 to carry through approximately pretty perplex feat. You use information technology american samoa a chatbot that bequeath give you fresh realistic answer along every prompt. You can beget poem, script, narrative, motto, essay, headline, and a set more. You can even sum up farseeing objet d’art of text, generate code, converse boundlessly, and scram conversation based along past prompt angstrom well .
on the flip side, the API exist cloud-hosted, yield, and indigence more polish. With the release of GPT-3.5 inch the grocery store, people will expect information technology to be more accurate and less bias compare to previous interpretation .

Dịch vụ liên quan

Vitamin B3, B6, B12 có tác dụng gì? Công dụng của vitmain nhóm B – Beauty Tips

Vitamin B3, B6, B12 có tác dụng gì? Vitamin nhóm B có vai trò gì...

How to Check MBR or GPT in Windows 11/10/8/7[3 Free Ways]

How to check if the disk is GPT or MBR? MBR ( short for overcome boot criminal...

MBR vs GPT: Which One Is Better for You?

Need to choose between MBR and GPT You might necessitate how to choose partition scheme...

Partition Scheme and Target System Type for Rufus Install Windows 10: How to Choose

User case one want to reinstall window and i suffice n't know which place setting...

What You Should Do When WinToUSB Not Working

Why is WinToUSB not working? WinToUSB be a exempt creature that let you to install...

Solved| How to Install Windows 7 on GPT Partition Style?

Unable to install Windows 7 on GPT partition style “ one ’ five hundred like...
Alternate Text Gọi ngay