Skip to content

Conversation

@szyhf
Copy link

@szyhf szyhf commented May 19, 2025

Describe the change

Add support for extra fields in ChatCompletionRequest to allow experimental features not yet officially supported in the API.

Provide OpenAI documentation link

https://github.com/openai/openai-go/blob/main/README.md?plain=1#L334-L336

Describe your solution

Implemented a flexible mechanism to add extra fields to ChatCompletionRequest:

  1. Added extraFields map[string]any to store additional fields
  2. Added SetExtraFields() method to set extra fields with security note
  3. Added GetExtraFields() method to retrieve extra fields
  4. Added comprehensive test coverage for the new functionality
    This implementation allows users to:
  • Add experimental features before they are officially supported
  • Add custom fields for special use cases
  • Override existing fields when needed

Tests

Added TestChatCompletionRequestExtraFields that covers:

  • Setting extra fields with different value types (string, number, boolean)
  • Verifying field count and values
  • Testing field override functionality
    Additional context This enhancement provides flexibility for early adopters to use experimental features while maintaining backward compatibility. The implementation includes security considerations by warning users about trusted input data.

The feature is designed to be:

  • Non-breaking to existing code
  • Type-safe with Go's type system
  • Easy to use with clear method names
  • Well-documented with usage examples

@szyhf szyhf changed the title chat: 新增ExtraFields接口 chat: Add ExtraFields May 19, 2025
@szyhf szyhf changed the title chat: Add ExtraFields chat: Support ExtraFields May 19, 2025
Copy link
Owner

@meguminnnnnnnnn meguminnnnnnnnn left a comment

Choose a reason for hiding this comment

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

LGTM

@meguminnnnnnnnn meguminnnnnnnnn merged commit e202cd5 into meguminnnnnnnnn:master May 23, 2025
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.

2 participants