facebookresearch / ParlAI

A framework for training and evaluating AI models on a variety of openly available dialogue datasets.
https://parl.ai
MIT License
10.49k stars 2.1k forks source link

Contributing OpenAI GPT-3 Models #5042

Closed rguan1 closed 1 year ago

rguan1 commented 1 year ago

Patch description

This pull request adds support for GPT-3 models via OpenAI's python completion endpoint. This is a followup on this issue that discussed how to integrate a model. I've followed the steps at the end of the linked issue to help properly implement the model for ParlAI.

Testing steps We have manually tested the changes and confirmed that they work for both self-chat and interactive commands

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

Enter [DONE] if you want to end the episode, [EXIT] to quit.
20:33:00 | creating task(s): interactive
Enter Your Message: How are you doing today ada?
[Gpt3Agent]: I'm doing well, what do you mean by "aduate"?
Enter Your Message: I am referring to the fact that your model name is text-ada-001
[Gpt3Agent]: The name of your model is text-ada-001.
Enter Your Message: 
(chatbot) Singularity> parlai self_chat -m gpt3 --num-self-chats 1 --selfchat-max-turns 2 --openai-api-key <insert your API key> --max-tokens 40 --model-name text-davinci-003 --init-prompt 'You are trying to make a pull request to an open source repo and want to convince the maintainers to let your pull request through on Github'

[context]: Hi!
[Gpt3Agent_1]: Hi there! How can I help?
   [Gpt3Agent_2]: I'd like to make a pull request to an open source repository on Github and would like to convince the maintainers to let my pull request through. Can you provide any guidance on how to do
facebook-github-bot commented 1 year ago

Hi @rguan1!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

facebook-github-bot commented 1 year ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

rguan1 commented 1 year ago

How do I add the openai dependency? I noticed that the build_website ci/cd is failing because the package is not available?

klshuster commented 1 year ago

How do I add the openai dependency? I noticed that the build_website ci/cd is failing because the package is not available?

You would need to change the requirements.txt file in the top-level repo.

Alternatively, you can do a safe import that instructs a user how to install the openai package if the user does not have the package available

rguan1 commented 1 year ago

@klshuster Thanks for responding! Got it. Which of the two options is preferable? Also, I am unfamiliar with safe import. How do you do that?

mojtaba-komeili commented 1 year ago

@klshuster Thanks for responding! Got it. Which of the two options is preferable? Also, I am unfamiliar with safe import. How do you do that?

For example something like this that we have somewhere in our code:

try:
    import transformers
except ImportError:
    raise ImportError('Please run `pip install transformers`.')
rguan1 commented 1 year ago

So, it looks like the build_website still wants the package explicitly in requirements.txt. Should I put it in then or is it ok if that test doesn't pass?

Overall, the package seems pretty small https://pypi.org/project/openai/#files . So, adding it shouldn't be a big burden.

rguan1 commented 1 year ago

I also plan on adding a GPT4/ChatGPT variant which uses a separate API endpoint soon. So, once I figure out how to iron out CI/CD issues in this PR, I'll make one for the other endpoint in the upcoming weeks. So be on the look out for that! ^.^

klshuster commented 1 year ago

Sure, you can include it, but please pin it to a version (e.g., openai<=1.0.1). And, make sure to update the cache keys in the circle CI config if you do so (please simply change the dates on all keys that look like the linked one to the date you make the change)

rguan1 commented 1 year ago

Added openai to requirements.txt and changed the date to circleci config.yaml. For the yaml changes, I pattern matched against this PR: https://github.com/facebookresearch/ParlAI/commit/104fb967172ff80cac24e22026341cc84253912a

klshuster commented 1 year ago

Could you pin to a <= version instead of >=? you can also do ~= to pin exactly to the version

rguan1 commented 1 year ago

Hopefully that resolves the last of the lint errors. What linter does the lint ci/cd use? It seems to complain about formatting that the autoformat.sh (black autoformat) is ok with?

rguan1 commented 1 year ago

Thanks for reviewing this! Do I merge the PR or do y'all (maintainers) merge the PR?

mojtaba-komeili commented 1 year ago

You can merge it yourself. It always feels good to merge ;)

rguan1 commented 1 year ago

This is my first time contributing to ParlAI. Normally you'd expect a merge button on a the PR once the PR is approved right?

This is what I see at the bottom of this PR. I don't see any merge button which suggests to me that the master branch is protected, so I can't merge it?

image
mojtaba-komeili commented 1 year ago

Oh, OK. I was not aware of that. Merging this. Thanks!