db

package
v0.0.0-...-67c0019 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(db *gdb.DB, obj Storer) error

Create saves an object to the database. It will first set the ID and CreatedAt fields. It is the responsibility of the caller to validate the object before calling this function.

func CreateAny

func CreateAny(db *gdb.DB, dataObj any) error

CreateAny creates an object from the database type. This should only be used for objects that cannot be retrieved after creation.

func CreateChatCompletionModelFromPublic

func CreateChatCompletionModelFromPublic(openAIModel openai.CreateChatCompletionRequest_Model) (string, error)

func Delete

func Delete[T any](db *gdb.DB, id string) error

Delete deletes an object from the database by ID.

func DeleteExpired

func DeleteExpired(db *gdb.DB, expiration time.Time, objs ...Storer) error

DeleteExpired deletes objects from the database created before or at the given expiration time.

func Dequeue

func Dequeue(db *gdb.DB, request Storer, agentID string) error

Dequeue dequeues the next request from the database, marking it as claimed by the given agent.

func EmbeddingModelFromPublic

func EmbeddingModelFromPublic(openAIModel openai.CreateEmbeddingRequest_Model) (string, error)

func EmitRunStepDeltaOutputEvent

func EmitRunStepDeltaOutputEvent(gbd *gorm.DB, run *Run, toolCall *openai.RunStepDetailsToolCallsObject_ToolCalls_Item, index int) error

func ExtractRunStepDetails

func ExtractRunStepDetails(details openai.RunStepObject_StepDetails) (any, error)

func Get

func Get(db *gdb.DB, dataObj any, id string) error

Get gets an object from the database by ID.

func IsTerminal

func IsTerminal(status string) bool

func List

func List[T any](db *gdb.DB, objs *[]T) error

List lists objects from the database.

func LoadBuiltInTool

func LoadBuiltInTool(ctx context.Context, gdb *gorm.DB, toolName string, toolDef tools.ToolDefinition) (types.Program, error)

func MessageContentFromString

func MessageContentFromString(message string) (*openai.MessageObject_Content_Item, error)

func Modify

func Modify(db *gdb.DB, obj any, id string, updates any) error

Modify modifies the object in the database. All validation should be done before calling this function.

func SetNewID

func SetNewID(obj Storer)

func SetOutputForRunStepToolCall

func SetOutputForRunStepToolCall(item *openai.RunStepDetailsToolCallsObject_ToolCalls_Item, output string) error

Types

type Assistant

type Assistant struct {
	Metadata     `json:",inline"`
	Description  *string                                                `json:"description"`
	FileIDs      datatypes.JSONSlice[string]                            `json:"file_ids"`
	Instructions *string                                                `json:"instructions"`
	Model        string                                                 `json:"model"`
	Name         *string                                                `json:"name"`
	Tools        datatypes.JSONSlice[openai.AssistantObject_Tools_Item] `json:"tools"`
}

func (*Assistant) ExtractGPTScriptTools

func (a *Assistant) ExtractGPTScriptTools(gptScriptToolDefinitions map[string]*openai.FunctionObject) ([]string, error)

func (*Assistant) FromPublic

func (a *Assistant) FromPublic(obj any) error

func (*Assistant) IDPrefix

func (a *Assistant) IDPrefix() string

func (*Assistant) ToPublic

func (a *Assistant) ToPublic() any

func (*Assistant) ToolsToChatCompletionTools

func (a *Assistant) ToolsToChatCompletionTools(gptScriptToolDefinitions, tools map[string]*openai.FunctionObject) ([]openai.ChatCompletionTool, error)

type AssistantFile

type AssistantFile struct {
	Base        `json:",inline"`
	AssistantID string `json:"assistant_id"`
}

func (*AssistantFile) FromPublic

func (af *AssistantFile) FromPublic(obj any) error

func (*AssistantFile) IDPrefix

func (af *AssistantFile) IDPrefix() string

func (*AssistantFile) ToPublic

func (af *AssistantFile) ToPublic() any

type Base

type Base struct {
	ID        string `json:"id" gorm:"primarykey"`
	CreatedAt int    `json:"created_at,omitempty"`
}

func (*Base) GetCreatedAt

func (b *Base) GetCreatedAt() int

func (*Base) GetID

func (b *Base) GetID() string

func (*Base) SetCreatedAt

func (b *Base) SetCreatedAt(t int)

func (*Base) SetID

func (b *Base) SetID(id string)

type BuiltInTool

type BuiltInTool struct {
	Tool   `json:",inline"`
	Commit string `json:"commit"`
}

type ChatCompletionResponseChunk

type ChatCompletionResponseChunk struct {
	Base              `json:",inline"`
	Choices           datatypes.JSONSlice[ChunkChoice] `json:"choices"`
	Model             string                           `json:"model"`
	SystemFingerprint *string                          `json:"system_fingerprint,omitempty"`
	// Not part of the public API
	JobResponse `json:",inline"`
	ResponseIdx int `json:"response_idx"`
}

func (*ChatCompletionResponseChunk) FromPublic

func (c *ChatCompletionResponseChunk) FromPublic(obj any) error

func (*ChatCompletionResponseChunk) GetEvent

func (c *ChatCompletionResponseChunk) GetEvent() string

func (*ChatCompletionResponseChunk) GetIndex

func (c *ChatCompletionResponseChunk) GetIndex() int

func (*ChatCompletionResponseChunk) IDPrefix

func (c *ChatCompletionResponseChunk) IDPrefix() string

func (*ChatCompletionResponseChunk) ToPublic

func (c *ChatCompletionResponseChunk) ToPublic() any

type Choice

type Choice struct {
	FinishReason string                                                   `json:"finish_reason"`
	Index        int                                                      `json:"index"`
	Logprobs     datatypes.JSONType[Lobprob]                              `json:"logprobs"`
	Message      datatypes.JSONType[openai.ChatCompletionResponseMessage] `json:"message"`
}

type ChunkChoice

type ChunkChoice struct {
	FinishReason string                                                       `json:"finish_reason"`
	Index        int                                                          `json:"index"`
	Logprobs     datatypes.JSONType[Lobprob]                                  `json:"logprobs"`
	Delta        datatypes.JSONType[openai.ChatCompletionStreamResponseDelta] `json:"delta"`
}

type CreateChatCompletionRequest

type CreateChatCompletionRequest struct {
	// The following fields are not exposed in the public API
	JobRequest `json:",inline"`
	ModelAPI   string `json:"model_api"`

	// The following fields are exposed in the public API
	FrequencyPenalty *float32                                                     `json:"frequency_penalty"`
	LogitBias        datatypes.JSONType[map[string]int]                           `json:"logit_bias"`
	Logprobs         *bool                                                        `json:"logprobs"`
	MaxTokens        *int                                                         `json:"max_tokens"`
	Messages         datatypes.JSONSlice[openai.ChatCompletionRequestMessage]     `json:"messages"`
	Model            string                                                       `json:"model"`
	N                *int                                                         `json:"n"`
	PresencePenalty  *float32                                                     `json:"presence_penalty"`
	ResponseFormat   *string                                                      `json:"response_format,omitempty"`
	Seed             *int                                                         `json:"seed"`
	Stop             datatypes.JSONType[*openai.CreateChatCompletionRequest_Stop] `json:"stop,omitempty"`
	Stream           *bool                                                        `json:"stream"`
	Temperature      *float32                                                     `json:"temperature"`
	ToolChoice       datatypes.JSONType[*openai.ChatCompletionToolChoiceOption]   `json:"tool_choice,omitempty"`
	Tools            datatypes.JSONSlice[openai.ChatCompletionTool]               `json:"tools,omitempty"`
	TopLogprobs      *int                                                         `json:"top_logprobs"`
	TopP             *float32                                                     `json:"top_p"`
	User             *string                                                      `json:"user,omitempty"`
}

func (*CreateChatCompletionRequest) FromPublic

func (c *CreateChatCompletionRequest) FromPublic(obj any) error

func (*CreateChatCompletionRequest) IDPrefix

func (c *CreateChatCompletionRequest) IDPrefix() string

func (*CreateChatCompletionRequest) ToPublic

func (c *CreateChatCompletionRequest) ToPublic() any

type CreateChatCompletionResponse

type CreateChatCompletionResponse struct {
	// The following fields are not exposed in the public API
	JobResponse `json:",inline"`
	Base        `json:",inline"`

	// The following fields are exposed in the public API
	Choices           datatypes.JSONSlice[Choice]                 `json:"choices"`
	Model             string                                      `json:"model"`
	SystemFingerprint *string                                     `json:"system_fingerprint,omitempty"`
	Usage             datatypes.JSONType[*openai.CompletionUsage] `json:"usage,omitempty"`
}

func (*CreateChatCompletionResponse) FromPublic

func (c *CreateChatCompletionResponse) FromPublic(obj any) error

func (*CreateChatCompletionResponse) IDPrefix

func (c *CreateChatCompletionResponse) IDPrefix() string

func (*CreateChatCompletionResponse) ToPublic

func (c *CreateChatCompletionResponse) ToPublic() any

type CreateEmbeddingRequest

type CreateEmbeddingRequest struct {
	// The following fields are not exposed in the public API
	JobRequest `json:",inline"`
	ModelAPI   string `json:"model_api"`

	// The following fields are exposed in the public API
	// Required fields
	Input datatypes.JSONType[openai.CreateEmbeddingRequest_Input] `json:"input"`
	Model string                                                  `json:"model"`

	// Optional fields
	EncodingFormat *string `json:"encoding_format,omitempty"`
	Dimensions     *int    `json:"dimensions,omitempty"`
	User           *string `json:"user,omitempty"`
}

func (*CreateEmbeddingRequest) FromPublic

func (e *CreateEmbeddingRequest) FromPublic(obj any) error

func (*CreateEmbeddingRequest) IDPrefix

func (e *CreateEmbeddingRequest) IDPrefix() string

func (*CreateEmbeddingRequest) ToPublic

func (e *CreateEmbeddingRequest) ToPublic() any

type CreateEmbeddingResponse

type CreateEmbeddingResponse struct {
	// The following fields are not exposed in the public API
	JobResponse `json:",inline"`
	Base        `json:",inline"`

	// The following fields are exposed in the public API
	Data  datatypes.JSONSlice[Embedding]     `json:"data"`
	Model string                             `json:"model"`
	Usage datatypes.JSONType[EmbeddingUsage] `json:"usage,omitempty"`
}

func (*CreateEmbeddingResponse) FromPublic

func (e *CreateEmbeddingResponse) FromPublic(obj any) error

func (*CreateEmbeddingResponse) IDPrefix

func (e *CreateEmbeddingResponse) IDPrefix() string

func (*CreateEmbeddingResponse) ToPublic

func (e *CreateEmbeddingResponse) ToPublic() any

type CreateImageEditRequest

type CreateImageEditRequest struct {
	JobRequest `json:",inline"`

	Image          []byte  `json:"image"`
	Mask           []byte  `json:"mask"`
	Model          *string `json:"model"`
	N              *int    `json:"n"`
	Prompt         string  `json:"prompt"`
	ResponseFormat *string `json:"response_format"`
	Size           *string `json:"size"`
	User           *string `json:"user,omitempty"`
}

func (*CreateImageEditRequest) FromPublic

func (c *CreateImageEditRequest) FromPublic(obj any) error

func (*CreateImageEditRequest) IDPrefix

func (*CreateImageEditRequest) IDPrefix() string

func (*CreateImageEditRequest) ToPublic

func (c *CreateImageEditRequest) ToPublic() any

type CreateImageRequest

type CreateImageRequest struct {
	// The following fields are not exposed in the public API
	JobRequest `json:",inline"`

	// The following fields are exposed in the public API
	Model          *string `json:"model"`
	N              *int    `json:"n"`
	Prompt         string  `json:"prompt"`
	Quality        *string `json:"quality,omitempty"`
	ResponseFormat *string `json:"response_format"`
	Size           *string `json:"size"`
	Style          *string `json:"style"`
	User           *string `json:"user,omitempty"`
}

func (*CreateImageRequest) FromPublic

func (i *CreateImageRequest) FromPublic(obj any) error

func (*CreateImageRequest) IDPrefix

func (*CreateImageRequest) IDPrefix() string

func (*CreateImageRequest) ToPublic

func (i *CreateImageRequest) ToPublic() any

type CreateImageVariationRequest

type CreateImageVariationRequest struct {
	JobRequest `json:",inline"`

	Image          []byte  `json:"image"`
	Model          *string `json:"model"`
	N              *int    `json:"n"`
	ResponseFormat *string `json:"response_format"`
	Size           *string `json:"size"`
	User           *string `json:"user,omitempty"`
}

func (*CreateImageVariationRequest) FromPublic

func (c *CreateImageVariationRequest) FromPublic(obj any) error

func (*CreateImageVariationRequest) IDPrefix

func (*CreateImageVariationRequest) IDPrefix() string

func (*CreateImageVariationRequest) ToPublic

func (c *CreateImageVariationRequest) ToPublic() any

type CreateSpeechRequest

type CreateSpeechRequest struct {
	JobRequest `json:",inline"`

	Input          string                                               `json:"input"`
	Model          datatypes.JSONType[openai.CreateSpeechRequest_Model] `json:"model"`
	ResponseFormat *string                                              `json:"response_format,omitempty"`
	Speed          *float32                                             `json:"speed,omitempty"`
	Voice          string                                               `json:"voice"`
}

func (*CreateSpeechRequest) FromPublic

func (s *CreateSpeechRequest) FromPublic(obj any) error

func (*CreateSpeechRequest) IDPrefix

func (s *CreateSpeechRequest) IDPrefix() string

func (*CreateSpeechRequest) ToPublic

func (s *CreateSpeechRequest) ToPublic() any

type CreateSpeechResponse

type CreateSpeechResponse struct {
	JobResponse `json:",inline"`

	Base    `json:",inline"`
	Content []byte `json:"content"`
}

func (*CreateSpeechResponse) FromPublic

func (c *CreateSpeechResponse) FromPublic(obj any) error

func (*CreateSpeechResponse) IDPrefix

func (*CreateSpeechResponse) IDPrefix() string

func (*CreateSpeechResponse) ToPublic

func (c *CreateSpeechResponse) ToPublic() any

type CreateTranscriptionRequest

type CreateTranscriptionRequest struct {
	JobRequest `json:",inline"`

	FileName               string                      `json:"file_name"`
	File                   []byte                      `json:"file"`
	Language               *string                     `json:"language,omitempty"`
	Model                  string                      `json:"model"`
	Prompt                 *string                     `json:"prompt,omitempty"`
	ResponseFormat         *string                     `json:"response_format,omitempty"`
	Temperature            *float32                    `json:"temperature,omitempty"`
	TimestampGranularities datatypes.JSONSlice[string] `json:"timestamp_granularities,omitempty"`
}

func (*CreateTranscriptionRequest) FromPublic

func (c *CreateTranscriptionRequest) FromPublic(obj any) error

func (*CreateTranscriptionRequest) IDPrefix

func (*CreateTranscriptionRequest) IDPrefix() string

func (*CreateTranscriptionRequest) ToPublic

func (c *CreateTranscriptionRequest) ToPublic() any

type CreateTranscriptionResponse

type CreateTranscriptionResponse struct {
	// The following fields are not exposed in the public API
	JobResponse `json:",inline"`

	// The following fields are exposed in the public API
	Base `json:",inline"`
	Text string
}

func (*CreateTranscriptionResponse) FromPublic

func (c *CreateTranscriptionResponse) FromPublic(obj any) error

func (*CreateTranscriptionResponse) IDPrefix

func (*CreateTranscriptionResponse) IDPrefix() string

func (*CreateTranscriptionResponse) ToPublic

func (c *CreateTranscriptionResponse) ToPublic() any

type CreateTranslationRequest

type CreateTranslationRequest struct {
	JobRequest `json:",inline"`

	FileName       string   `json:"file_name"`
	File           []byte   `json:"file"`
	Model          string   `json:"model"`
	Prompt         *string  `json:"prompt,omitempty"`
	ResponseFormat *string  `json:"response_format,omitempty"`
	Temperature    *float32 `json:"temperature,omitempty"`
}

func (*CreateTranslationRequest) FromPublic

func (c *CreateTranslationRequest) FromPublic(obj any) error

func (*CreateTranslationRequest) IDPrefix

func (*CreateTranslationRequest) IDPrefix() string

func (*CreateTranslationRequest) ToPublic

func (c *CreateTranslationRequest) ToPublic() any

type CreateTranslationResponse

type CreateTranslationResponse struct {
	// The following fields are not exposed in the public API
	JobResponse `json:",inline"`

	// The following fields are exposed in the public API
	Base `json:",inline"`
	Text string
}

func (*CreateTranslationResponse) FromPublic

func (c *CreateTranslationResponse) FromPublic(obj any) error

func (*CreateTranslationResponse) IDPrefix

func (*CreateTranslationResponse) IDPrefix() string

func (*CreateTranslationResponse) ToPublic

func (c *CreateTranslationResponse) ToPublic() any

type DB

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

func New

func New(dsn string, autoMigrate bool) (*DB, error)

func (*DB) AutoMigrate

func (db *DB) AutoMigrate() error

func (*DB) Check

func (db *DB) Check(w http.ResponseWriter, _ *http.Request)

func (*DB) Close

func (db *DB) Close() error

func (*DB) WithContext

func (db *DB) WithContext(ctx context.Context) *gorm.DB

type Embedding

type Embedding struct {
	Index     int                                            `json:"index"`
	Embedding datatypes.JSONType[openai.Embedding_Embedding] `json:"embedding"`
}

type EmbeddingUsage

type EmbeddingUsage struct {
	PromptTokens int `json:"prompt_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

EmbeddingUsage represents the inline CreateEmbeddingResponse.Usage struct which is not generated as a separate type

type File

type File struct {
	Base
	Content  []byte `json:"file"`
	Purpose  string `json:"purpose"`
	Filename string `json:"filename"`
}

func (*File) FromPublic

func (f *File) FromPublic(obj any) error

func (*File) IDPrefix

func (f *File) IDPrefix() string

func (*File) ToPublic

func (f *File) ToPublic() any

type FineTuningJob

type FineTuningJob struct {
	Base            `json:",inline"`
	Error           datatypes.JSONType[FineTuningJobError]           `json:"error"`
	FineTunedModel  *string                                          `json:"fine_tuned_model"`
	FinishedAt      *int                                             `json:"finished_at"`
	Hyperparameters datatypes.JSONType[FineTuningJobHyperParameters] `json:"hyperparameters"`
	Model           string                                           `json:"model"`
	OrganizationID  string                                           `json:"organization_id"`
	ResultFiles     datatypes.JSONSlice[string]                      `json:"result_files"`
	Status          string                                           `json:"status"`
	TrainedTokens   *int                                             `json:"trained_tokens"`
	TrainingFile    string                                           `json:"training_file"`
	ValidationFile  *string                                          `json:"validation_file"`
}

func (*FineTuningJob) FromPublic

func (f *FineTuningJob) FromPublic(obj any) error

func (*FineTuningJob) IDPrefix

func (f *FineTuningJob) IDPrefix() string

func (*FineTuningJob) ToPublic

func (f *FineTuningJob) ToPublic() any

type FineTuningJobError

type FineTuningJobError struct {
	Code    string  `json:"code"`
	Message string  `json:"message"`
	Param   *string `json:"param"`
}

type FineTuningJobHyperParameters

type FineTuningJobHyperParameters struct {
	NEpochs datatypes.JSONType[openai.FineTuningJob_Hyperparameters_NEpochs] `json:"n_epochs"`
}

type GenericToolCallInfo

type GenericToolCallInfo struct {
	ID        string
	Name      string
	Arguments string
	Output    string
}

type ImagesResponse

type ImagesResponse struct {
	// The following fields are not exposed in the public API
	JobResponse `json:",inline"`

	// The following fields are exposed in the public API
	Base `json:",inline"`
	Data datatypes.JSONSlice[openai.Image] `json:"data"`
}

func (*ImagesResponse) FromPublic

func (i *ImagesResponse) FromPublic(obj any) error

func (*ImagesResponse) IDPrefix

func (*ImagesResponse) IDPrefix() string

func (*ImagesResponse) ToPublic

func (i *ImagesResponse) ToPublic() any

type InvalidTypeError

type InvalidTypeError struct {
	Expected, Got any
}

func (InvalidTypeError) Error

func (e InvalidTypeError) Error() string

type JobRequest

type JobRequest struct {
	Base      `json:",inline"`
	ClaimedBy *string `json:"claimed_by,omitempty"`
	Done      bool    `json:"done"`
}

func (JobRequest) IsDone

func (j JobRequest) IsDone() bool

type JobResponse

type JobResponse struct {
	RequestID  string  `json:"request_id"`
	Error      *string `json:"error"`
	StatusCode int     `json:"status_code"`
	Done       bool    `json:"done"`
}

func (JobResponse) GetErrorString

func (j JobResponse) GetErrorString() string

func (JobResponse) GetRequestID

func (j JobResponse) GetRequestID() string

func (JobResponse) GetStatusCode

func (j JobResponse) GetStatusCode() int

func (JobResponse) IsDone

func (j JobResponse) IsDone() bool

type Lobprob

type Lobprob struct {
	Content []openai.ChatCompletionTokenLogprob `json:"content"`
}

type Message

type Message struct {
	Metadata          `json:",inline"`
	Role              string                                                 `json:"role"`
	Content           datatypes.JSONSlice[openai.MessageObject_Content_Item] `json:"content"`
	AssistantID       *string                                                `json:"assistant_id,omitempty"`
	ThreadID          string                                                 `json:"thread_id,omitempty"`
	RunID             *string                                                `json:"run_id,omitempty"`
	FileIDs           datatypes.JSONSlice[string]                            `json:"file_ids,omitempty"`
	Status            string                                                 `json:"status,omitempty"`
	CompletedAt       *int                                                   `json:"completed_at,omitempty"`
	IncompleteAt      *int                                                   `json:"incomplete_at,omitempty"`
	IncompleteDetails datatypes.JSONType[*struct {
		Reason openai.MessageObjectIncompleteDetailsReason `json:"reason"`
	}] `json:"incomplete_details,omitempty"`
}

func (*Message) FromPublic

func (m *Message) FromPublic(obj any) error

func (*Message) IDPrefix

func (m *Message) IDPrefix() string

func (*Message) ToPublic

func (m *Message) ToPublic() any

func (*Message) WithTextContent

func (m *Message) WithTextContent(content string) error

type MessageDelta

type MessageDelta struct {
	ID    string                                `json:"id"`
	Delta datatypes.JSONType[MessageDeltaDelta] `json:"delta"`
}

func NewMessageDeltaWithText

func NewMessageDeltaWithText(index int, id, text string) (*MessageDelta, error)

func (*MessageDelta) FromPublic

func (m *MessageDelta) FromPublic(obj any) error

func (*MessageDelta) ToPublic

func (m *MessageDelta) ToPublic() any

type MessageDeltaContentTextObjectText

type MessageDeltaContentTextObjectText struct {
	Annotations *[]openai.MessageDeltaContentTextObject_Text_Annotations_Item `json:"annotations,omitempty"`
	Value       *string                                                       `json:"value,omitempty"`
}

type MessageDeltaDelta

type MessageDeltaDelta struct {
	Content *[]openai.MessageDeltaObject_Delta_Content_Item `json:"content,omitempty"`

	// Keeping this field as FileIds makes the casting to the openai types much easier.
	//nolint:revive
	FileIds *[]string                           `json:"file_ids,omitempty"`
	Role    *openai.MessageDeltaObjectDeltaRole `json:"role,omitempty"`
}

type MessageFile

type MessageFile struct {
	Base      `json:",inline"`
	MessageID string `json:"message_id"`
}

func (*MessageFile) FromPublic

func (m *MessageFile) FromPublic(obj any) error

func (*MessageFile) IDPrefix

func (m *MessageFile) IDPrefix() string

func (*MessageFile) ToPublic

func (m *MessageFile) ToPublic() any

type Metadata

type Metadata struct {
	Base     `json:",inline"`
	Metadata datatypes.JSONMap `json:"metadata,omitempty"`
}

type Model

type Model struct {
	Base    `json:",inline"`
	OwnedBy string `json:"owned_by"`
}

func (*Model) FromPublic

func (m *Model) FromPublic(obj any) error

func (*Model) IDPrefix

func (m *Model) IDPrefix() string

func (*Model) ToPublic

func (m *Model) ToPublic() any

type Run

type Run struct {
	Metadata       `json:",inline"`
	AssistantID    string                                           `json:"assistant_id"`
	ThreadID       string                                           `json:"thread_id"`
	Status         string                                           `json:"status"`
	RequiredAction datatypes.JSONType[*RunRequiredAction]           `json:"required_action"`
	LastError      datatypes.JSONType[*RunLastError]                `json:"last_error"`
	ExpiresAt      *int                                             `json:"expires_at,omitempty"`
	StartedAt      *int                                             `json:"started_at,omitempty"`
	CancelledAt    *int                                             `json:"cancelled_at,omitempty"`
	CompletedAt    *int                                             `json:"completed_at,omitempty"`
	FailedAt       *int                                             `json:"failed_at,omitempty"`
	Model          string                                           `json:"model"`
	Instructions   string                                           `json:"instructions,omitempty"`
	Tools          datatypes.JSONSlice[openai.RunObject_Tools_Item] `json:"tools"`
	FileIDs        datatypes.JSONSlice[string]                      `json:"file_ids,omitempty"`
	Usage          datatypes.JSONType[*openai.RunCompletionUsage]   `json:"usage"`

	// These are not part of the public API
	ClaimedBy       *string `json:"claimed_by,omitempty"`
	SystemClaimedBy *string `json:"system_claimed_by,omitempty"`
	SystemStatus    *string `json:"system_status,omitempty"`
	EventIndex      int     `json:"event_index,omitempty"`
}

func CancelRun

func CancelRun(db *gdb.DB, id string) (*Run, error)

CancelRun cancels a run that is in progress. If the run is not in progress, it will return an error.

func (*Run) BeforeUpdate

func (r *Run) BeforeUpdate(tx *gorm.DB) error

func (*Run) FromPublic

func (r *Run) FromPublic(obj any) error

func (*Run) GetStatus

func (r *Run) GetStatus() string

func (*Run) IDPrefix

func (r *Run) IDPrefix() string

func (*Run) ToPublic

func (r *Run) ToPublic() any

type RunEvent

type RunEvent struct {
	JobResponse `json:",inline"`
	Base        `json:",inline"`

	EventName    string                            `json:"event_name"`
	Run          datatypes.JSONType[*Run]          `json:"run,omitempty"`
	Thread       datatypes.JSONType[*Thread]       `json:"thread,omitempty"`
	RunStep      datatypes.JSONType[*RunStep]      `json:"run_step,omitempty"`
	RunStepDelta datatypes.JSONType[*RunStepDelta] `json:"run_step_delta,omitempty"`
	Message      datatypes.JSONType[*Message]      `json:"message,omitempty"`
	MessageDelta datatypes.JSONType[*MessageDelta] `json:"message_delta,omitempty"`
	ResponseIdx  int                               `json:"response_idx"`
}

func (*RunEvent) FromPublic

func (r *RunEvent) FromPublic(obj any) error

func (*RunEvent) GetEvent

func (r *RunEvent) GetEvent() string

func (*RunEvent) GetIndex

func (r *RunEvent) GetIndex() int

func (*RunEvent) IDPrefix

func (r *RunEvent) IDPrefix() string

func (*RunEvent) ToPublic

func (r *RunEvent) ToPublic() any

type RunLastError

type RunLastError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type RunRequiredAction

type RunRequiredAction struct {
	SubmitToolOutputs []openai.RunToolCallObject         `json:"submit_tool_outputs"`
	XConfirm          *RunRequiredActionXConfirm         `json:"x-confirm"`
	Type              openai.RunObjectRequiredActionType `json:"type"`
}

type RunRequiredActionXConfirm

type RunRequiredActionXConfirm struct {
	Action string `json:"action"`
	ID     string `json:"id"`
}

type RunStep

type RunStep struct {
	Metadata    `json:",inline"`
	AssistantID string                                               `json:"assistant_id"`
	CancelledAt *int                                                 `json:"cancelled_at"`
	CompletedAt *int                                                 `json:"completed_at"`
	ExpiredAt   *int                                                 `json:"expired_at"`
	FailedAt    *int                                                 `json:"failed_at"`
	LastError   datatypes.JSONType[RunLastError]                     `json:"last_error"`
	RunID       string                                               `json:"run_id"`
	Status      string                                               `json:"status"`
	StepDetails datatypes.JSONType[openai.RunStepObject_StepDetails] `json:"step_details"`
	ThreadID    string                                               `json:"thread_id"`
	Type        string                                               `json:"type"`
	Usage       datatypes.JSONType[*openai.RunStepCompletionUsage]   `json:"usage"`

	// These are not part of the public API
	ClaimedBy          *string `json:"claimed_by,omitempty"`
	RunnerType         *string `json:"runner_type,omitempty"`
	RetrievalArguments string  `json:"retrieval_arguments,omitempty"`
}

func (*RunStep) BeforeUpdate

func (r *RunStep) BeforeUpdate(tx *gorm.DB) error

func (*RunStep) FromPublic

func (r *RunStep) FromPublic(obj any) error

func (*RunStep) GetRunStepFunctionCalls

func (r *RunStep) GetRunStepFunctionCalls() ([]openai.RunStepDetailsToolCallsFunctionObject, error)

func (*RunStep) GetStatus

func (r *RunStep) GetStatus() string

func (*RunStep) IDPrefix

func (r *RunStep) IDPrefix() string

func (*RunStep) Merge

func (r *RunStep) Merge(toolCalls *[]GenericToolCallInfo, chunk ChatCompletionResponseChunk) (*RunStepDelta, error)

Merge will merge the given chunk into the current run step.

func (*RunStep) RunStepConfirmed

func (r *RunStep) RunStepConfirmed(id string) (bool, error)

func (*RunStep) SetConfirmed

func (r *RunStep) SetConfirmed(id string, confirmed *bool) error

func (*RunStep) ToPublic

func (r *RunStep) ToPublic() any

type RunStepDelta

type RunStepDelta struct {
	ID    string                                `json:"id"`
	Delta datatypes.JSONType[RunStepDeltaDelta] `json:"delta"`
}

func (*RunStepDelta) FromPublic

func (r *RunStepDelta) FromPublic(obj any) error

func (*RunStepDelta) ToPublic

func (r *RunStepDelta) ToPublic() any

type RunStepDeltaDelta

type RunStepDeltaDelta struct {
	StepDetails *openai.RunStepDeltaObject_Delta_StepDetails `json:"step_details,omitempty"`
}

type RunStepEvent

type RunStepEvent struct {
	Base        `json:",inline"`
	JobResponse `json:",inline"`

	CallContext        datatypes.JSONMap       `json:"call_context,omitempty"`
	ToolSubCalls       datatypes.JSONMap       `json:"tool_sub_calls,omitempty"`
	ToolResults        int                     `json:"tool_results,omitempty"`
	Type               string                  `json:"type,omitempty"`
	ChatCompletionID   string                  `json:"chat_completion_id,omitempty"`
	ChatRequest        datatypes.JSONType[any] `json:"chat_request,omitempty"`
	ChatResponse       datatypes.JSONType[any] `json:"chat_response,omitempty"`
	ChatResponseCached bool                    `json:"chat_response_cached,omitempty"`
	Content            string                  `json:"content,omitempty"`
	RunID              string                  `json:"run_id,omitempty"`
	Input              string                  `json:"input,omitempty"`
	Output             string                  `json:"output,omitempty"`
	Err                string                  `json:"err,omitempty"`
	ResponseIdx        int                     `json:"response_idx"`
}

func FromGPTScriptEvent

func FromGPTScriptEvent(event server.Event, runID, runStepID string, index int, done bool) *RunStepEvent

func (*RunStepEvent) FromPublic

func (r *RunStepEvent) FromPublic(obj any) error

func (*RunStepEvent) GetEvent

func (r *RunStepEvent) GetEvent() string

func (*RunStepEvent) GetIndex

func (r *RunStepEvent) GetIndex() int

func (*RunStepEvent) IDPrefix

func (r *RunStepEvent) IDPrefix() string

func (*RunStepEvent) ToPublic

func (r *RunStepEvent) ToPublic() any

type RunToolObject

type RunToolObject struct {
	JobRequest

	EnvVars       datatypes.JSONSlice[string] `json:"env_vars,omitempty"`
	File          string                      `json:"file"`
	Input         string                      `json:"input,omitempty"`
	Subtool       string                      `json:"subtool"`
	Chdir         string                      `json:"chdir,omitempty"`
	DisableCache  bool                        `json:"disable_cache,omitempty"`
	DangerousMode bool                        `json:"dangerous_mode,omitempty"`

	Output    string `json:"output,omitempty"`
	Status    string `json:"status,omitempty"`
	Confirmed *bool  `json:"confirmed,omitempty"`
}

func (*RunToolObject) FromPublic

func (r *RunToolObject) FromPublic(obj any) error

func (*RunToolObject) IDPrefix

func (r *RunToolObject) IDPrefix() string

func (*RunToolObject) ToPublic

func (r *RunToolObject) ToPublic() any

type Storer

type Storer interface {
	IDPrefix() string
	SetID(string)
	GetID() string
	SetCreatedAt(int)
	GetCreatedAt() int
}

type Thread

type Thread struct {
	Metadata `json:",inline"`
	// This is not part of the public API
	LockedByRunID string `json:"locked_by_run_id"`
}

func (*Thread) FromPublic

func (t *Thread) FromPublic(obj any) error

func (*Thread) GetThreadID

func (t *Thread) GetThreadID() string

func (*Thread) IDPrefix

func (t *Thread) IDPrefix() string

func (*Thread) SetThreadID

func (t *Thread) SetThreadID(string) error

func (*Thread) ToPublic

func (t *Thread) ToPublic() any

type Tool

type Tool struct {
	Base        `json:",inline"`
	Name        string                      `json:"name"`
	Description string                      `json:"description"`
	Contents    *string                     `json:"contents"`
	URL         *string                     `json:"url"`
	Subtool     *string                     `json:"subtool"`
	EnvVars     datatypes.JSONSlice[string] `json:"env_vars"`
	// Not part of the public API
	Program datatypes.JSON `json:"program"`
}

func (*Tool) FromPublic

func (t *Tool) FromPublic(obj any) error

func (*Tool) IDPrefix

func (t *Tool) IDPrefix() string

func (*Tool) ToPublic

func (t *Tool) ToPublic() any

Jump to

Keyboard shortcuts

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