|
|
|
|
| package request
|
|
|
| import (
|
| "fmt"
|
| "io"
|
| "strconv"
|
| "time"
|
|
|
| "entgo.io/ent"
|
| "entgo.io/ent/dialect/sql"
|
| "entgo.io/ent/dialect/sql/sqlgraph"
|
| )
|
|
|
| const (
|
|
|
| Label = "request"
|
|
|
| FieldID = "id"
|
|
|
| FieldCreatedAt = "created_at"
|
|
|
| FieldUpdatedAt = "updated_at"
|
|
|
| FieldAPIKeyID = "api_key_id"
|
|
|
| FieldProjectID = "project_id"
|
|
|
| FieldTraceID = "trace_id"
|
|
|
| FieldDataStorageID = "data_storage_id"
|
|
|
| FieldSource = "source"
|
|
|
| FieldModelID = "model_id"
|
|
|
| FieldFormat = "format"
|
|
|
| FieldRequestHeaders = "request_headers"
|
|
|
| FieldRequestBody = "request_body"
|
|
|
| FieldResponseBody = "response_body"
|
|
|
| FieldResponseChunks = "response_chunks"
|
|
|
| FieldChannelID = "channel_id"
|
|
|
| FieldExternalID = "external_id"
|
|
|
| FieldStatus = "status"
|
|
|
| FieldStream = "stream"
|
|
|
| FieldClientIP = "client_ip"
|
|
|
| FieldMetricsLatencyMs = "metrics_latency_ms"
|
|
|
| FieldMetricsFirstTokenLatencyMs = "metrics_first_token_latency_ms"
|
|
|
| EdgeAPIKey = "api_key"
|
|
|
| EdgeProject = "project"
|
|
|
| EdgeTrace = "trace"
|
|
|
| EdgeDataStorage = "data_storage"
|
|
|
| EdgeExecutions = "executions"
|
|
|
| EdgeChannel = "channel"
|
|
|
| EdgeUsageLogs = "usage_logs"
|
|
|
| Table = "requests"
|
|
|
| APIKeyTable = "requests"
|
|
|
|
|
| APIKeyInverseTable = "api_keys"
|
|
|
| APIKeyColumn = "api_key_id"
|
|
|
| ProjectTable = "requests"
|
|
|
|
|
| ProjectInverseTable = "projects"
|
|
|
| ProjectColumn = "project_id"
|
|
|
| TraceTable = "requests"
|
|
|
|
|
| TraceInverseTable = "traces"
|
|
|
| TraceColumn = "trace_id"
|
|
|
| DataStorageTable = "requests"
|
|
|
|
|
| DataStorageInverseTable = "data_storages"
|
|
|
| DataStorageColumn = "data_storage_id"
|
|
|
| ExecutionsTable = "request_executions"
|
|
|
|
|
| ExecutionsInverseTable = "request_executions"
|
|
|
| ExecutionsColumn = "request_id"
|
|
|
| ChannelTable = "requests"
|
|
|
|
|
| ChannelInverseTable = "channels"
|
|
|
| ChannelColumn = "channel_id"
|
|
|
| UsageLogsTable = "usage_logs"
|
|
|
|
|
| UsageLogsInverseTable = "usage_logs"
|
|
|
| UsageLogsColumn = "request_id"
|
| )
|
|
|
|
|
| var Columns = []string{
|
| FieldID,
|
| FieldCreatedAt,
|
| FieldUpdatedAt,
|
| FieldAPIKeyID,
|
| FieldProjectID,
|
| FieldTraceID,
|
| FieldDataStorageID,
|
| FieldSource,
|
| FieldModelID,
|
| FieldFormat,
|
| FieldRequestHeaders,
|
| FieldRequestBody,
|
| FieldResponseBody,
|
| FieldResponseChunks,
|
| FieldChannelID,
|
| FieldExternalID,
|
| FieldStatus,
|
| FieldStream,
|
| FieldClientIP,
|
| FieldMetricsLatencyMs,
|
| FieldMetricsFirstTokenLatencyMs,
|
| }
|
|
|
|
|
| func ValidColumn(column string) bool {
|
| for i := range Columns {
|
| if column == Columns[i] {
|
| return true
|
| }
|
| }
|
| return false
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
| var (
|
| Hooks [1]ent.Hook
|
| Policy ent.Policy
|
|
|
| DefaultCreatedAt func() time.Time
|
|
|
| DefaultUpdatedAt func() time.Time
|
|
|
| UpdateDefaultUpdatedAt func() time.Time
|
|
|
| DefaultProjectID int
|
|
|
| DefaultFormat string
|
|
|
| DefaultStream bool
|
|
|
| DefaultClientIP string
|
| )
|
|
|
|
|
| type Source string
|
|
|
|
|
| const DefaultSource = SourceAPI
|
|
|
|
|
| const (
|
| SourceAPI Source = "api"
|
| SourcePlayground Source = "playground"
|
| SourceTest Source = "test"
|
| )
|
|
|
| func (s Source) String() string {
|
| return string(s)
|
| }
|
|
|
|
|
| func SourceValidator(s Source) error {
|
| switch s {
|
| case SourceAPI, SourcePlayground, SourceTest:
|
| return nil
|
| default:
|
| return fmt.Errorf("request: invalid enum value for source field: %q", s)
|
| }
|
| }
|
|
|
|
|
| type Status string
|
|
|
|
|
| const (
|
| StatusPending Status = "pending"
|
| StatusProcessing Status = "processing"
|
| StatusCompleted Status = "completed"
|
| StatusFailed Status = "failed"
|
| StatusCanceled Status = "canceled"
|
| )
|
|
|
| func (s Status) String() string {
|
| return string(s)
|
| }
|
|
|
|
|
| func StatusValidator(s Status) error {
|
| switch s {
|
| case StatusPending, StatusProcessing, StatusCompleted, StatusFailed, StatusCanceled:
|
| return nil
|
| default:
|
| return fmt.Errorf("request: invalid enum value for status field: %q", s)
|
| }
|
| }
|
|
|
|
|
| type OrderOption func(*sql.Selector)
|
|
|
|
|
| func ByID(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldID, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByAPIKeyID(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldAPIKeyID, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByProjectID(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldProjectID, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByTraceID(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldTraceID, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByDataStorageID(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldDataStorageID, opts...).ToFunc()
|
| }
|
|
|
|
|
| func BySource(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldSource, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByModelID(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldModelID, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByFormat(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldFormat, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByChannelID(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldChannelID, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByExternalID(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldExternalID, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByStream(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldStream, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByClientIP(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldClientIP, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByMetricsLatencyMs(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldMetricsLatencyMs, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByMetricsFirstTokenLatencyMs(opts ...sql.OrderTermOption) OrderOption {
|
| return sql.OrderByField(FieldMetricsFirstTokenLatencyMs, opts...).ToFunc()
|
| }
|
|
|
|
|
| func ByAPIKeyField(field string, opts ...sql.OrderTermOption) OrderOption {
|
| return func(s *sql.Selector) {
|
| sqlgraph.OrderByNeighborTerms(s, newAPIKeyStep(), sql.OrderByField(field, opts...))
|
| }
|
| }
|
|
|
|
|
| func ByProjectField(field string, opts ...sql.OrderTermOption) OrderOption {
|
| return func(s *sql.Selector) {
|
| sqlgraph.OrderByNeighborTerms(s, newProjectStep(), sql.OrderByField(field, opts...))
|
| }
|
| }
|
|
|
|
|
| func ByTraceField(field string, opts ...sql.OrderTermOption) OrderOption {
|
| return func(s *sql.Selector) {
|
| sqlgraph.OrderByNeighborTerms(s, newTraceStep(), sql.OrderByField(field, opts...))
|
| }
|
| }
|
|
|
|
|
| func ByDataStorageField(field string, opts ...sql.OrderTermOption) OrderOption {
|
| return func(s *sql.Selector) {
|
| sqlgraph.OrderByNeighborTerms(s, newDataStorageStep(), sql.OrderByField(field, opts...))
|
| }
|
| }
|
|
|
|
|
| func ByExecutionsCount(opts ...sql.OrderTermOption) OrderOption {
|
| return func(s *sql.Selector) {
|
| sqlgraph.OrderByNeighborsCount(s, newExecutionsStep(), opts...)
|
| }
|
| }
|
|
|
|
|
| func ByExecutions(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
| return func(s *sql.Selector) {
|
| sqlgraph.OrderByNeighborTerms(s, newExecutionsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
| }
|
| }
|
|
|
|
|
| func ByChannelField(field string, opts ...sql.OrderTermOption) OrderOption {
|
| return func(s *sql.Selector) {
|
| sqlgraph.OrderByNeighborTerms(s, newChannelStep(), sql.OrderByField(field, opts...))
|
| }
|
| }
|
|
|
|
|
| func ByUsageLogsCount(opts ...sql.OrderTermOption) OrderOption {
|
| return func(s *sql.Selector) {
|
| sqlgraph.OrderByNeighborsCount(s, newUsageLogsStep(), opts...)
|
| }
|
| }
|
|
|
|
|
| func ByUsageLogs(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
| return func(s *sql.Selector) {
|
| sqlgraph.OrderByNeighborTerms(s, newUsageLogsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
| }
|
| }
|
| func newAPIKeyStep() *sqlgraph.Step {
|
| return sqlgraph.NewStep(
|
| sqlgraph.From(Table, FieldID),
|
| sqlgraph.To(APIKeyInverseTable, FieldID),
|
| sqlgraph.Edge(sqlgraph.M2O, true, APIKeyTable, APIKeyColumn),
|
| )
|
| }
|
| func newProjectStep() *sqlgraph.Step {
|
| return sqlgraph.NewStep(
|
| sqlgraph.From(Table, FieldID),
|
| sqlgraph.To(ProjectInverseTable, FieldID),
|
| sqlgraph.Edge(sqlgraph.M2O, true, ProjectTable, ProjectColumn),
|
| )
|
| }
|
| func newTraceStep() *sqlgraph.Step {
|
| return sqlgraph.NewStep(
|
| sqlgraph.From(Table, FieldID),
|
| sqlgraph.To(TraceInverseTable, FieldID),
|
| sqlgraph.Edge(sqlgraph.M2O, true, TraceTable, TraceColumn),
|
| )
|
| }
|
| func newDataStorageStep() *sqlgraph.Step {
|
| return sqlgraph.NewStep(
|
| sqlgraph.From(Table, FieldID),
|
| sqlgraph.To(DataStorageInverseTable, FieldID),
|
| sqlgraph.Edge(sqlgraph.M2O, true, DataStorageTable, DataStorageColumn),
|
| )
|
| }
|
| func newExecutionsStep() *sqlgraph.Step {
|
| return sqlgraph.NewStep(
|
| sqlgraph.From(Table, FieldID),
|
| sqlgraph.To(ExecutionsInverseTable, FieldID),
|
| sqlgraph.Edge(sqlgraph.O2M, false, ExecutionsTable, ExecutionsColumn),
|
| )
|
| }
|
| func newChannelStep() *sqlgraph.Step {
|
| return sqlgraph.NewStep(
|
| sqlgraph.From(Table, FieldID),
|
| sqlgraph.To(ChannelInverseTable, FieldID),
|
| sqlgraph.Edge(sqlgraph.M2O, true, ChannelTable, ChannelColumn),
|
| )
|
| }
|
| func newUsageLogsStep() *sqlgraph.Step {
|
| return sqlgraph.NewStep(
|
| sqlgraph.From(Table, FieldID),
|
| sqlgraph.To(UsageLogsInverseTable, FieldID),
|
| sqlgraph.Edge(sqlgraph.O2M, false, UsageLogsTable, UsageLogsColumn),
|
| )
|
| }
|
|
|
|
|
| func (e Source) MarshalGQL(w io.Writer) {
|
| io.WriteString(w, strconv.Quote(e.String()))
|
| }
|
|
|
|
|
| func (e *Source) UnmarshalGQL(val interface{}) error {
|
| str, ok := val.(string)
|
| if !ok {
|
| return fmt.Errorf("enum %T must be a string", val)
|
| }
|
| *e = Source(str)
|
| if err := SourceValidator(*e); err != nil {
|
| return fmt.Errorf("%s is not a valid Source", str)
|
| }
|
| return nil
|
| }
|
|
|
|
|
| func (e Status) MarshalGQL(w io.Writer) {
|
| io.WriteString(w, strconv.Quote(e.String()))
|
| }
|
|
|
|
|
| func (e *Status) UnmarshalGQL(val interface{}) error {
|
| str, ok := val.(string)
|
| if !ok {
|
| return fmt.Errorf("enum %T must be a string", val)
|
| }
|
| *e = Status(str)
|
| if err := StatusValidator(*e); err != nil {
|
| return fmt.Errorf("%s is not a valid Status", str)
|
| }
|
| return nil
|
| }
|
|
|