-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for Azure Content Filter Response
- Loading branch information
Showing
15 changed files
with
462 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
openai-core/src/commonMain/kotlin/com.aallam.openai.azure.api/chat/ChatFinishDetails.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.aallam.openai.azure.api.chat | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* An abstract representation of structured information about why a chat completions response terminated. | ||
*/ | ||
@Serializable | ||
public sealed class ChatFinishDetails { | ||
|
||
/** | ||
* Represents the "stop" type of ChatFinishDetails. | ||
*/ | ||
@Serializable | ||
@SerialName("stop") | ||
public data class StopFinishDetails( | ||
|
||
/** | ||
* The token sequence that the model terminated with. | ||
*/ | ||
@SerialName("stop") | ||
val stop: String | ||
) : ChatFinishDetails() | ||
|
||
/** | ||
* A structured representation of a stop reason that signifies a token limit was reached before the model could | ||
* naturally complete. | ||
*/ | ||
@Serializable | ||
@SerialName("max_tokens") | ||
public class MaxTokensFinishDetails : ChatFinishDetails() | ||
} |
41 changes: 41 additions & 0 deletions
41
openai-core/src/commonMain/kotlin/com.aallam.openai.azure.api/core/ResponseError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.aallam.openai.azure.api.core | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerialName | ||
|
||
/** | ||
* This class represents the error details of an HTTP response. | ||
*/ | ||
@Serializable | ||
public data class ResponseError( | ||
|
||
/** | ||
* The error code of this error. | ||
*/ | ||
@SerialName("code") | ||
val code: String, | ||
|
||
/** | ||
* The error message of this error. | ||
*/ | ||
@SerialName("message") | ||
val message: String, | ||
|
||
/** | ||
* The target of this error. | ||
*/ | ||
@SerialName("target") | ||
val target: String? = null, | ||
|
||
/** | ||
* The inner error information for this error. | ||
*/ | ||
@SerialName("innererror") | ||
val innerError: ResponseInnerError? = null, | ||
|
||
/** | ||
* A list of details about specific errors that led to this reported error. | ||
*/ | ||
@SerialName("details") | ||
val errorDetails: List<ResponseError>? = null | ||
) |
24 changes: 24 additions & 0 deletions
24
openai-core/src/commonMain/kotlin/com.aallam.openai.azure.api/core/ResponseInnerError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.aallam.openai.azure.api.core | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerialName | ||
|
||
|
||
/** | ||
* The inner error of a ResponseError. | ||
*/ | ||
@Serializable | ||
public data class ResponseInnerError( | ||
|
||
/** | ||
* The error code of the inner error. | ||
*/ | ||
@SerialName("code") | ||
val code: String? = null, | ||
|
||
/** | ||
* The nested inner error for this error. | ||
*/ | ||
@SerialName("innererror") | ||
val innerError: ResponseInnerError? = null | ||
) |
24 changes: 24 additions & 0 deletions
24
...commonMain/kotlin/com.aallam.openai.azure.api/filtering/ContentFilterBlocklistIdResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.aallam.openai.azure.api.filtering | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerialName | ||
|
||
|
||
/** | ||
* Represents the outcome of an evaluation against a custom blocklist as performed by content filtering. | ||
*/ | ||
@Serializable | ||
public data class ContentFilterBlocklistIdResult( | ||
|
||
/** | ||
* The ID of the custom blocklist evaluated. | ||
*/ | ||
@SerialName("id") | ||
val id: String, | ||
|
||
/** | ||
* A value indicating whether the content has been filtered. | ||
*/ | ||
@SerialName("filtered") | ||
val filtered: Boolean | ||
) |
35 changes: 35 additions & 0 deletions
35
...monMain/kotlin/com.aallam.openai.azure.api/filtering/ContentFilterCitedDetectionResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.aallam.openai.azure.api.filtering | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Represents the outcome of a detection operation against protected resources as performed by content filtering. | ||
*/ | ||
@Serializable | ||
public data class ContentFilterCitedDetectionResult( | ||
|
||
/** | ||
* A value indicating whether or not the content has been filtered. | ||
*/ | ||
@SerialName("filtered") | ||
val filtered: Boolean, | ||
|
||
/** | ||
* A value indicating whether detection occurred, irrespective of severity or whether the content was filtered. | ||
*/ | ||
@SerialName("detected") | ||
val detected: Boolean, | ||
|
||
/** | ||
* The internet location associated with the detection. | ||
*/ | ||
@SerialName("URL") | ||
val url: String, | ||
|
||
/** | ||
* The license description associated with the detection. | ||
*/ | ||
@SerialName("license") | ||
val license: String | ||
) |
23 changes: 23 additions & 0 deletions
23
...c/commonMain/kotlin/com.aallam.openai.azure.api/filtering/ContentFilterDetectionResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.aallam.openai.azure.api.filtering | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerialName | ||
|
||
/** | ||
* Represents the outcome of a detection operation performed by content filtering. | ||
*/ | ||
@Serializable | ||
public data class ContentFilterDetectionResult( | ||
|
||
/** | ||
* A value indicating whether the content has been filtered. | ||
*/ | ||
@SerialName("filtered") | ||
val filtered: Boolean, | ||
|
||
/** | ||
* A value indicating whether detection occurred, irrespective of severity or whether the content was filtered. | ||
*/ | ||
@SerialName("detected") | ||
val detected: Boolean | ||
) |
23 changes: 23 additions & 0 deletions
23
...i-core/src/commonMain/kotlin/com.aallam.openai.azure.api/filtering/ContentFilterResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.aallam.openai.azure.api.filtering | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Information about filtered content severity level and if it has been filtered or not. | ||
*/ | ||
@Serializable | ||
public data class ContentFilterResult( | ||
|
||
/** | ||
* Ratings for the intensity and risk level of filtered content. | ||
*/ | ||
@SerialName("severity") | ||
val severity: ContentFilterSeverity, | ||
|
||
/** | ||
* A value indicating whether the content has been filtered. | ||
*/ | ||
@SerialName("filtered") | ||
val filtered: Boolean | ||
) |
70 changes: 70 additions & 0 deletions
70
...nMain/kotlin/com.aallam.openai.azure.api/filtering/ContentFilterResultDetailsForPrompt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.aallam.openai.azure.api.filtering | ||
|
||
import com.aallam.openai.azure.api.core.ResponseError | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Information about content filtering evaluated against input data to Azure OpenAI. | ||
*/ | ||
@Serializable | ||
public data class ContentFilterResultDetailsForPrompt( | ||
|
||
/** | ||
* 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. | ||
*/ | ||
@SerialName("sexual") | ||
val sexual: ContentFilterResult? = null, | ||
|
||
/** | ||
* Describes language related to physical actions intended to hurt, injure, damage, or | ||
* kill someone or something; describes weapons, etc. | ||
*/ | ||
@SerialName("violence") | ||
val violence: ContentFilterResult? = null, | ||
|
||
/** | ||
* 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. | ||
*/ | ||
@SerialName("hate") | ||
val hate: ContentFilterResult? = null, | ||
|
||
/** | ||
* Describes language related to physical actions intended to purposely hurt, injure, | ||
* or damage one’s body, or kill oneself. | ||
*/ | ||
@SerialName("self_harm") | ||
val selfHarm: ContentFilterResult? = null, | ||
|
||
/** | ||
* Describes whether profanity was detected. | ||
*/ | ||
@SerialName("profanity") | ||
val profanity: ContentFilterDetectionResult? = null, | ||
|
||
/** | ||
* Describes detection results against configured custom blocklists. | ||
*/ | ||
@SerialName("custom_blocklists") | ||
val customBlocklists: List<ContentFilterBlocklistIdResult>? = null, | ||
|
||
/** | ||
* Describes an error returned if the content filtering system is | ||
* down or otherwise unable to complete the operation in time. | ||
*/ | ||
@SerialName("error") | ||
val error: ResponseError? = null, | ||
|
||
/** | ||
* Whether a jailbreak attempt was detected in the prompt. | ||
*/ | ||
@SerialName("jailbreak") | ||
val jailbreak: ContentFilterDetectionResult? = null | ||
) |
Oops, something went wrong.