openai

package
v3.82.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Code generated by go generate; DO NOT EDIT.

Index

Constants

View Source
const (
	BASE_URL      = "https://api.openai.com"
	ORGS_ENDPOINT = "/v1/organizations"
	ME_ENDPOINT   = "/v1/me"
)

Variables

View Source
var (
	PermissionStrings = map[Permission]string{
		ModelsRead:             "models:read",
		ModelCapabilitiesWrite: "model_capabilities:write",
		AssistantsRead:         "assistants:read",
		AssistantsWrite:        "assistants:write",
		ThreadsRead:            "threads:read",
		ThreadsWrite:           "threads:write",
		FineTuningRead:         "fine_tuning:read",
		FineTuningWrite:        "fine_tuning:write",
		FilesRead:              "files:read",
		FilesWrite:             "files:write",
	}

	StringToPermission = map[string]Permission{
		"models:read":              ModelsRead,
		"model_capabilities:write": ModelCapabilitiesWrite,
		"assistants:read":          AssistantsRead,
		"assistants:write":         AssistantsWrite,
		"threads:read":             ThreadsRead,
		"threads:write":            ThreadsWrite,
		"fine_tuning:read":         FineTuningRead,
		"fine_tuning:write":        FineTuningWrite,
		"files:read":               FilesRead,
		"files:write":              FilesWrite,
	}

	PermissionIDs = map[Permission]int{
		ModelsRead:             1,
		ModelCapabilitiesWrite: 2,
		AssistantsRead:         3,
		AssistantsWrite:        4,
		ThreadsRead:            5,
		ThreadsWrite:           6,
		FineTuningRead:         7,
		FineTuningWrite:        8,
		FilesRead:              9,
		FilesWrite:             10,
	}

	IdToPermission = map[int]Permission{
		1:  ModelsRead,
		2:  ModelCapabilitiesWrite,
		3:  AssistantsRead,
		4:  AssistantsWrite,
		5:  ThreadsRead,
		6:  ThreadsWrite,
		7:  FineTuningRead,
		8:  FineTuningWrite,
		9:  FilesRead,
		10: FilesWrite,
	}
)
View Source
var POST_PAYLOAD = map[string]interface{}{"speed": 1}
View Source
var SCOPES = []OpenAIScope{
	{
		ReadTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/models", Method: "GET", Valid: []int{200}, Invalid: []int{403}, Type: analyzers.READ, Status: analyzers.PermissionStatus{}},
		},
		Endpoints:      []string{"/v1/models"},
		ReadPermission: ModelsRead,
	},
	{
		WriteTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/images/generations", Method: "POST", Payload: POST_PAYLOAD, Valid: []int{400}, Invalid: []int{401}, Type: analyzers.WRITE, Status: analyzers.PermissionStatus{}},
		},
		Endpoints:       []string{"/v1/audio", "/v1/chat/completions", "/v1/embeddings", "/v1/images", "/v1/moderations"},
		WritePermission: ModelCapabilitiesWrite,
	},
	{
		ReadTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/assistants", Method: "GET", Valid: []int{400}, Invalid: []int{401}, Type: analyzers.READ, Status: analyzers.PermissionStatus{}},
		},
		WriteTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/assistants", Method: "POST", Payload: POST_PAYLOAD, Valid: []int{400}, Invalid: []int{401}, Type: analyzers.WRITE, Status: analyzers.PermissionStatus{}},
		},
		Endpoints:       []string{"/v1/assistants"},
		ReadPermission:  AssistantsRead,
		WritePermission: AssistantsWrite,
	},
	{
		ReadTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/threads/1", Method: "GET", Valid: []int{400}, Invalid: []int{401}, Type: analyzers.READ, Status: analyzers.PermissionStatus{}},
		},
		WriteTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/threads", Method: "POST", Payload: POST_PAYLOAD, Valid: []int{400}, Invalid: []int{401}, Type: analyzers.WRITE, Status: analyzers.PermissionStatus{}},
		},
		Endpoints:       []string{"/v1/threads"},
		ReadPermission:  ThreadsRead,
		WritePermission: ThreadsWrite,
	},
	{
		ReadTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/fine_tuning/jobs", Method: "GET", Valid: []int{200}, Invalid: []int{401}, Type: analyzers.READ, Status: analyzers.PermissionStatus{}},
		},
		WriteTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/fine_tuning/jobs", Method: "POST", Payload: POST_PAYLOAD, Valid: []int{400}, Invalid: []int{401}, Type: analyzers.WRITE, Status: analyzers.PermissionStatus{}},
		},
		Endpoints:       []string{"/v1/fine_tuning"},
		ReadPermission:  FineTuningRead,
		WritePermission: FineTuningWrite,
	},
	{
		ReadTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/files", Method: "GET", Valid: []int{200}, Invalid: []int{401}, Type: analyzers.READ, Status: analyzers.PermissionStatus{}},
		},
		WriteTests: []analyzers.HttpStatusTest{
			{URL: BASE_URL + "/v1/files", Method: "POST", Payload: POST_PAYLOAD, Valid: []int{415}, Invalid: []int{401}, Type: analyzers.WRITE, Status: analyzers.PermissionStatus{}},
		},
		Endpoints:       []string{"/v1/files"},
		ReadPermission:  FilesRead,
		WritePermission: FilesWrite,
	},
}

Functions

func AnalyzeAndPrintPermissions

func AnalyzeAndPrintPermissions(cfg *config.Config, apiKey string)

Types

type Analyzer

type Analyzer struct {
	Cfg *config.Config
}

func (Analyzer) Analyze

func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error)

func (Analyzer) Type

type AnalyzerJSON

type AnalyzerJSON struct {
	// contains filtered or unexported fields
}

func AnalyzePermissions

func AnalyzePermissions(cfg *config.Config, key string) (*AnalyzerJSON, error)

AnalyzePermissions will analyze the permissions of an OpenAI API key

type MeJSON

type MeJSON struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Email      string `json:"email"`
	Phone      string `json:"phone_number"`
	MfaEnabled bool   `json:"mfa_flag_enabled"`
	Orgs       struct {
		Data []struct {
			ID          string `json:"id"`
			Title       string `json:"title"`
			User        string `json:"name"`
			Description string `json:"description"`
			Personal    bool   `json:"personal"`
			Default     bool   `json:"is_default"`
			Role        string `json:"role"`
		} `json:"data"`
	} `json:"orgs"`
}

type OpenAIScope

type OpenAIScope struct {
	ReadTests       []analyzers.HttpStatusTest
	WriteTests      []analyzers.HttpStatusTest
	Endpoints       []string
	ReadPermission  Permission
	WritePermission Permission
}

func (*OpenAIScope) RunTests

func (s *OpenAIScope) RunTests(key string) error

type Permission added in v3.80.5

type Permission int
const (
	Invalid                Permission = iota
	ModelsRead             Permission = iota
	ModelCapabilitiesWrite Permission = iota
	AssistantsRead         Permission = iota
	AssistantsWrite        Permission = iota
	ThreadsRead            Permission = iota
	ThreadsWrite           Permission = iota
	FineTuningRead         Permission = iota
	FineTuningWrite        Permission = iota
	FilesRead              Permission = iota
	FilesWrite             Permission = iota
)

func PermissionFromID added in v3.80.5

func PermissionFromID(id int) (Permission, error)

PermissionFromID converts an ID to its Permission enum

func PermissionFromString added in v3.80.5

func PermissionFromString(s string) (Permission, error)

PermissionFromString converts a string representation to its Permission enum

func (Permission) ToID added in v3.80.5

func (p Permission) ToID() (int, error)

ToID converts a Permission enum to its ID

func (Permission) ToString added in v3.80.5

func (p Permission) ToString() (string, error)

ToString converts a Permission enum to its string representation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL