Skip to content

Update openai_classifier.py to add a client option#362

Open
ycysuk wants to merge 1 commit into2FastLabs:mainfrom
ycysuk:patch-1
Open

Update openai_classifier.py to add a client option#362
ycysuk wants to merge 1 commit into2FastLabs:mainfrom
ycysuk:patch-1

Conversation

@ycysuk
Copy link
Copy Markdown

@ycysuk ycysuk commented Jul 22, 2025

Feature request: add openai compatiable API to OpenAIClassifier

Fixes #361

Summary

Changes

Add a client option to pass by a openai compatiable API, same as OpenAIAgent

class OpenAIClassifierOptions:
    def __init__(self,
                 api_key: str,
                 model_id: Optional[str] = None,
                 inference_config: Optional[Dict[str, Any]] = None,
                 client: Optional[Any] = None):
        self.api_key = api_key
        self.model_id = model_id
        self.inference_config = inference_config or {}
        self.client = client

class OpenAIClassifier(Classifier):
    def __init__(self, options: OpenAIClassifierOptions):
        ...
        if options.client:
            self.client = options.client
        else:
            self.client = OpenAI(api_key=options.api_key)
        ...

User experience

client = OpenAI(api_key='your api key', base_url='openai compatiable api')
classifier=OpenAIClassifier(OpenAIClassifierOptions(
            api_key=api_key,
            model_id='your model id',
            client=client))

Checklist

If your change doesn't seem to apply, please leave them unchecked.

  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented
  • I have linked this PR to an existing issue (required)
Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

Add `client` option to pass by a openai compatiable API, same as `OpenAIAgent`
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.

Feature request: add openai compatiable API to OpenAIClassifier

1 participant