-
Notifications
You must be signed in to change notification settings - Fork 578
feat(openai): Set system instruction attribute for Completions API #5358
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
base: master
Are you sure you want to change the base?
feat(openai): Set system instruction attribute for Completions API #5358
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Integrations
Other
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| message | ||
| for message in messages | ||
| if not _is_system_instruction_completions(message) | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Iterator consumed twice causes silent data loss
Medium Severity
In _set_completions_api_input_data, the messages parameter is iterated over twice: first by _get_system_instructions_completions(messages) at line 332, then by the list comprehension creating non_system_messages at lines 353-357. Since the type hint accepts Iterable (which includes generators), passing a non-rewindable iterator would cause the second iteration to silently produce an empty list, resulting in lost span data for non-system messages.
Description
For #5359, it is easier to have distinct handling of the messages and input types for completions and responses APIs, respectively.
Set the system instruction attribute, conforming to OTtel structure for OpenAI Completions functions:
https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-system-instructions
Issues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)