Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract openai API calls and retry at lowest level #3696

Conversation

collijk
Copy link
Contributor

@collijk collijk commented May 2, 2023

Background

Fourth PR in the chain to organize the LLM interaction. See:

In a previous PR, I extracted a retry decorator from the embedding calls. This PR uses the same retry decorator on an extracted call to create chat completions from the OpenAI API.

Changes

  • APIManager now only manages API budgets. Will be renamed and updated to use LLM structs in the next PR.
  • autogpt.llm.llm_utils.retry_openai_api moved to autogpt.llm.providers.openai.retry_api
  • Low level API methods for creating embeddings and chat completions have been extracted to autogpt.llm.providers.openai and have been appropriately decorated to consistently handle API failure cases.
  • autogpt.llm.llm_utils.create_chat_completion refactored to use low-level wrapped api calls and update the budget manually.
  • Move retry handler tests from tests.unit.test_llm_utils to tests.unit.test_openai

Documentation

N/A, this is primarily code motion

Test Plan

N/A this is primarily code motion and the code in question has unit tests.

PR Quality Checklist

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

@vercel
Copy link

vercel bot commented May 2, 2023

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 Jun 12, 2023 0:42am

@github-actions
Copy link

github-actions bot commented May 2, 2023

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

@collijk collijk added this to the v0.3.1 Release milestone May 2, 2023
@github-actions
Copy link

github-actions bot commented May 2, 2023

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

@codecov
Copy link

codecov bot commented May 2, 2023

Codecov Report

Patch coverage: 86.31% and project coverage change: +0.38 🎉

Comparison is base (49d1a5a) 70.74% compared to head (5c7b222) 71.13%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3696      +/-   ##
==========================================
+ Coverage   70.74%   71.13%   +0.38%     
==========================================
  Files          72       72              
  Lines        3504     3509       +5     
  Branches      556      556              
==========================================
+ Hits         2479     2496      +17     
+ Misses        856      843      -13     
- Partials      169      170       +1     
Impacted Files Coverage Δ
autogpt/app.py 48.35% <0.00%> (-1.09%) ⬇️
autogpt/llm/utils/__init__.py 49.20% <57.14%> (-12.54%) ⬇️
autogpt/llm/providers/openai.py 93.50% <93.15%> (-6.50%) ⬇️
autogpt/llm/api_manager.py 100.00% <100.00%> (+3.57%) ⬆️
autogpt/llm/base.py 92.77% <100.00%> (+0.17%) ⬆️
autogpt/memory/vector/utils.py 83.87% <100.00%> (-1.85%) ⬇️

... and 3 files with indirect coverage changes

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

@github-actions
Copy link

github-actions bot commented May 2, 2023

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

Sudo-psc
Sudo-psc previously approved these changes May 4, 2023
@p-i-
Copy link
Contributor

p-i- commented May 5, 2023

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

@github-actions
Copy link

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

@vercel vercel bot temporarily deployed to Preview May 13, 2023 21:31 Inactive
@github-actions
Copy link

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

@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label May 13, 2023
@p-i- p-i- modified the milestones: v0.3.1 Release, v0.3.2-release May 14, 2023
@lc0rp
Copy link
Contributor

lc0rp commented May 19, 2023

James, @collijk - I know you've got your head down. Is this worth trying to put in 0.3.2? Is anyone else available to resolve conflicts?

@lc0rp
Copy link
Contributor

lc0rp commented May 19, 2023

Seems to me, this could still be valuable even after the re-arch. Marking for maintainer-review

@lc0rp lc0rp added the ready-for-maintainer Catalyst has decided this PR looks ready for a maintainer to merge label May 19, 2023
@vercel
Copy link

vercel bot commented May 25, 2023

Deployment failed with the following error:

Resource is limited - try again in 3 minutes (more than 100, code: "api-deployments-free-per-day").

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label May 25, 2023
@github-actions
Copy link

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

@github-actions
Copy link

This PR exceeds the recommended size of 500 lines. Please make sure you are NOT addressing multiple issues with one PR.

@github-actions
Copy link

This PR exceeds the recommended size of 500 lines. Please make sure you are NOT addressing multiple issues with one PR.

@github-actions
Copy link

This PR exceeds the recommended size of 500 lines. Please make sure you are NOT addressing multiple issues with one PR.

@lc0rp lc0rp modified the milestones: v0.4.1 Release, v0.4.2 Release Jun 14, 2023
@github-actions
Copy link

This PR exceeds the recommended size of 500 lines. Please make sure you are NOT addressing multiple issues with one PR.

@Auto-GPT-Bot
Copy link
Contributor

You changed AutoGPT's behaviour. The cassettes have been updated and will be merged to the submodule when this Pull Request gets merged.

@waynehamadi waynehamadi merged commit 6e6e7fc into Significant-Gravitas:master Jun 14, 2023
16 checks passed
erik-megarad added a commit to erik-megarad/Auto-GPT that referenced this pull request Jun 16, 2023
Extract openai API calls and retry at lowest level (Significant-Gravitas#3696)

* Extract open ai api calls and retry at lowest level

* Forgot a test

* Gotta fix my local docker config so I can let pre-commit hooks run, ugh

* fix: merge artiface

* Fix linting

* Update memory.vector.utils

* feat: make sure resp exists

* fix: raise error message if created

* feat: rename file

* fix: partial test fix

* fix: update comments

* fix: linting

* fix: remove broken test

* fix: require a model to exist

* fix: BaseError issue

* fix: runtime error

* Fix mock response in test_make_agent

* add 429 as errors to retry

---------

Co-authored-by: k-boikov <64261260+k-boikov@users.noreply.github.com>
Co-authored-by: Nicholas Tindle <nick@ntindle.com>
Co-authored-by: Reinier van der Leer <github@pwuts.nl>
Co-authored-by: Nicholas Tindle <nicktindle@outlook.com>
Co-authored-by: Luke K (pr-0f3t) <2609441+lc0rp@users.noreply.github.com>
Co-authored-by: Merwane Hamadi <merwanehamadi@gmail.com>

Add 16k gpt model

Refactor module layout of command classes

Remove nonessential commands

Basic working version of functions support

Make required args required

Rewrite write_file to work with new arguments

Replace gpt-3.5-turbo by gpt-3.5-turbo-0613

gpt-3.5-turbo-16k-0613 everywhere

models that are not 0613 are gone

Refactor message history and cycling

Ask users to update their models

Fix issues with token counting

Fix issues with history trimming

Remove self feedback and rename user_input to triggering_prompt when necessary

Fix json parsing issues

Document the steps of the interaction loop

Fix issues with parsing reply

Refactor MessageCycle

Up word limit in prompt

Change command prompt constraint to reference functions

Fix {} arguments error

Fix issues with command arguments

Fix issues with function arguments attached to assistant responses

Evolve prompts to improve AI understand of function calls

Fix issues with command result serialization

Fix read_file path bug

Fix a bunch of tests

Abandon function memory role for now

Fix history and summarization issues and its tests

Change task_complete so the AI doesn't call it accidentally

Remove agent manager as it is unused and now broken

Fix token encoding model edge cases

Fix openai provider tests

Update setup test

Cleanup imports

Trigger CI

Fix LogCycle and stringify commands

Prompt change

Reduce diff size due to moving functions

Include missing test
waynehamadi pushed a commit that referenced this pull request Jun 17, 2023
Extract openai API calls and retry at lowest level (#3696)

* Extract open ai api calls and retry at lowest level

* Forgot a test

* Gotta fix my local docker config so I can let pre-commit hooks run, ugh

* fix: merge artiface

* Fix linting

* Update memory.vector.utils

* feat: make sure resp exists

* fix: raise error message if created

* feat: rename file

* fix: partial test fix

* fix: update comments

* fix: linting

* fix: remove broken test

* fix: require a model to exist

* fix: BaseError issue

* fix: runtime error

* Fix mock response in test_make_agent

* add 429 as errors to retry

---------

Co-authored-by: k-boikov <64261260+k-boikov@users.noreply.github.com>
Co-authored-by: Nicholas Tindle <nick@ntindle.com>
Co-authored-by: Reinier van der Leer <github@pwuts.nl>
Co-authored-by: Nicholas Tindle <nicktindle@outlook.com>
Co-authored-by: Luke K (pr-0f3t) <2609441+lc0rp@users.noreply.github.com>
Co-authored-by: Merwane Hamadi <merwanehamadi@gmail.com>

Add 16k gpt model

Refactor module layout of command classes

Remove nonessential commands

Basic working version of functions support

Make required args required

Rewrite write_file to work with new arguments

Replace gpt-3.5-turbo by gpt-3.5-turbo-0613

gpt-3.5-turbo-16k-0613 everywhere

models that are not 0613 are gone

Refactor message history and cycling

Ask users to update their models

Fix issues with token counting

Fix issues with history trimming

Remove self feedback and rename user_input to triggering_prompt when necessary

Fix json parsing issues

Document the steps of the interaction loop

Fix issues with parsing reply

Refactor MessageCycle

Up word limit in prompt

Change command prompt constraint to reference functions

Fix {} arguments error

Fix issues with command arguments

Fix issues with function arguments attached to assistant responses

Evolve prompts to improve AI understand of function calls

Fix issues with command result serialization

Fix read_file path bug

Fix a bunch of tests

Abandon function memory role for now

Fix history and summarization issues and its tests

Change task_complete so the AI doesn't call it accidentally

Remove agent manager as it is unused and now broken

Fix token encoding model edge cases

Fix openai provider tests

Update setup test

Cleanup imports

Trigger CI

Fix LogCycle and stringify commands

Prompt change

Reduce diff size due to moving functions

Include missing test

Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com>
Auto-GPT-Bot pushed a commit to erik-megarad/Auto-GPT that referenced this pull request Jun 17, 2023
Extract openai API calls and retry at lowest level (Significant-Gravitas#3696)

* Extract open ai api calls and retry at lowest level

* Forgot a test

* Gotta fix my local docker config so I can let pre-commit hooks run, ugh

* fix: merge artiface

* Fix linting

* Update memory.vector.utils

* feat: make sure resp exists

* fix: raise error message if created

* feat: rename file

* fix: partial test fix

* fix: update comments

* fix: linting

* fix: remove broken test

* fix: require a model to exist

* fix: BaseError issue

* fix: runtime error

* Fix mock response in test_make_agent

* add 429 as errors to retry

---------

Co-authored-by: k-boikov <64261260+k-boikov@users.noreply.github.com>
Co-authored-by: Nicholas Tindle <nick@ntindle.com>
Co-authored-by: Reinier van der Leer <github@pwuts.nl>
Co-authored-by: Nicholas Tindle <nicktindle@outlook.com>
Co-authored-by: Luke K (pr-0f3t) <2609441+lc0rp@users.noreply.github.com>
Co-authored-by: Merwane Hamadi <merwanehamadi@gmail.com>

Add 16k gpt model

Refactor module layout of command classes

Remove nonessential commands

Basic working version of functions support

Make required args required

Rewrite write_file to work with new arguments

Replace gpt-3.5-turbo by gpt-3.5-turbo-0613

gpt-3.5-turbo-16k-0613 everywhere

models that are not 0613 are gone

Refactor message history and cycling

Ask users to update their models

Fix issues with token counting

Fix issues with history trimming

Remove self feedback and rename user_input to triggering_prompt when necessary

Fix json parsing issues

Document the steps of the interaction loop

Fix issues with parsing reply

Refactor MessageCycle

Up word limit in prompt

Change command prompt constraint to reference functions

Fix {} arguments error

Fix issues with command arguments

Fix issues with function arguments attached to assistant responses

Evolve prompts to improve AI understand of function calls

Fix issues with command result serialization

Fix read_file path bug

Fix a bunch of tests

Abandon function memory role for now

Fix history and summarization issues and its tests

Change task_complete so the AI doesn't call it accidentally

Remove agent manager as it is unused and now broken

Fix token encoding model edge cases

Fix openai provider tests

Update setup test

Cleanup imports

Trigger CI

Fix LogCycle and stringify commands

Prompt change

Reduce diff size due to moving functions

Include missing test

Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
behaviour change ready-for-maintainer Catalyst has decided this PR looks ready for a maintainer to merge size/xl
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

10 participants