assist

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MessageClasses = map[string]string{
	"command execution": "the user want to execute a command on one or many servers",
	"troubleshooting":   "the user wants to diagnose a problem or understand an error message",
	"configuration":     "the user wants to generate configuration for a software which is not Teleport",
	"manage resources":  "the user wants to list/add/remove/edit resources connected to the Teleport cluster",
	"access request":    "the user requests access to one or many resources from the Teleport cluster",
	"teleport setup":    "the user wants help with its Teleport cluster, like setting up a new feature or knowing if something is feasible",
	"other":             "the user asks a question which is not IT nor Teleport-related",
}

MessageClasses contains type of assist message we expect users to send. When running on Cloud we attempt to classify user messages in one of those categories. If this succeeds, we send an event into the analytics pipeline.

Keys are the category names, those are the ones reported in the event and generated by the model. Values are the category description. They are used to build the model prompt and allow to provide more context to the model to improve the classification.

Functions

This section is empty.

Types

type Assist

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

Assist is the Teleport Assist client.

func NewClient

func NewClient(ctx context.Context, proxyClient PluginGetter,
	proxySettings any, openaiCfg *openai.ClientConfig) (*Assist, error)

NewClient creates a new Assist client.

func (*Assist) ClassifyMessage

func (a *Assist) ClassifyMessage(ctx context.Context, message string, classes map[string]string) (string, error)

ClassifyMessage takes a user message, a list of categories, and uses the AI mode as a zero-shot classifier. It returns an error if the classification result is not a valid class.

func (*Assist) GenerateCommandSummary

func (a *Assist) GenerateCommandSummary(ctx context.Context, messages []*assist.AssistantMessage, output map[string][]byte) (string, *tokens.TokenCount, error)

GenerateCommandSummary summarizes the output of a command executed on one or many nodes. The conversation history is also sent into the prompt in order to gather context and know what information is relevant in the command output.

func (*Assist) GenerateSummary

func (a *Assist) GenerateSummary(ctx context.Context, message string) (string, error)

GenerateSummary generates a summary for the given message.

func (*Assist) NewChat

func (a *Assist) NewChat(ctx context.Context, assistService MessageService, toolContext *tools.ToolContext,
	conversationID string,
) (*Chat, error)

NewChat creates a new Assist chat.

func (*Assist) NewLightweightChat

func (a *Assist) NewLightweightChat(username string) (*LightweightChat, error)

NewLightweightChat creates a new Assist chat what doesn't store the history of the conversation.

func (*Assist) NewSSHCommand

func (a *Assist) NewSSHCommand(username string) (*ai.Chat, error)

func (*Assist) RunTool

func (a *Assist) RunTool(ctx context.Context, onMessage onMessageFunc, toolName, userInput string, toolContext *tools.ToolContext,
) (*tokens.TokenCount, error)

RunTool runs a model tool without an ai.Chat.

type Chat

type Chat struct {

	// ConversationID is the ID of the conversation.
	ConversationID string
	// Username is the username of the user who started the chat.
	Username string
	// contains filtered or unexported fields
}

Chat is a Teleport Assist chat.

func (*Chat) IsNewConversation

func (c *Chat) IsNewConversation() bool

IsNewConversation returns true if the conversation has no messages yet.

func (*Chat) ProcessComplete

func (c *Chat) ProcessComplete(ctx context.Context, onMessage onMessageFunc, userInput string,
) (*tokens.TokenCount, error)

ProcessComplete processes the completion request and returns the number of tokens used.

func (*Chat) RecordMesssage

func (c *Chat) RecordMesssage(ctx context.Context, kind MessageType, payload string) error

RecordMessage is used to record out-of-band messages such as hidden acknowledgements.

type CommandExecSummary

type CommandExecSummary struct {
	ExecutionID string `json:"execution_id"`
	Summary     string `json:"summary"`
	Command     string `json:"command"`
}

CommandExecSummary is a payload for the COMMAND_RESULT_SUMMARY message.

func (CommandExecSummary) String

func (s CommandExecSummary) String() string

String implements the Stringer interface and formats the message for AI model consumption.

type LightweightChat

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

LightweightChat is a Teleport Assist chat that doesn't store the history of the conversation.

func (*LightweightChat) ProcessComplete

func (c *LightweightChat) ProcessComplete(ctx context.Context, onMessage onMessageFunc, userInput string,
) (*tokens.TokenCount, error)

ProcessComplete processes a user message and returns the assistant's response.

type MessageService

type MessageService interface {
	// GetAssistantMessages returns all messages with given conversation ID.
	GetAssistantMessages(ctx context.Context, req *assist.GetAssistantMessagesRequest) (*assist.GetAssistantMessagesResponse, error)

	// CreateAssistantMessage adds the message to the backend.
	CreateAssistantMessage(ctx context.Context, msg *assist.CreateAssistantMessageRequest) error
}

MessageService is the minimal interface used by the chat to interact with the Assist message service in the backend.

type MessageType

type MessageType string

MessageType is a type of the Assist message.

const (
	// MessageKindCommand is the type of Assist message that contains the command to execute.
	MessageKindCommand MessageType = "COMMAND"
	// MessageKindCommandResult is the type of Assist message that contains the command execution result.
	MessageKindCommandResult MessageType = "COMMAND_RESULT"
	// MessageKindAccessRequest is the type of Assist message that contains the access request.
	// Sent by the backend when it wants the frontend to display a prompt to the user.
	MessageKindAccessRequest MessageType = "ACCESS_REQUEST"
	// MessageKindAccessRequestCreated is a marker message to indicate that an access request was created.
	// Sent by the frontend to the backend to indicate that it was created to future loads of the conversation.
	MessageKindAccessRequestCreated MessageType = "ACCESS_REQUEST_CREATED"
	// MessageKindCommandResultSummary is the type of message that is optionally
	// emitted after a command and contains a summary of the command output.
	// This message is both sent after the command execution to the web UI,
	// and persisted in the conversation history.
	MessageKindCommandResultSummary MessageType = "COMMAND_RESULT_SUMMARY"
	// MessageKindUserMessage is the type of Assist message that contains the user message.
	MessageKindUserMessage MessageType = "CHAT_MESSAGE_USER"
	// MessageKindAssistantMessage is the type of Assist message that contains the assistant message.
	MessageKindAssistantMessage MessageType = "CHAT_MESSAGE_ASSISTANT"
	// MessageKindAssistantPartialMessage is the type of Assist message that contains the assistant partial message.
	MessageKindAssistantPartialMessage MessageType = "CHAT_PARTIAL_MESSAGE_ASSISTANT"
	// MessageKindAssistantPartialFinalize is the type of Assist message that ends the partial message stream.
	MessageKindAssistantPartialFinalize MessageType = "CHAT_PARTIAL_MESSAGE_ASSISTANT_FINALIZE"
	// MessageKindSystemMessage is the type of Assist message that contains the system message.
	MessageKindSystemMessage MessageType = "CHAT_MESSAGE_SYSTEM"
	// MessageKindError is the type of Assist message that is presented to user as information, but not stored persistently in the conversation. This can include backend error messages and the like.
	MessageKindError MessageType = "CHAT_MESSAGE_ERROR"
	// MessageKindProgressUpdate is the type of Assist message that contains a progress update.
	// A progress update starts a new "stage" and ends a previous stage if there was one.
	MessageKindProgressUpdate MessageType = "CHAT_MESSAGE_PROGRESS_UPDATE"
)

type PluginGetter

type PluginGetter interface {
	PluginsClient() pluginsv1.PluginServiceClient
}

PluginGetter is the minimal interface used by the chat to interact with the plugin service in the backend.

Jump to

Keyboard shortcuts

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