api

package
v0.0.0-...-b6acc2a Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: MIT Imports: 8 Imported by: 5

Documentation

Index

Constants

View Source
const (
	VersionMajor = 1
	VersionMinor = 0

	ProtocolVersion  = VersionMajor
	MagicCookieKey   = "LAZYGPT_PLUGIN_MAGIC_COOKIE"
	MagicCookieValue = "678363c73a70838a84ea7f90a1c7bdfc6e80e8560e50ea75e0a6ca906d00c881"
)

Variables

View Source
var ErrNotGRPC = errors.New("only gRPC plugins supported")

ErrNotGRPC is returned when a plugin is not a gRPC plugin.

Functions

func HandshakeConfig

func HandshakeConfig() plugin.HandshakeConfig

HandshakeConfig returns a plugin.HandshakeConfig with the proper magic cookie values to use for this protocol version.

func InitLogging

func InitLogging(ctx context.Context, name string) context.Context

InitLogging initializes a logger in the context.

func Plugins

func Plugins() map[string]plugin.Plugin

func Version

func Version() string

Version returns the string representation of the protocol version.

Types

type Completion

type Completion interface {
	// Complete returns a list of possible completions for the given input.
	Complete(ctx context.Context, messages []Message) (*Message, Reason, error)
}

Completion is the interface that plugins must implement to provide completion suggestions.

type CompletionGRPCClient

type CompletionGRPCClient struct {
	Client CompletionClient
}

CompletionGRPCClient is the gRPC client implementation of the plugin.

func NewCompletionGRPCClient

func NewCompletionGRPCClient(client CompletionClient) *CompletionGRPCClient

NewCompletionGRPCClient returns a new CompletionGRPCClient.

func (*CompletionGRPCClient) Complete

func (c *CompletionGRPCClient) Complete(
	ctx context.Context,
	messages []Message,
) (*Message, Reason, error)

Complete implements the gRPC client for the completion plugin.

type CompletionGRPCServer

type CompletionGRPCServer struct {
	UnimplementedCompletionServer

	Impl Completion
}

CompletionGRPCServer is the gRPC server implementation of the plugin.

func NewCompletionGRPCServer

func NewCompletionGRPCServer(impl Completion) *CompletionGRPCServer

NewCompletionGRPCServer returns a new CompletionGRPCServer.

func (*CompletionGRPCServer) Complete

func (s *CompletionGRPCServer) Complete(
	ctx context.Context,
	req *CompletionRequest,
) (*CompletionResponse, error)

Complete implements the gRPC server for the completion plugin.

type Embedding

type Embedding interface {
	// Embedding returns the embedding for the given input.
	Embedding(ctx context.Context, input string) ([]float32, error)
}

Embedding is the interface that plugins must implement to provide embedding functionality.

type EmbeddingGRPCClient

type EmbeddingGRPCClient struct {
	Client EmbeddingClient
}

EmbeddingGRPCClient is the gRPC client implementation of the plugin.

func NewEmbeddingGRPCClient

func NewEmbeddingGRPCClient(client EmbeddingClient) *EmbeddingGRPCClient

NewEmbeddingGRPCClient returns a new EmbeddingGRPCClient.

func (*EmbeddingGRPCClient) Embedding

func (c *EmbeddingGRPCClient) Embedding(
	ctx context.Context,
	input string,
) ([]float32, error)

Embedding implements the gRPC client for the embedding plugin.

type EmbeddingGRPCServer

type EmbeddingGRPCServer struct {
	UnimplementedEmbeddingServer

	Impl Embedding
}

EmbeddingGRPCServer is the gRPC server implementation of the plugin.

func NewEmbeddingGRPCServer

func NewEmbeddingGRPCServer(impl Embedding) *EmbeddingGRPCServer

NewEmbeddingGRPCServer returns a new EmbeddingGRPCServer.

func (*EmbeddingGRPCServer) Embedding

func (s *EmbeddingGRPCServer) Embedding(
	ctx context.Context,
	req *EmbeddingRequest,
) (*EmbeddingResponse, error)

Embedding implements the gRPC server for the embedding plugin.

type Interfaces

type Interfaces interface {
	// Interfaces returns a list of interfaces that the plugin implements.
	Interfaces(ctx context.Context) ([]string, error)
}

Interfaces is the interface that plugins must implement to provide discovery of implemented interfaces.

type InterfacesGRPCClient

type InterfacesGRPCClient struct {
	Client InterfacesClient
}

InterfacesGRPCClient is the gRPC client implementation of the plugin.

func NewInterfacesGRPCClient

func NewInterfacesGRPCClient(client InterfacesClient) *InterfacesGRPCClient

NewInterfacesGRPCClient returns a new InterfacesGRPCClient.

func (*InterfacesGRPCClient) Interfaces

func (c *InterfacesGRPCClient) Interfaces(ctx context.Context) ([]string, error)

Interfaces implements the gRPC client for the interfaces plugin.

type InterfacesGRPCServer

type InterfacesGRPCServer struct {
	UnimplementedInterfacesServer

	Impl Interfaces
}

InterfacesGRPCServer is the gRPC server implementation of the plugin.

func NewInterfacesGRPCServer

func NewInterfacesGRPCServer(impl Interfaces) *InterfacesGRPCServer

NewInterfacesGRPCServer returns a new InterfacesGRPCServer.

func (*InterfacesGRPCServer) Interfaces

func (s *InterfacesGRPCServer) Interfaces(
	ctx context.Context,
	_ *InterfacesRequest,
) (*InterfacesResponse, error)

Interfaces implements the gRPC server for the interfaces plugin.

type Memory

type Memory interface {
	// Memorize memorizes each data string.
	Memorize(ctx context.Context, data []string) error

	// Recall recalls the memory closest to the data string. If a count is
	// specified, it returns the count closest memories.
	Recall(ctx context.Context, data string, count ...int) ([]string, error)
}

Memory is the interface that plugins must implement to provide memory functionality.

type MemoryGRPCClient

type MemoryGRPCClient struct {
	Client MemoryClient
}

MemoryGRPCClient is the gRPC client implementation of the plugin.

func NewMemoryGRPCClient

func NewMemoryGRPCClient(client MemoryClient) *MemoryGRPCClient

NewMemoryGRPCClient returns a new MemoryGRPCClient.

func (*MemoryGRPCClient) Memorize

func (c *MemoryGRPCClient) Memorize(
	ctx context.Context,
	data []string,
) error

Memorize implements the gRPC client for the memory plugin.

func (*MemoryGRPCClient) Recall

func (c *MemoryGRPCClient) Recall(
	ctx context.Context,
	data string,
	count ...int,
) ([]string, error)

Recall implements the gRPC client for the memory plugin.

type MemoryGRPCServer

type MemoryGRPCServer struct {
	UnimplementedMemoryServer

	Impl Memory
}

MemoryGRPCServer is the gRPC server implementation of the plugin.

func NewMemoryGRPCServer

func NewMemoryGRPCServer(impl Memory) *MemoryGRPCServer

NewMemoryGRPCServer returns a new MemoryGRPCServer.

func (*MemoryGRPCServer) Memorize

func (s *MemoryGRPCServer) Memorize(
	ctx context.Context,
	req *MemorizeRequest,
) (*MemorizeResponse, error)

Memorize implements the gRPC server for the memory plugin memorize method.

func (*MemoryGRPCServer) Recall

func (s *MemoryGRPCServer) Recall(
	ctx context.Context,
	req *RecallRequest,
) (*RecallResponse, error)

Recall implements the gRPC server for the memory plugin recall method.

type Message

type Message struct {
	Content string `json:"content"`
	Name    string `json:"name"`
	Role    string `json:"role"`
}

type Plugin

type Plugin struct {
	plugin.Plugin
	// contains filtered or unexported fields
}

func NewCompletionPlugin

func NewCompletionPlugin(completion Completion) *Plugin

NewCompletionPlugin returns a new CompletionPlugin.

func NewEmbeddingPlugin

func NewEmbeddingPlugin(embedding Embedding) *Plugin

NewEmbeddingPlugin returns a new EmbeddingPlugin.

func NewInterfacesPlugin

func NewInterfacesPlugin(interfaces Interfaces) *Plugin

NewInterfacesPlugin returns a new InterfacesPlugin.

func NewMemoryPlugin

func NewMemoryPlugin(memory Memory) *Plugin

NewMemoryPlugin returns a new MemoryPlugin.

func NewPlugin

func NewPlugin(
	register func(*grpc.Server),
	client func(*grpc.ClientConn) (interface{}, error),
) *Plugin

NewPlugin return a new plugin instance for the given plugin implementation.

func (*Plugin) Client

func (plugin *Plugin) Client(_ *plugin.MuxBroker, _ *rpc.Client) (interface{}, error)

Client always returns an error, we only support GRPC.

func (*Plugin) GRPCClient

func (plugin *Plugin) GRPCClient(
	_ context.Context,
	_ *plugin.GRPCBroker,
	client *grpc.ClientConn,
) (interface{}, error)

GRPCClient returns the plugin client.

func (*Plugin) GRPCServer

func (plugin *Plugin) GRPCServer(_ *plugin.GRPCBroker, srv *grpc.Server) error

GRPCServer registers the plugin with the gRPC server.

func (*Plugin) Server

func (plugin *Plugin) Server(_ *plugin.MuxBroker) (interface{}, error)

Server always returns an error, we only support GRPC.

Jump to

Keyboard shortcuts

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