Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove reduntant client type check#39

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gabor-openai merged 5 commits intomainfromdev/steven/moderation_fix
Nov 3, 2025

Conversation

@steven10a
Copy link
Collaborator

Removes unneeded check that the client is OpenAI. This is handled by directly trying the moderation endpoint, if it doesn't exist we create a fallback client

  • Fixes a potential bug that was identified in the TS version. Theisinstance check is fragile and if it fails to match will cause us to incorrectly setclient=None

CopilotAI review requested due to automatic review settingsNovember 3, 2025 17:38
Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR simplifies the client extraction logic in themoderation function by removing redundant type checking. The original code checked if the context'sguardrail_llm attribute was specifically anAsyncOpenAI instance before using it, but this check is unnecessary since the code later handles API incompatibilities gracefully.

  • Simplified client extraction from context by removing unnecessary type check
  • Reduced lines of code from 7 to 2 while maintaining the same functionality

💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.

Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.

Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.

Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/guardrails/checks/text/moderation.py:36

  • Missing import for syncOpenAI class. Line 190 usesisinstance(client, AsyncOpenAI) to detect async clients, implying sync clients are supported, but the syncOpenAI class is not imported. This will cause the code to work accidentally (since non-AsyncOpenAI clients will be treated as sync), but type checking will fail and the code is not explicit about its dependencies. AddOpenAI to the import:from openai import AsyncOpenAI, NotFoundError, OpenAI
from openai import AsyncOpenAI, NotFoundError

💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.

# Try the context client first, fall back if moderation endpoint doesn't exist
ifclientisnotNone:
# Determine if client is async or sync
is_async=isinstance(client,AsyncOpenAI)
Copy link

CopilotAINov 3, 2025

Choose a reason for hiding this comment

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

The client type detection assumes any non-AsyncOpenAI client is synchronous, which may not be accurate for Azure clients or other variants. Consider using a more explicit check likehasattr(client.moderations.create, '__call__') andnot inspect.iscoroutinefunction(client.moderations.create) similar to the pattern inllm_base.py (line 231), or import and check against specific sync client types (OpenAI,AzureOpenAI).

Copilot uses AI. Check for mistakes.
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

WAI. Only OpenAI clients are valid for moderation so we will catch the other types and fallback to generating an OAI client.

Copy link
Collaborator

@gabor-openaigabor-openai left a comment

Choose a reason for hiding this comment

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

TY

@gabor-openaigabor-openai merged commit66b40d0 intomainNov 3, 2025
9 checks passed
@gabor-openaigabor-openai deleted the dev/steven/moderation_fix branchNovember 3, 2025 22:32
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@gabor-openaigabor-openaigabor-openai approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@steven10a@gabor-openai

[8]ページ先頭

©2009-2025 Movatter.jp