GPT3

This is an agent that interfaces with OpenAI’s completion V1 api (/v1/completions). The completions v1 API broadly covers the models that fall under GPT-3 like:

  • text-davinci-003

  • text-curie-001

  • text-ada-001

The model works by prompting the completion API repeatedly with the proper chat history appended to the prompt.

A more comprehensive set of available models or engines is listed in the official docs here

We’ve written the model wrapper such that it can handle both:

  1. A proper chat history: by appending turns of conversation to the final prompt

  2. An initial conversation prompt which can offer instruction to the GPT-3 model

Setup

pip install openai

More info on setup is outlined in the official docs here.

Once the openai Python package is installed, you can start using the endpoint as long as you have a valid OpenAI API key generated and ready-to-use.

Interactive example

parlai interactive -m gpt3 --openai-api-key <insert your api key> --max-tokens 40 --model-name text-ada-001

Self chat example

parlai self_chat -m gpt3 --num-self-chats 1 --selfchat-max-turns 5 --openai-api-key <insert your api key> --max-tokens 40 --model-name text-davinci-002 --partner-model-file zoo:blender/blender_90M/model

Limitations

This API wrapper has three major limitations

  1. Cost - Repeatedly prompting the completion API can be expensive especially on the more expensive models like Davinci.

  2. Rate limiting - API queries can run into rate limiting issues which will cause the conversation to error out. Official docs offers more insight on dealing with this issue.

  3. Token Limit - A combination of prompt and response can usually only be up to 2049 and may be smaller depending on the model for GPT-3 official docs. This limits the size of both the initial prompt as well as the length of conversation that we can feed back into the model. Exceeding this limit will cause the conversation to error out.

Gpt3Agent Options

GPT3 Arguments

Argument

Description

--openai-api-key

Add your OpenAI api key

--model-name

Choose a version of GPT-3 that varies on cost, quality, and speed like text-davinci-003, text-davinci-002,

text-curie-001, text-babbage-001, or text-ada-001

--init-prompt

Initial prompt that starts the conversation. Turns of conversation are appended to subsequent OpenAI

completion queries.

Default: ````.

--suffix

Suffix that comes after the completion of an inserted text

--max-tokens

The max number of tokens generated as a single conversation turn

--temperature

Temperature ranges between 0-2 such that higher temperature will make outputs more random while lower

values make the output more deterministic

Default: 1.0.

--top-p

Determines nucleus sampling rate

Default: 1.0.

--stop-sequence

Stop sequence is a string that will stop further generation of tokens

--presence-penalty

Presence penalty ranges between -2.0 to 2.0 such that more positive values will reduce chance of generating

tokens that already appeared in text

Default: 0.0.

--frequency-penalty

Frequency penalty ranges between -2.0 to 2.0 such that more positive values will reduce chance of

generating tokens that appear frequently

Default: 0.0.