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

[OpenAI.Inference] Adding content filter support #24652

Merged
merged 15 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ model ChatChoice {
@projectedName("json", "delta")
@projectedName("csharp", "InternalStreamingDeltaMessage")
delta?: ChatMessage;

@doc("""
Information about the content filtering category (hate, sexual, violence, self_harm), if it
has been detected, as well as the severity level (very_low, low, medium, high-scale that
determines the intensity and risk level of harmful content) and if it has been filtered or not.
""")
@added(ServiceApiVersions.v2023_06_01_Preview)
@projectedName("json", "content_filter_results")
contentFilterResults?: ContentFilterResults;
trrwilson marked this conversation as resolved.
Show resolved Hide resolved
}

@doc("""
Expand Down Expand Up @@ -227,6 +236,14 @@ model ChatCompletions {
@projectedName("json", "choices")
choices: ChatChoice[];

@doc("""
Content filtering results for zero or more prompts in the request. In a streaming request,
results for different prompts may arrive at different times or in different orders.
""")
@added(ServiceApiVersions.v2023_06_01_Preview)
@projectedName("json", "prompt_annotations")
promptFilterResults?: PromptFilterResult[];

@doc("""
Usage information for tokens processed and generated as part of this completions operation.
""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,96 @@ enum CompletionsFinishReason {
@added(ServiceApiVersions.v2023_07_01_Preview)
functionCall: "function_call",
}

@added(ServiceApiVersions.v2023_06_01_Preview)
@doc("Ratings for the intensity and risk level of harmful content.")
enum ContentFilterSeverity {
@doc("""
Content may be related to violence, self-harm, sexual, or hate categories but the terms
are used in general, journalistic, scientific, medical, and similar professional contexts,
which are appropriate for most audiences.
""")
safe: "safe",

@doc("""
Content that expresses prejudiced, judgmental, or opinionated views, includes offensive
use of language, stereotyping, use cases exploring a fictional world (for example, gaming,
literature) and depictions at low intensity.
""")
low: "low",

@doc("""
Content that uses offensive, insulting, mocking, intimidating, or demeaning language
towards specific identity groups, includes depictions of seeking and executing harmful
instructions, fantasies, glorification, promotion of harm at medium intensity.
""")
medium: "medium",

@doc("""
Content that displays explicit and severe harmful instructions, actions,
damage, or abuse; includes endorsement, glorification, or promotion of severe
harmful acts, extreme or illegal forms of harm, radicalization, or non-consensual
power exchange or abuse.
""")
high: "high",
}

@added(ServiceApiVersions.v2023_06_01_Preview)
@doc("Information about filtered content severity level and if it has been filtered or not.")
model ContentFilterResult {
@doc("Ratings for the intensity and risk level of filtered content.")
@projectedName("json", "severity")
severity: ContentFilterSeverity;

@doc("A value indicating whether or not the content has been filtered.")
@projectedName("json", "filtered")
filtered: boolean;
}

@added(ServiceApiVersions.v2023_06_01_Preview)
@doc("Information about the content filtering category, if it has been detected.")
model ContentFilterResults {
@doc("""
Describes language related to anatomical organs and genitals, romantic relationships,
acts portrayed in erotic or affectionate terms, physical sexual acts, including
those portrayed as an assault or a forced sexual violent act against one’s will,
prostitution, pornography, and abuse.
""")
sexual: ContentFilterResult;

@doc("""
Describes language related to physical actions intended to hurt, injure, damage, or
kill someone or something; describes weapons, etc.
""")
violence: ContentFilterResult;

@doc("""
Describes language attacks or uses that include pejorative or discriminatory language
with reference to a person or identity group on the basis of certain differentiating
attributes of these groups including but not limited to race, ethnicity, nationality,
gender identity and expression, sexual orientation, religion, immigration status, ability
status, personal appearance, and body size.
""")
hate: ContentFilterResult;

@doc("""
Describes language related to physical actions intended to purposely hurt, injure,
or damage one’s body, or kill oneself.
""")
@projectedName("json", "self_harm")
selfHarm: ContentFilterResult;
}

@added(ServiceApiVersions.v2023_06_01_Preview)
@doc("""
Content filtering results for a single prompt in the request.
""")
model PromptFilterResult {
@doc("The index of this prompt in the set of prompt results")
@projectedName("json", "prompt_index")
promptIndex: int32;

@doc("Content filtering results for this prompt")
@projectedName("json", "content_filter_results")
contentFilterResults?: ContentFilterResults;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import "@typespec/rest";
import "@typespec/http";
import "@typespec/versioning";
import "./completions.common.tsp";

using TypeSpec.Rest;
using TypeSpec.Http;
using TypeSpec.Versioning;

namespace Azure.OpenAI;

Expand Down Expand Up @@ -159,6 +161,14 @@ model Completions {
@projectedName("csharp", "InternalCreatedSecondsAfterUnixEpoch")
created: int32;

@doc("""
Content filtering results for zero or more prompts in the request. In a streaming request,
results for different prompts may arrive at different times or in different orders.
""")
@added(ServiceApiVersions.v2023_06_01_Preview)
brandom-msft marked this conversation as resolved.
Show resolved Hide resolved
@projectedName("json", "prompt_annotations")
promptFilterResults?: PromptFilterResult[];
trrwilson marked this conversation as resolved.
Show resolved Hide resolved

@doc("""
The collection of completions choices associated with this completions response.
Generally, `n` choices are generated per provided prompt with a default value of 1.
Expand Down