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

fix(openai): correctly tag image inputs for chat completions [backport #7759 to 2.2] #7813

Merged
merged 4 commits into from
Dec 4, 2023

Conversation

Yun-Kim
Copy link
Contributor

@Yun-Kim Yun-Kim commented Dec 1, 2023

This backports #7759 to 2.2.

This PR adds a step to stringify input messages before tagging in the OpenAI chat completions endpoint. Previously, we had assumed that messages.content would always be a string (which was true until OpenAI recently added the image input feature to the chat completions endpoint), but it can now be an array of str-str dictionaries.

Testing Strategy

Regression tests have been added, and manual testing has also confirmed that the error reported on #7737 does not appear.

Checklist

  • Change(s) are motivated and described in the PR description.
  • Testing strategy is described if automated tests are not included in the PR.
  • Risk is outlined (performance impact, potential for breakage, maintainability, etc).
  • Change is maintainable (easy to change, telemetry, documentation).
  • Library release note guidelines are followed. If no release note is required, add label changelog/no-changelog.
  • Documentation is included (in-code, generated user docs, public corp docs).
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Title is accurate.
  • No unnecessary changes are introduced.
  • Description motivates each change.
  • Avoids breaking API changes unless absolutely necessary.
  • Testing strategy adequately addresses listed risk(s).
  • Change is maintainable (easy to change, telemetry, documentation).
  • Release note makes sense to a user of the library.
  • Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment.
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy
  • If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Resolves #7737.

This PR adds a step to stringify input messages before tagging in the
OpenAI chat completions endpoint. Previously, we had assumed that
`messages.content` would always be a string (which was true until OpenAI
recently added the image input feature to the chat completions
endpoint), but it can now be an array of str-str dictionaries.

Regression tests have been added, and manual testing has also confirmed
that the error reported on #7737 does not appear.

- [x] Change(s) are motivated and described in the PR description.
- [x] Testing strategy is described if automated tests are not included
in the PR.
- [x] Risk is outlined (performance impact, potential for breakage,
maintainability, etc).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed. If no release note is required, add label
`changelog/no-changelog`.
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/)).
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

- [ ] Title is accurate.
- [ ] No unnecessary changes are introduced.
- [ ] Description motivates each change.
- [ ] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes unless absolutely necessary.
- [ ] Testing strategy adequately addresses listed risk(s).
- [ ] Change is maintainable (easy to change, telemetry, documentation).
- [ ] Release note makes sense to a user of the library.
- [ ] Reviewer has explicitly acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment.
- [ ] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
- [ ] If this PR touches code that signs or publishes builds or
packages, or handles credentials of any kind, I've requested a review
from `@DataDog/security-design-and-guidance`.
- [ ] This PR doesn't touch any of that.
@Yun-Kim Yun-Kim requested review from a team as code owners December 1, 2023 19:47
@Yun-Kim Yun-Kim changed the base branch from main to 2.2 December 1, 2023 19:47
@pr-commenter
Copy link

pr-commenter bot commented Dec 1, 2023

Benchmarks

Benchmark execution time: 2023-12-04 18:43:21

Comparing candidate commit e1e5ff5 in PR branch yunkim/backport-7759-2-2 with baseline commit ee7d50e in branch 2.2.

Found 1 performance improvements and 0 performance regressions! Performance is the same for 89 metrics, 0 unstable metrics.

scenario:flasksimple-appsec-post

  • 🟩 execution_time [-414.950µs; -270.593µs] or [-6.215%; -4.053%]

@majorgreys majorgreys enabled auto-merge (squash) December 4, 2023 13:54
@majorgreys majorgreys merged commit a7d09a1 into 2.2 Dec 4, 2023
53 checks passed
@majorgreys majorgreys deleted the yunkim/backport-7759-2-2 branch December 4, 2023 19:56
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

2 participants