Skip to content

Commit

Permalink
Add content filtering support (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcominerva authored Jul 21, 2023
2 parents d698b8f + 6442194 commit a5c9c83
Show file tree
Hide file tree
Showing 47 changed files with 756 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ await chatGptClient.AddFunctionResponseAsync(conversationId, functionCall.Name,

Check out the [Function calling sample](https://github.com/marcominerva/ChatGptNet/blob/master/samples/ChatGptFunctionCallingConsole/Application.cs#L18) for a complete implementation of this workflow.

## Content filtering

When using Azure OpenAI Service, we automatically get content filtering for free. For details about how it works, check out the [documentation](https://learn.microsoft.com/azure/ai-services/openai/concepts/content-filter). This information is returned for all scenarios when using API version `2023-06-01-preview` or later. **ChatGptNet** fully supports this object model by providing the corresponding properties in the [ChatGptResponse](https://github.com/marcominerva/ChatGptNet/blob/master/src/ChatGptNet/Models/ChatGptResponse.cs#L57) and [ChatGptChoice](https://github.com/marcominerva/ChatGptNet/blob/master/src/ChatGptNet/Models/ChatGptChoice.cs#L26) classes.

## Contribute

The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests on the repo and we'll address them as we can.
Expand Down
2 changes: 2 additions & 0 deletions docs/ChatGptNet.Models/ChatGptChoice.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ public class ChatGptChoice
| name | description |
| --- | --- |
| [ChatGptChoice](ChatGptChoice/ChatGptChoice.md)() | The default constructor. |
| [ContentFilterResults](ChatGptChoice/ContentFilterResults.md) { get; set; } | Gets or sets the content filter results for the this [`ChatGptChoice`](./ChatGptChoice.md). |
| [Delta](ChatGptChoice/Delta.md) { getset; } | When using streaming responses, gets or sets the partial message delta associated with this [`ChatGptChoice`](./ChatGptChoice.md). |
| [FinishReason](ChatGptChoice/FinishReason.md) { getset; } | Gets or sets a value specifying why the choice has been returned. |
| [Index](ChatGptChoice/Index.md) { getset; } | Gets or sets the index of the choice in the list. |
| [IsChoiceFiltered](ChatGptChoice/IsChoiceFiltered.md) { get; } | Gets or sets a value indicating whether the this [`ChatGptChoice`](./ChatGptChoice.md) has been filtered by content filtering system. |
| [IsFunctionCall](ChatGptChoice/IsFunctionCall.md) { get; } | Gets a value indicating whether this choice contains a function call. |
| [Message](ChatGptChoice/Message.md) { getset; } | Gets or sets the message associated with this [`ChatGptChoice`](./ChatGptChoice.md). |

Expand Down
15 changes: 15 additions & 0 deletions docs/ChatGptNet.Models/ChatGptChoice/ContentFilterResults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ChatGptChoice.ContentFilterResults property

Gets or sets the content filter results for the this [`ChatGptChoice`](../ChatGptChoice.md).

```csharp
public ChatGptContentFilterResults? ContentFilterResults { get; set; }
```

## See Also

* class [ChatGptContentFilterResults](../ChatGptContentFilterResults.md)
* class [ChatGptChoice](../ChatGptChoice.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
14 changes: 14 additions & 0 deletions docs/ChatGptNet.Models/ChatGptChoice/IsChoiceFiltered.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ChatGptChoice.IsChoiceFiltered property

Gets or sets a value indicating whether the this [`ChatGptChoice`](../ChatGptChoice.md) has been filtered by content filtering system.

```csharp
public bool IsChoiceFiltered { get; }
```

## See Also

* class [ChatGptChoice](../ChatGptChoice.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
26 changes: 26 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterResult.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ChatGptContentFilterResult class

Contains detail about a particular content filter result.

```csharp
public class ChatGptContentFilterResult
```

## Public Members

| name | description |
| --- | --- |
| [ChatGptContentFilterResult](ChatGptContentFilterResult/ChatGptContentFilterResult.md)() | The default constructor. |
| [Filtered](ChatGptContentFilterResult/Filtered.md) { get; set; } | Gets or sets a value indicating whether the content has been filtered. |
| [Severity](ChatGptContentFilterResult/Severity.md) { getset; } | Gets or sets the severity levels of the content. |

## Remarks

See [Content filtering](https://learn.microsoft.com/azure/ai-services/openai/concepts/content-filter) for more information.
## See Also

* namespace [ChatGptNet.Models](../ChatGptNet.md)
* [ChatGptContentFilterResult.cs](https://github.com/marcominerva/ChatGptNet/tree/master/src/ChatGptNet/Models/ChatGptContentFilterResult.cs)
<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ChatGptContentFilterResult constructor

The default constructor.

```csharp
public ChatGptContentFilterResult()
```

## See Also

* class [ChatGptContentFilterResult](../ChatGptContentFilterResult.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
14 changes: 14 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterResult/Filtered.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ChatGptContentFilterResult.Filtered property

Gets or sets a value indicating whether the content has been filtered.

```csharp
public bool Filtered { get; set; }
```

## See Also

* class [ChatGptContentFilterResult](../ChatGptContentFilterResult.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
24 changes: 24 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterResult/Severity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ChatGptContentFilterResult.Severity property

Gets or sets the severity levels of the content.

```csharp
public string Severity { get; set; }
```

## Remarks

Currently supported severity levels are:

* **Safe** – 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.
* **Low** – 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.
* **Medium** – 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.
* **High** – 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.

## See Also

* class [ChatGptContentFilterSeverityLevels](../ChatGptContentFilterSeverityLevels.md)
* class [ChatGptContentFilterResult](../ChatGptContentFilterResult.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
28 changes: 28 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterResults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ChatGptContentFilterResults class

Contains details about conteng filtering results.

```csharp
public class ChatGptContentFilterResults
```

## Public Members

| name | description |
| --- | --- |
| [ChatGptContentFilterResults](ChatGptContentFilterResults/ChatGptContentFilterResults.md)() | The default constructor. |
| [Hate](ChatGptContentFilterResults/Hate.md) { get; set; } | Gets of sets information about the hate content filter. |
| [SelfHarm](ChatGptContentFilterResults/SelfHarm.md) { getset; } | Gets of sets information about the self-harm content filter. |
| [Sexual](ChatGptContentFilterResults/Sexual.md) { getset; } | Gets of sets information about the sexual content filter. |
| [Violence](ChatGptContentFilterResults/Violence.md) { getset; } | Gets or sets information about the violence content filter. |

## Remarks

See [Content filtering](https://learn.microsoft.com/azure/ai-services/openai/concepts/content-filter) for more information.
## See Also

* namespace [ChatGptNet.Models](../ChatGptNet.md)
* [ChatGptContentFilterResults.cs](https://github.com/marcominerva/ChatGptNet/tree/master/src/ChatGptNet/Models/ChatGptContentFilterResults.cs)
<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ChatGptContentFilterResults constructor

The default constructor.

```csharp
public ChatGptContentFilterResults()
```

## See Also

* class [ChatGptContentFilterResults](../ChatGptContentFilterResults.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
19 changes: 19 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterResults/Hate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ChatGptContentFilterResults.Hate property

Gets of sets information about the hate content filter.

```csharp
public ChatGptContentFilterResult Hate { get; set; }
```

## Remarks

The hate category 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.

## See Also

* class [ChatGptContentFilterResult](../ChatGptContentFilterResult.md)
* class [ChatGptContentFilterResults](../ChatGptContentFilterResults.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
19 changes: 19 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterResults/SelfHarm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ChatGptContentFilterResults.SelfHarm property

Gets of sets information about the self-harm content filter.

```csharp
public ChatGptContentFilterResult SelfHarm { get; set; }
```

## Remarks

The self-harm category describes language related to physical actions intended to purposely hurt, injure, or damage one’s body, or kill oneself.

## See Also

* class [ChatGptContentFilterResult](../ChatGptContentFilterResult.md)
* class [ChatGptContentFilterResults](../ChatGptContentFilterResults.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
19 changes: 19 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterResults/Sexual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ChatGptContentFilterResults.Sexual property

Gets of sets information about the sexual content filter.

```csharp
public ChatGptContentFilterResult Sexual { get; set; }
```

## Remarks

The sexual category 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.

## See Also

* class [ChatGptContentFilterResult](../ChatGptContentFilterResult.md)
* class [ChatGptContentFilterResults](../ChatGptContentFilterResults.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
19 changes: 19 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterResults/Violence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ChatGptContentFilterResults.Violence property

Gets or sets information about the violence content filter.

```csharp
public ChatGptContentFilterResult Violence { get; set; }
```

## Remarks

The sexual category 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.

## See Also

* class [ChatGptContentFilterResult](../ChatGptContentFilterResult.md)
* class [ChatGptContentFilterResults](../ChatGptContentFilterResults.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
27 changes: 27 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterSeverityLevels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ChatGptContentFilterSeverityLevels class

Contains all the content filter severity levels defined by Azure OpenAI Service.

```csharp
public static class ChatGptContentFilterSeverityLevels
```

## Public Members

| name | description |
| --- | --- |
| const [High](ChatGptContentFilterSeverityLevels/High.md) | 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. |
| const [Low](ChatGptContentFilterSeverityLevels/Low.md) | 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. |
| const [Medium](ChatGptContentFilterSeverityLevels/Medium.md) | 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. |
| const [Safe](ChatGptContentFilterSeverityLevels/Safe.md) | 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. |

## Remarks

See [Content filtering](https://learn.microsoft.com/azure/ai-services/openai/concepts/content-filter#severity-levels) for more information.
## See Also

* namespace [ChatGptNet.Models](../ChatGptNet.md)
* [ChatGptContentFilterSeverityLevels.cs](https://github.com/marcominerva/ChatGptNet/tree/master/src/ChatGptNet/Models/ChatGptContentFilterSeverityLevels.cs)
<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
14 changes: 14 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterSeverityLevels/High.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ChatGptContentFilterSeverityLevels.High field

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.

```csharp
public const string High;
```

## See Also

* class [ChatGptContentFilterSeverityLevels](../ChatGptContentFilterSeverityLevels.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
14 changes: 14 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterSeverityLevels/Low.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ChatGptContentFilterSeverityLevels.Low field

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.

```csharp
public const string Low;
```

## See Also

* class [ChatGptContentFilterSeverityLevels](../ChatGptContentFilterSeverityLevels.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ChatGptContentFilterSeverityLevels.Medium field

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.

```csharp
public const string Medium;
```

## See Also

* class [ChatGptContentFilterSeverityLevels](../ChatGptContentFilterSeverityLevels.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
14 changes: 14 additions & 0 deletions docs/ChatGptNet.Models/ChatGptContentFilterSeverityLevels/Safe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ChatGptContentFilterSeverityLevels.Safe field

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.

```csharp
public const string Safe;
```

## See Also

* class [ChatGptContentFilterSeverityLevels](../ChatGptContentFilterSeverityLevels.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
2 changes: 2 additions & 0 deletions docs/ChatGptNet.Models/ChatGptError.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ public class ChatGptError
| --- | --- |
| [ChatGptError](ChatGptError/ChatGptError.md)() | The default constructor. |
| [Code](ChatGptError/Code.md) { get; set; } | Gets or sets the error code. |
| [InnerError](ChatGptError/InnerError.md) { getset; } | Contains further details about the error. |
| [Message](ChatGptError/Message.md) { getset; } | Gets or sets the error message. |
| [Parameter](ChatGptError/Parameter.md) { getset; } | Gets or sets the parameter that caused the error. |
| [StatusCode](ChatGptError/StatusCode.md) { getset; } | Gets or sets the HTTP status code of the error. |
| [Type](ChatGptError/Type.md) { getset; } | Gets or sets the error type. |

## Remarks
Expand Down
15 changes: 15 additions & 0 deletions docs/ChatGptNet.Models/ChatGptError/InnerError.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ChatGptError.InnerError property

Contains further details about the error.

```csharp
public ChatGptInnerError? InnerError { get; set; }
```

## See Also

* class [ChatGptInnerError](../ChatGptInnerError.md)
* class [ChatGptError](../ChatGptError.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
14 changes: 14 additions & 0 deletions docs/ChatGptNet.Models/ChatGptError/StatusCode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ChatGptError.StatusCode property

Gets or sets the HTTP status code of the error.

```csharp
public int StatusCode { get; set; }
```

## See Also

* class [ChatGptError](../ChatGptError.md)
* namespace [ChatGptNet.Models](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
Loading

0 comments on commit a5c9c83

Please sign in to comment.