mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал packages.jpg
This commit is contained in:
21
vendor/github.com/sashabaranov/go-openai/moderation.go
generated
vendored
21
vendor/github.com/sashabaranov/go-openai/moderation.go
generated
vendored
@@ -2,6 +2,7 @@ package openai
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -15,9 +16,19 @@ import (
|
||||
const (
|
||||
ModerationTextStable = "text-moderation-stable"
|
||||
ModerationTextLatest = "text-moderation-latest"
|
||||
ModerationText001 = "text-moderation-001"
|
||||
// Deprecated: use ModerationTextStable and ModerationTextLatest instead.
|
||||
ModerationText001 = "text-moderation-001"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrModerationInvalidModel = errors.New("this model is not supported with moderation, please use text-moderation-stable or text-moderation-latest instead") //nolint:lll
|
||||
)
|
||||
|
||||
var validModerationModel = map[string]struct{}{
|
||||
ModerationTextStable: {},
|
||||
ModerationTextLatest: {},
|
||||
}
|
||||
|
||||
// ModerationRequest represents a request structure for moderation API.
|
||||
type ModerationRequest struct {
|
||||
Input string `json:"input,omitempty"`
|
||||
@@ -58,12 +69,18 @@ type ModerationResponse struct {
|
||||
ID string `json:"id"`
|
||||
Model string `json:"model"`
|
||||
Results []Result `json:"results"`
|
||||
|
||||
httpHeader
|
||||
}
|
||||
|
||||
// Moderations — perform a moderation api call over a string.
|
||||
// Input can be an array or slice but a string will reduce the complexity.
|
||||
func (c *Client) Moderations(ctx context.Context, request ModerationRequest) (response ModerationResponse, err error) {
|
||||
req, err := c.requestBuilder.Build(ctx, http.MethodPost, c.fullURL("/moderations", request.Model), request)
|
||||
if _, ok := validModerationModel[request.Model]; len(request.Model) > 0 && !ok {
|
||||
err = ErrModerationInvalidModel
|
||||
return
|
||||
}
|
||||
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/moderations", request.Model), withBody(&request))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user