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:
A proper chat history: by appending turns of conversation to the final prompt
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
Cost - Repeatedly prompting the completion API can be expensive especially on the more expensive models like Davinci.
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.
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 |
---|---|
|
Add your OpenAI api key |
|
Choose a version of GPT-3 that varies on cost, quality, and speed like text-davinci-003, text-davinci-002, |
|
Initial prompt that starts the conversation. Turns of conversation are appended to subsequent OpenAI |
|
Suffix that comes after the completion of an inserted text |
|
The max number of tokens generated as a single conversation turn |
|
Temperature ranges between 0-2 such that higher temperature will make outputs more random while lower |
|
Determines nucleus sampling rate |
|
Stop sequence is a string that will stop further generation of tokens |
|
Presence penalty ranges between -2.0 to 2.0 such that more positive values will reduce chance of generating |
|
Frequency penalty ranges between -2.0 to 2.0 such that more positive values will reduce chance of |