bot

package
v0.0.0-...-7fbe3ab Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const PromptTypeMemory = "memory_message"
View Source
const PromptTypeTransition = "transition_message"
View Source
const PromptTypeUser = "user_message"

Variables

View Source
var ErrBotSessionNotFound = fmt.Errorf("bot session not found")
View Source
var Keys = &keys{}

Functions

This section is empty.

Types

type BotChatCompletionMessage

type BotChatCompletionMessage struct {
	Role    string `json:"role" redis:"role"`
	Content string `json:"content" redis:"content"`

	// This property isn't in the official documentation, but it's in
	// the documentation for the official library for python:
	// - https://github.com/openai/openai-python/blob/main/chatml.md
	// - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
	Name string `json:"name,omitempty" redis:"name,omitempty"`
}

type BotConfig

type BotConfig struct {
	Model          string                         `json:"model" redis:"model"`
	Locations      map[string]BotLocationConfig   `json:"locations" redis:"locations"`
	Transitions    map[string]BotTransitionConfig `json:"transitions" redis:"transitions"`
	ApiKey         string                         `json:"api_key" redis:"api_key"`
	Authorized     bool                           `json:"authorized" redis:"authorized"`
	WelcomeMessage string                         `json:"welcome_message" redis:"welcome_message"`
}

BotConfig holds the overall config for the bot

func (*BotConfig) FormatLocations

func (b *BotConfig) FormatLocations() string

func (*BotConfig) FormatTransitions

func (b *BotConfig) FormatTransitions() string

type BotEvent

type BotEvent struct {
	Type     BotEventType      `json:"type" redis:"type"`
	Value    string            `json:"value" redis:"value"`
	Metadata map[string]string `json:"metadata" redis:"metadata"`
	PairId   string            `json:"pair_id" redis:"pair_id"`
}

type BotEventPair

type BotEventPair struct {
	Request  *BotEvent `json:"request" redis:"request"`
	Response *BotEvent `json:"response" redis:"response"`
}

type BotEventType

type BotEventType string
const (
	BotEventTypeError               BotEventType = "error"
	BotEventTypeAgentMessage        BotEventType = "agent_message"
	BotEventTypeUserMessage         BotEventType = "user_message"
	BotEventTypeTransitionMessage   BotEventType = "transition_message"
	BotEventTypeMemoryMessage       BotEventType = "memory_message"
	BotEventTypeMemoryUpdated       BotEventType = "memory_updated"
	BotEventTypeSessionCreated      BotEventType = "session_created"
	BotEventTypeTransitionFired     BotEventType = "transition_fired"
	BotEventTypeTransitionFailed    BotEventType = "transition_failed"
	BotEventTypeTransitionStarted   BotEventType = "transition_started"
	BotEventTypeTransitionCompleted BotEventType = "transition_completed"
	BotEventTypeNetworkState        BotEventType = "network_state"
	BotEventTypeConfirmTransition   BotEventType = "confirm_transition"
	BotEventTypeAcceptTransition    BotEventType = "accept_transition"
	BotEventTypeRejectTransition    BotEventType = "reject_transition"
	BotEventTypeInputFileRequest    BotEventType = "input_file_request"
	BotEventTypeInputFileResponse   BotEventType = "input_file_response"
	BotEventTypeOutputFile          BotEventType = "output_file"
	BotEventTypeConfirmRequest      BotEventType = "confirm_request"
	BotEventTypeConfirmResponse     BotEventType = "confirm_response"
)

type BotInterface

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

func NewBotInterface

func NewBotInterface(opts botInterfaceOpts) (*BotInterface, error)

func (*BotInterface) SendPrompt

func (bi *BotInterface) SendPrompt(sessionId, messageType string, request *BotEvent) error

type BotLocationConfig

type BotLocationConfig struct {
	Name   string            `json:"name" redis:"name"`
	Marker map[string]string `json:"marker" redis:"marker"`
	Expose bool              `json:"expose" redis:"expose"`
}

BotLocationConfig holds the config for a location in the bot network

func (*BotLocationConfig) FormatLocation

func (l *BotLocationConfig) FormatLocation() string

type BotMemoryResponse

type BotMemoryResponse struct {
	Msg string `json:"msg" redis:"msg"`
}

type BotNetworkSnapshot

type BotNetworkSnapshot struct {
	SessionId            string           `json:"session_id" redis:"session_id"`
	LocationMarkerCounts map[string]int64 `json:"location_marker_counts" redis:"location_marker_counts"`
	Config               BotConfig        `json:"config" redis:"config"`
}

type BotServiceOpts

type BotServiceOpts struct {
	Config         types.AppConfig
	RedisClient    *common.RedisClient
	BackendRepo    repository.BackendRepository
	WorkspaceRepo  repository.WorkspaceRepository
	TaskRepo       repository.TaskRepository
	ContainerRepo  repository.ContainerRepository
	Scheduler      *scheduler.Scheduler
	RouteGroup     *echo.Group
	Tailscale      *network.Tailscale
	TaskDispatcher *task.Dispatcher
	EventRepo      repository.EventRepository
}

type BotSession

type BotSession struct {
	Id           string                     `json:"id" redis:"id"`
	Messages     []BotChatCompletionMessage `json:"messages" redis:"messages"`
	CreatedAt    int64                      `json:"created_at" redis:"created_at"`
	EventHistory []*BotEvent                `json:"event_history" redis:"event_history"`
}

func (*BotSession) GetMessagesInOpenAIFormat

func (s *BotSession) GetMessagesInOpenAIFormat() []openai.ChatCompletionMessage

type BotTask

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

func (*BotTask) Cancel

func (t *BotTask) Cancel(ctx context.Context, reason types.TaskCancellationReason) error

func (*BotTask) Execute

func (t *BotTask) Execute(ctx context.Context, options ...interface{}) error

func (*BotTask) HeartBeat

func (t *BotTask) HeartBeat(ctx context.Context) (bool, error)

func (*BotTask) Message

func (t *BotTask) Message() *types.TaskMessage

func (*BotTask) Metadata

func (t *BotTask) Metadata() types.TaskMetadata

func (*BotTask) Retry

func (t *BotTask) Retry(ctx context.Context) error

type BotTransitionConfig

type BotTransitionConfig struct {
	Cpu           int64          `json:"cpu" redis:"cpu"`
	Gpu           types.GpuType  `json:"gpu" redis:"gpu"`
	Memory        int64          `json:"memory" redis:"memory"`
	PythonVersion string         `json:"python_version" redis:"python_version"`
	ImageId       string         `json:"image_id" redis:"image_id"`
	Timeout       int            `json:"timeout" redis:"timeout"`
	KeepWarm      int            `json:"keep_warm" redis:"keep_warm"`
	MaxPending    int            `json:"max_pending" redis:"max_pending"`
	Volumes       []string       `json:"volumes" redis:"volumes"`
	Secrets       []string       `json:"secrets" redis:"secrets"`
	Handler       string         `json:"handler" redis:"handler"`
	OnStart       string         `json:"on_start" redis:"on_start"`
	CallbackUrl   string         `json:"callback_url" redis:"callback_url"`
	TaskPolicy    string         `json:"task_policy" redis:"task_policy"`
	Name          string         `json:"name" redis:"name"`
	Inputs        map[string]int `json:"inputs" redis:"inputs"`
	Outputs       []string       `json:"outputs" redis:"outputs"`
	Description   string         `json:"description" redis:"description"`
	Expose        bool           `json:"expose" redis:"expose"`
	Confirm       bool           `json:"confirm" redis:"confirm"`
}

BotTransitionConfig holds the config for a transition

func (*BotTransitionConfig) FormatTransition

func (t *BotTransitionConfig) FormatTransition() string

type BotTransitionResponse

type BotTransitionResponse struct {
	Msg string `json:"msg" redis:"msg"`
}

type BotUserResponse

type BotUserResponse struct {
	Msg            string `json:"msg" redis:"msg"`
	MarkerData     Marker `json:"marker_data" redis:"marker_data"`
	CompleteMarker bool   `json:"complete_marker" redis:"complete_marker"`
}

type Marker

type Marker struct {
	LocationName string        `json:"location_name" mapstructure:"location_name"`
	Fields       []MarkerField `json:"marker_data" mapstructure:"marker_data"`
	SourceTaskId string        `json:"source_task_id" mapstructure:"source_task_id"`
}

type MarkerField

type MarkerField struct {
	FieldName  string `json:"field_name" mapstructure:"field_name"`
	FieldValue string `json:"field_value" mapstructure:"field_value"`
}

type MetadataKey

type MetadataKey string
const (
	MetadataRequestId      MetadataKey = "request_id"
	MetadataSessionId      MetadataKey = "session_id"
	MetadataTransitionName MetadataKey = "transition_name"
	MetadataTaskId         MetadataKey = "task_id"
	MetadataErrorMsg       MetadataKey = "error_msg"
)

type PetriBotService

type PetriBotService struct {
	pb.UnimplementedBotServiceServer
	// contains filtered or unexported fields
}

func (*PetriBotService) PopBotTask

func (*PetriBotService) PushBotEvent

func (*PetriBotService) PushBotEventBlocking

func (*PetriBotService) PushBotMarkers

Jump to

Keyboard shortcuts

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