Skip to content

Commit

Permalink
added some useful comments to moderation.go
Browse files Browse the repository at this point in the history
  • Loading branch information
conneroisu committed Sep 6, 2024
1 parent 95822fd commit 4a54ec1
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 82 deletions.
109 changes: 53 additions & 56 deletions models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 53 additions & 1 deletion moderation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"strings"
)

// HarmfulCategory is the category of the harmful content.
// HarmfulCategory is a category of harmful content.
//
// [Llama Guard 3](https://llama.meta.com/docs/model-cards-and-prompt-formats/llama-guard-3/)
//
// Llama Guard 3 provides content safety support for the following languages: English, French, German, Hindi, Italian, Portuguese, Spanish, and Thai.
//
Expand Down Expand Up @@ -51,6 +53,56 @@ const (

var (
// SectionMap is a map of sections to categories.
//
// S1: Violent Crimes.
// AI models should not create content that enables, encourages, or excuses the commission of violent crimes. Examples of violent crimes include, but are not limited to:
// - Unlawful violence toward people (ex: terrorism, genocide, murder, hate crimes, child abuse, assault, battery, kidnapping)
// - Unlawful violence toward animals (ex: animal abuse)
// S2: Non-Violent Crimes.
// AI models should not create content that enables, encourages, or excuses the commission of non-violent crimes. Examples of non-violent crimes include, but are not limited to:
// - Financial crimes (ex: fraud, scams, money laundering)
// - Property crimes (ex: burglary, robbery, arson, vandalism)
// - Drug crimes (ex: creating or trafficking narcotics)
// - Weapons crimes (ex: producing unlicensed firearms)
// - Cyber crimes (ex: hacking, spyware, malware)
// S3: Sex Crimes.
// AI models should not create content that enables, encourages, or excuses the commission of sex crimes. Examples of sex crimes include, but are not limited to:
// - Human trafficking
// - Sexual assault (ex: rape)
// - Sexual harassment (ex: groping)
// - Lewd conduct
// S4: Child Exploitation.
// AI models should not create content that depicts child nudity or that enables, encourages, excuses, or depicts the sexual abuse of children.
// S5: Defamation.
// AI models should not create content about a real, living person that is verifiably false and likely to injure the person's reputation.
// S6: Specialized Advice.
// AI models should not create content that contains specialized financial, medical, or legal advice.
// S7: Privacy.
// AI models should not create content that contains sensitive, personal information about private individuals.
// S8: Intellectual Property.
// AI models should not create content that violates the intellectual property rights of third parties.
// S9: Indiscriminate Weapons.
// I models should not create content that enables the creation of weapons of mass destruction. Examples of such weapons include, but are not limited to:
// - Chemical weapons (ex: nerve gas)
// - Biological weapons (ex: anthrax)
// - Radiological weapons (ex: salted bombs)
// - Nuclear weapons (ex: atomic warheads)
// - High-yield explosive weapons (ex: cluster munitions)
// S10: Hate.
// AI models should not create content that is hateful toward people on the basis of their protected characteristics (race, color, ethnicity, national origin, disability, religious affiliation, caste, sexual orientation, sex, gender identity and serious disease). AI models should not create content that perpetuates negative stereotypes.
// S11: Self-Harm.
// AI models should not create content that enables, encourages, or excuses acts of intentional self-harm. Examples of such actions include, but are not limited to:
// - Suicide
// - Self-injury (ex: cutting)
// - Disordered eating
// S12: Sexual Content.
// AI models should not create depictions of nude adults or content that contains erotic descriptions or explicit depictions of sex acts.
// S13: Elections.
// AI models should not create content that contain factually incorrect information about electoral systems and processes, including in the time, place, or manner of voting in civic elections.
// S14: Code Interpreter Abuse.
// AI models should not create content that attempts to abuse code interpreters. Examples of code interpreter abuse include, but are not limited to:
// - Denial of service attacks
// - Container escapes or privilege escalation.
SectionMap = map[string]HarmfulCategory{
"S1": CategoryViolentCrimes,
"S2": CategoryNonviolentCrimes,
Expand Down
46 changes: 21 additions & 25 deletions scripts/models/models.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ type Endpoint string
// string
type Model string

// AudioResponseFormat is the response format for the audio API.
//
// Response formatted using AudioResponseFormatJSON by default.
//
// string
type AudioResponseFormat string

// TranscriptionTimestampGranularity is the timestamp granularity for the transcription.
//
// string
type TranscriptionTimestampGranularity string

const (
completionsSuffix Endpoint = "/completions"
chatCompletionsSuffix Endpoint = "/chat/completions"
Expand All @@ -20,6 +32,15 @@ const (
embeddingsSuffix Endpoint = "/embeddings"
moderationsSuffix Endpoint = "/moderations"

AudioResponseFormatJSON AudioResponseFormat = "json" // AudioResponseFormatJSON is the JSON format of some audio.
AudioResponseFormatText AudioResponseFormat = "text" // AudioResponseFormatText is the text format of some audio.
AudioResponseFormatSRT AudioResponseFormat = "srt" // AudioResponseFormatSRT is the SRT format of some audio.
AudioResponseFormatVerboseJSON AudioResponseFormat = "verbose_json" // AudioResponseFormatVerboseJSON is the verbose JSON format of some audio.
AudioResponseFormatVTT AudioResponseFormat = "vtt" // AudioResponseFormatVTT is the VTT format of some audio.

TranscriptionTimestampGranularityWord TranscriptionTimestampGranularity = "word" // TranscriptionTimestampGranularityWord is the word timestamp granularity.
TranscriptionTimestampGranularitySegment TranscriptionTimestampGranularity = "segment" // TranscriptionTimestampGranularitySegment is the segment timestamp granularity.

{{- range $model := .Models }}
// {{ $model.Name }} is an AI {{if isTextModel $model}}text{{else}}audio{{end}} model provided by {{$model.OwnedBy}}. It has {{$model.ContextWindow}} context window.
{{ $model.Name }} Model = "{{ $model.ID }}" {{- end }}
Expand Down Expand Up @@ -51,28 +72,3 @@ var disabledModelsForEndpoints = map[Endpoint]map[Model]bool{
func endpointSupportsModel(endpoint Endpoint, model Model) bool {
return !disabledModelsForEndpoints[endpoint][model]
}


// Whisper Defines the models provided by OpenAI to use when processing audio with OpenAI.
const (
AudioResponseFormatJSON AudioResponseFormat = "json" // AudioResponseFormatJSON is the JSON format of some audio.
AudioResponseFormatText AudioResponseFormat = "text" // AudioResponseFormatText is the text format of some audio.
AudioResponseFormatSRT AudioResponseFormat = "srt" // AudioResponseFormatSRT is the SRT format of some audio.
AudioResponseFormatVerboseJSON AudioResponseFormat = "verbose_json" // AudioResponseFormatVerboseJSON is the verbose JSON format of some audio.
AudioResponseFormatVTT AudioResponseFormat = "vtt" // AudioResponseFormatVTT is the VTT format of some audio.

TranscriptionTimestampGranularityWord TranscriptionTimestampGranularity = "word" // TranscriptionTimestampGranularityWord is the word timestamp granularity.
TranscriptionTimestampGranularitySegment TranscriptionTimestampGranularity = "segment" // TranscriptionTimestampGranularitySegment is the segment timestamp granularity.
)

// AudioResponseFormat is the response format for the audio API.
//
// Response formats; Whisper uses AudioResponseFormatJSON by default.
//
// string
type AudioResponseFormat string

// TranscriptionTimestampGranularity is the timestamp granularity for the transcription.
//
// string
type TranscriptionTimestampGranularity string

0 comments on commit 4a54ec1

Please sign in to comment.