AutoGPT icon indicating copy to clipboard operation
AutoGPT copied to clipboard

OpenAI Plugins/OpenAPI(Swagger) REST APIs commands generator

Open evahteev opened this issue 1 year ago • 26 comments

Background

OpenAI declared their interface for plugins, which effectively could be commands for Auto-GPT OpenAI plugins spec https://platform.openai.com/docs/plugins/introduction .

Effectively it's OpenAPI(Swagger) specification, with OpenAI Plugin metadata on top of it For example here is weather plugin https://weathergpt.vercel.app/ https://weathergpt.vercel.app/.well-known/ai-plugin.json https://github.com/steven-tey/weathergpt

I started to work on this as a testing framework for OpenAI plugins, while access to plugins Feature there is still behind the whitelist.

Changes

As this work was started previously in https://github.com/BillSchumacher/Auto-GPT/pull/4 and was merged in master half-baked, this is a continuation of it and finalization so it actually works. Compared to the previous PR OpenAPI/AI support was moved from plugins.py into commands openapi.py instead as Commands are looking better suited for REST Endpoint - Method type of calls and ingestions.

Documentation

image

To achieve client generation for any REST API which supports OpenAPI spec openapi command was added, where we generate REST API client using openapi-python-client, instantiating it and injecting in commands, based on config provided to users.

Any APIs added to openapi_commands.yaml and whitelisted in OPENAPI_APIS envs would be fetched for OpenAPI spec of OpenAI manifest and all methods found would be added to Auto-GPT commands.

For any REST API added to the config, we have:

  • OpenAPI(Swagger) spec parsed and each endpoint-method ingested as separate commands
  • OpenAI manifest is generated and saved in ./plugins/openapi/{api_name}/ai-plugin.json making it OpenAI plugins generator
  • Custom python client package is generated and placed ./plugins/openapi/{api_name}/client
  • Making changes in manifest/openapi spec/client anyone can effectively develop new API plugins, or adjust them.

Test Plan

All added methods are covered with unit tests. Manually tested.

Future plans

  • Add Authorization support
  • Add ability to generate plugins in Auto-GPT runtime when it's hitting rest API's supporting OpenAPI schema.

PR Quality Checklist

  • [X] My pull request is atomic and focuses on a single change.
  • [X] I have thoroughly tested my changes with multiple different prompts.
  • [X] I have considered potential risks and mitigations for my changes.
  • [X] I have documented my changes clearly and comprehensively.
  • [X] I have not snuck in any "extra" small tweaks changes

evahteev avatar Apr 20 '23 08:04 evahteev

@BillSchumacher I've refactored previously merged https://github.com/BillSchumacher/Auto-GPT/pull/4 and moved this functionality to commands injection as it looked like it fits better there. Can you please review it? Thanks.

evahteev avatar Apr 20 '23 08:04 evahteev

I see throughout the PR openai and openapi are used interchangeably. Easy to do, but they are very different.

buckedunicorn avatar Apr 20 '23 13:04 buckedunicorn

I see throughout the PR openai and openapi are used interchangeably. Easy to do, but they are very different.

There are methods that are specific for support of OpenAI Plugins Interface https://platform.openai.com/docs/plugins/introduction that's why they named differently. Actually, I see one place where it could be changed based on what's happening inside, going to fix it, thanks.

evahteev avatar Apr 20 '23 14:04 evahteev

LGTM!

kovalenp avatar Apr 20 '23 15:04 kovalenp

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 20 '23 17:04 github-actions[bot]

How does this work with passing data to the prompt? Some conversations need to be had about how we load plugins in general.

ntindle avatar Apr 20 '23 23:04 ntindle

How does this work with passing data to the prompt? Some conversations need to be had about how we load plugins in general.

It's returned as Json, same way search or any other command does, here's an example:

image

evahteev avatar Apr 21 '23 08:04 evahteev

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 21 '23 08:04 github-actions[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 22 '23 12:04 github-actions[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 23 '23 03:04 github-actions[bot]

Test loading normal and open ai plugins side by side

ntindle avatar Apr 23 '23 03:04 ntindle

Codecov Report

Patch coverage: 77.24% and project coverage change: -7.48 :warning:

Comparison is base (2b5852f) 45.09% compared to head (433547b) 37.62%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2642      +/-   ##
==========================================
- Coverage   45.09%   37.62%   -7.48%     
==========================================
  Files          60       60              
  Lines        2856     2860       +4     
  Branches      472      478       +6     
==========================================
- Hits         1288     1076     -212     
- Misses       1463     1727     +264     
+ Partials      105       57      -48     
Impacted Files Coverage Δ
autogpt/cli.py 0.00% <0.00%> (ø)
autogpt/plugins.py 89.58% <ø> (+15.70%) :arrow_up:
autogpt/commands/openapi.py 78.57% <78.57%> (ø)
autogpt/config/config.py 74.14% <100.00%> (-1.20%) :arrow_down:

... and 15 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Apr 23 '23 03:04 codecov[bot]

Run black and issort to fix linter

ntindle avatar Apr 23 '23 03:04 ntindle

Add tests to not reduce coverage of project

ntindle avatar Apr 23 '23 03:04 ntindle

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 23 '23 19:04 github-actions[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview May 4, 2023 5:20am

vercel[bot] avatar Apr 26 '23 18:04 vercel[bot]

This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size

github-actions[bot] avatar Apr 26 '23 18:04 github-actions[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar Apr 26 '23 18:04 github-actions[bot]

This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size

github-actions[bot] avatar Apr 26 '23 18:04 github-actions[bot]

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Apr 26 '23 20:04 github-actions[bot]

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

github-actions[bot] avatar May 04 '23 05:05 github-actions[bot]

This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size

github-actions[bot] avatar May 04 '23 05:05 github-actions[bot]

This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size

github-actions[bot] avatar May 04 '23 05:05 github-actions[bot]

Codecov Report

Patch coverage: 77.24% and project coverage change: -0.05 :warning:

Comparison is base (cb97f5c) 60.96% compared to head (cecc26b) 60.91%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2642      +/-   ##
==========================================
- Coverage   60.96%   60.91%   -0.05%     
==========================================
  Files          72       72              
  Lines        3302     3306       +4     
  Branches      542      548       +6     
==========================================
+ Hits         2013     2014       +1     
- Misses       1151     1159       +8     
+ Partials      138      133       -5     
Impacted Files Coverage Δ
autogpt/main.py 0.00% <0.00%> (ø)
autogpt/plugins.py 92.30% <ø> (+16.94%) :arrow_up:
autogpt/commands/openapi.py 78.57% <78.57%> (ø)
autogpt/config/config.py 75.00% <100.00%> (+0.14%) :arrow_up:

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar May 04 '23 05:05 codecov[bot]

This is a mass message from the AutoGPT core team. Our apologies for the ongoing delay in processing PRs. This is because we are re-architecting the AutoGPT core!

For more details (and for infor on joining our Discord), please refer to: https://github.com/Significant-Gravitas/Auto-GPT/wiki/Architecting

p-i- avatar May 05 '23 00:05 p-i-

References issue #3652

p-i- avatar May 05 '23 17:05 p-i-

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar May 25 '23 18:05 github-actions[bot]

@evahteev are you still interested in this? I know its been a good bit

ntindle avatar Jun 10 '23 03:06 ntindle

Closed as it was merged

evahteev avatar Jun 28 '23 20:06 evahteev