diff --git a/.github/workflows/chron-models.yaml b/.github/workflows/chron-models.yaml
index 50e992a..c60fa1a 100644
--- a/.github/workflows/chron-models.yaml
+++ b/.github/workflows/chron-models.yaml
@@ -49,7 +49,7 @@ jobs:
git commit -m "Update Go modules, Go workspace, and docs" || echo "No changes to commit"
# Step 8: Push changes back to the repository
- - name: Push changes
- uses: ad-m/github-push-action@v1
+ - name: Push changes to repository
+ uses: stefanzweifel/git-auto-commit-action@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
diff --git a/README.md b/README.md
index 6ccb0a3..da7565f 100644
--- a/README.md
+++ b/README.md
@@ -214,32 +214,47 @@ 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)
@@ -255,10 +270,15 @@ var (
// - 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.
@@ -739,7 +759,7 @@ CreateTranslation calls the translations endpoint with the given request.
Returns the translated text in the response\_format specified in the request.
-### func \(\*Client\) [Moderate]()
+### func \(\*Client\) [Moderate]()
```go
func (c *Client) Moderate(ctx context.Context, request ModerationRequest) (response Moderation, err error)
@@ -1183,7 +1203,7 @@ type Model string
```
-## type [Moderation]()
+## type [Moderation]()
Moderation represents one of possible moderation results.
@@ -1195,7 +1215,7 @@ type Moderation struct {
```
-## type [ModerationRequest]()
+## type [ModerationRequest]()
ModerationRequest represents a request structure for moderation API.
diff --git a/audio.go b/audio.go
index 0f22697..3bbbbcf 100644
--- a/audio.go
+++ b/audio.go
@@ -30,7 +30,7 @@ type AudioResponse struct {
Words Words `json:"words"` // Words is the words of the response.
Text string `json:"text"` // Text is the text of the response.
- http.Header // Header is the header of the response.
+ Header http.Header // Header is the header of the response.
}
// Words is the words of the response.
@@ -60,7 +60,8 @@ func (r *AudioResponse) SetHeader(header http.Header) {
r.Header = header
}
-// audioTextResponse is the response structure for the audio API when the response format is text.
+// audioTextResponse is the response structure for the audio API when the
+// response format is text.
type audioTextResponse struct {
Text string `json:"text"` // Text is the text of the response.
header http.Header // Header is the header of the response.
@@ -99,6 +100,9 @@ func (c *Client) CreateTranslation(
return c.callAudioAPI(ctx, request, translationsSuffix)
}
+// callAudioAPI calls the audio API with the given request.
+//
+// Currently supports both the transcription and translation APIs.
func (c *Client) callAudioAPI(
ctx context.Context,
request AudioRequest,
@@ -192,7 +196,8 @@ func audioMultipartForm(request AudioRequest, b formBuilder) error {
return b.Close()
}
-// createFileField creates the "file" form field from either an existing file or by using the reader.
+// createFileField creates the "file" form field from either an existing file
+// or by using the reader.
func createFileField(
request AudioRequest,
b formBuilder,
diff --git a/audio_test.go b/audio_test.go
index 0084329..9789b69 100644
--- a/audio_test.go
+++ b/audio_test.go
@@ -88,18 +88,15 @@ func TestCreateFileField(t *testing.T) {
defer cleanup()
path := filepath.Join(dir, "fake.mp3")
test.CreateTestFile(t, path)
-
req := AudioRequest{
FilePath: path,
}
-
mockFailedErr := fmt.Errorf("mock form builder fail")
mockBuilder := &mockFormBuilder{
mockCreateFormFile: func(string, *os.File) error {
return mockFailedErr
},
}
-
err := createFileField(req, mockBuilder)
a.ErrorIs(
err,
diff --git a/cmd/models/main.go b/cmd/models/main.go
index 4f08d6c..6d4e029 100644
--- a/cmd/models/main.go
+++ b/cmd/models/main.go
@@ -17,6 +17,10 @@ import (
"github.com/samber/lo"
)
+const (
+ outputFile = "models.go"
+)
+
//go:embed models.go.txt
var outputFileTemplate string
@@ -24,28 +28,6 @@ type templateParams struct {
Models []ResponseModel `json:"models"`
}
-const (
- outputFile = "models.go"
- outputFileHeader = `
-// Code generated by github.com/conneroisu/groq-go/scripts/models/main.go DO NOT EDIT.
-
-package groq
-
-`
- modelsInitURL = "https://console.groq.com/docs/models"
-)
-
-// each model~:
-//
-// Distil-Whisper English
-//
-// Model ID: distil-whisper-large-v3-en
-// Developer: HuggingFace
-// Max File Size: 25 MB
-// [ Model Card ](https://huggingface.co/distil-whisper-large-v3-en)
-//
-// Need to then go to the huggingface page and take the first tag Text-Generation (Llama) or Automatic-Speech-Recognition (Whisper).
-
// main is the entry point for the application.
func main() {
ctx := context.Background()
@@ -158,6 +140,8 @@ func fillTemplate(w io.Writer, models []ResponseModel) error {
// if the id of the model is llama-guard-3-8b
return model.ID == "llama-guard-3-8b"
},
+ // getCurrentDate returns the current date in the format
+ // "2006-01-02 15:04:05".
"getCurrentDate": func() string {
return time.Now().Format("2006-01-02 15:04:05")
},
@@ -176,7 +160,7 @@ func fillTemplate(w io.Writer, models []ResponseModel) error {
}
func nameModels(models []ResponseModel) {
- for i, _ := range models {
+ for i := range models {
if (models)[i].Name == "" {
models[i].Name = lo.PascalCase(models[i].ID)
}
diff --git a/moderation.go b/moderation.go
index efa8a11..564ae04 100644
--- a/moderation.go
+++ b/moderation.go
@@ -55,32 +55,48 @@ 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)
@@ -88,18 +104,27 @@ var (
// - 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.
diff --git a/scripts/makefile/install.sh b/scripts/makefile/install.sh
index bd8742f..eedd9a6 100644
--- a/scripts/makefile/install.sh
+++ b/scripts/makefile/install.sh
@@ -11,19 +11,3 @@ command -v go >/dev/null 2>&1 || brew install go
# Check if the command, gum, exists, if not install it
command -v gum >/dev/null 2>&1 || go install github.com/charmbracelet/gum@latest
-
-# Check if the command, protoc, exists, if not install it
-gum spin --spinner dot --title "Installing Protoc" --show-output -- \
- command -v protoc >/dev/null 2>&1 || go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
-
-# Check if the command, sqlite3, exists, if not install it
-gum spin --spinner dot --title "Installing SQLite3" --show-output -- \
- command -v sqlite3 >/dev/null 2>&1 || brew install sqlite
-
-# Check if the command, sqldiff, exists, if not install it
-gum spin --spinner dot --title "Installing SQLDiff" --show-output -- \
- command -v sqldiff >/dev/null 2>&1 || brew install sqldiff
-
-# Check if the command, sqlc, exists, if not install it
-gum spin --spinner dot --title "Installing SQLC" --show-output -- \
- command -v sqlc >/dev/null 2>&1 || brew install sqlc
diff --git a/scripts/taskfile/install.sh b/scripts/taskfile/install.sh
index 3e8cd4d..8b6c1f7 100644
--- a/scripts/taskfile/install.sh
+++ b/scripts/taskfile/install.sh
@@ -11,19 +11,3 @@ command -v go >/dev/null 2>&1 || brew install go
# Check if the command, gum, exists, if not install it
command -v gum >/dev/null 2>&1 || go install github.com/charmbracelet/gum@latest
-
-# Check if the command, protoc, exists, if not install it
-gum spin --spinner dot --title "Installing Protoc" --show-output -- \
- command -v protoc >/dev/null 2>&1 || go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
-
-# Check if the command, sqlite3, exists, if not install it
-gum spin --spinner dot --title "Installing SQLite3" --show-output -- \
- command -v sqlite3 >/dev/null 2>&1 || brew install sqlite
-
-# Check if the command, sqldiff, exists, if not install it
-gum spin --spinner dot --title "Installing SQLDiff" --show-output -- \
- command -v sqldiff >/dev/null 2>&1 || brew install sqldiff
-
-# Check if the command, sqlc, exists, if not install it
-gum spin --spinner dot --title "Installing SQLC" --show-output -- \
- command -v sqlc >/dev/null 2>&1 || brew install sqlc
diff --git a/stream.go b/stream.go
index 4eb2721..6214322 100644
--- a/stream.go
+++ b/stream.go
@@ -86,13 +86,14 @@ func (stream *streamReader[T]) processLines() (T, error) {
hasErrorPrefix bool
)
for {
- rawLine, readErr := stream.reader.ReadBytes('\n')
- if readErr != nil || hasErrorPrefix {
+ rawLine, err := stream.reader.ReadBytes('\n')
+ if err != nil || hasErrorPrefix {
respErr := stream.unmarshalError()
if respErr != nil {
- return *new(T), fmt.Errorf("error, %w", respErr.Error)
+ return *new(T),
+ fmt.Errorf("error, %w", respErr.Error)
}
- return *new(T), readErr
+ return *new(T), err
}
noSpaceLine := bytes.TrimSpace(rawLine)
if bytes.HasPrefix(noSpaceLine, errorPrefix) {
@@ -102,9 +103,9 @@ func (stream *streamReader[T]) processLines() (T, error) {
if hasErrorPrefix {
noSpaceLine = bytes.TrimPrefix(noSpaceLine, headerData)
}
- writeErr := stream.errAccumulator.Write(noSpaceLine)
- if writeErr != nil {
- return *new(T), writeErr
+ err := stream.errAccumulator.Write(noSpaceLine)
+ if err != nil {
+ return *new(T), err
}
emptyMessagesCount++
if emptyMessagesCount > stream.emptyMessagesLimit {