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

Add support for openai v1 completions #1006

Merged
merged 9 commits into from
Dec 15, 2023

Conversation

hmstepanek
Copy link
Contributor

@hmstepanek hmstepanek commented Dec 13, 2023

Overview

Adds support for openai v1 completions

  • Move wrapper logic for request capturing of mock server into lower level _request method where we can capture both error and successful responses.
  • Ignore embedding error tests for v1 for now since they haven't been implemented yet.
  • Adds v1 tests for successful and error responses for v1 chat completions for both async and sync.
  • Adds v1 tests for message id capturing and feedback.
  • Change v1 tests in tox to test latest.

@hmstepanek hmstepanek requested a review from a team as a code owner December 13, 2023 18:33
@hmstepanek hmstepanek changed the base branch from main to develop-ai-limited-preview December 13, 2023 18:34
Copy link

github-actions bot commented Dec 13, 2023

🦙 MegaLinter status: ❌ ERROR

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON bandit 2 0 5.76s
✅ PYTHON black 8 0 0 1.98s
✅ PYTHON flake8 8 0 1.07s
✅ PYTHON isort 8 0 0 0.31s
❌ PYTHON pylint 8 13 8.6s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

@codecov-commenter
Copy link

codecov-commenter commented Dec 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (develop-ai-limited-preview@140c7bc). Click here to learn what that means.

Additional details and impacted files
@@                      Coverage Diff                      @@
##             develop-ai-limited-preview    #1006   +/-   ##
=============================================================
  Coverage                              ?   82.10%           
=============================================================
  Files                                 ?      191           
  Lines                                 ?    20132           
  Branches                              ?     3495           
=============================================================
  Hits                                  ?    16530           
  Misses                                ?     2598           
  Partials                              ?     1004           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

# param, etc in the error response, they are not populated on the exception
# object so grab them from the response object instead.
content = getattr(response, "content", b"{}")
response = json_decode(content.decode("utf-8")).get("error", {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the status code and other notice error attributes may be available on exc.body exc.message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to use the body. The exc.message is not the message we are looking for. 😂 It includes the json inside of it which is the same as the default message that we would grab without overriding it so I'm using the message from the body instead still.

body = getattr(exc, "body", {})
notice_error_attributes = {
"http.statusCode": getattr(exc, "status_code", "") or "",
"error.message": body.get("message", "") or "",
Copy link
Contributor

@umaannamalai umaannamalai Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check if body has anything in it to avoid NoneType errors? The body attribute would only be on OpenAI errors and if we hit a standard error like TypeError this may not be populated?

{"role": "system", "content": "You are a scientist."},
{"role": "user", "content": "What is 212 degrees Fahrenheit converted to Celsius?"},
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In v0, we also had the test case of no API key being supplied at all - it may be good to add that here so we're consistent with tests cases across versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just throws the same error as the api_key = "DEADBEEF" case except it's None so I figured we didn't really need to test for that as it's not different.

@umaannamalai umaannamalai merged commit 7b98c51 into develop-ai-limited-preview Dec 15, 2023
46 of 50 checks passed
@umaannamalai umaannamalai deleted the add-openai-v1-completion branch December 15, 2023 02:29
@mergify mergify bot removed the tests-failing label Dec 15, 2023
@umaannamalai umaannamalai added this to the v9.8.0 milestone Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants