js

package
v0.4.35 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateEmbeddingsStepObject

func CreateEmbeddingsStepObject(runtime *goja.Runtime, loop *eventloop.EventLoop, provider steps.Step[string, []float32]) (*goja.Object, error)

Example usage with embeddings step

func CreateStepObject

func CreateStepObject[T any, U any](
	runtime *goja.Runtime,
	loop *eventloop.EventLoop,
	step steps.Step[T, U],
	inputConverter func(goja.Value) T,
	outputConverter func(U) goja.Value,
) (*goja.Object, error)

CreateStepObject creates a JavaScript object wrapping a Step with Promise, blocking and callback APIs

func NewJSLambdaStep

func NewJSLambdaStep[T any, U any](
	runtime *goja.Runtime,
	fn goja.Callable,
	inputConverter func(T) goja.Value,
	outputConverter func(goja.Value) (U, error),
) steps.Step[T, U]

Helper to create a LambdaStep from a JavaScript function

func RegisterConversation

func RegisterConversation(runtime *goja.Runtime) error

RegisterConversation registers the Conversation constructor in the JavaScript runtime

func RegisterEmbeddings

func RegisterEmbeddings(runtime *goja.Runtime, globalName string, provider embeddings.Provider, loop *eventloop.EventLoop) error

RegisterEmbeddings registers the embeddings functionality in the given Goja runtime

func RegisterFactory

func RegisterFactory(runtime *goja.Runtime, loop *eventloop.EventLoop, stepSettings *settings.StepSettings) error

RegisterFactory registers the chat step factory functionality in the JavaScript runtime

func RegisterStep

func RegisterStep[T any, U any](
	runtime *goja.Runtime,
	loop *eventloop.EventLoop,
	name string,
	step steps.Step[T, U],
	inputConverter func(goja.Value) T,
	outputConverter func(U) goja.Value,
) error

RegisterStep is kept for backward compatibility

Types

type CallbackFunctions

type CallbackFunctions struct {
	OnResult goja.Callable
	OnError  goja.Callable
	OnDone   goja.Callable
	OnCancel goja.Callable
}

type JSConversation

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

JSConversation wraps a conversation.Manager to expose it to JavaScript

func NewJSConversation

func NewJSConversation(runtime *goja.Runtime) *JSConversation

func (*JSConversation) AddMessage

func (jc *JSConversation) AddMessage(role string, text string, options *goja.Object) (string, error)

AddMessage adds a new chat message to the conversation

func (*JSConversation) AddMessageWithImage

func (jc *JSConversation) AddMessageWithImage(role string, text string, imagePath string) (string, error)

AddMessageWithImage adds a chat message with an attached image

func (*JSConversation) AddToolResult

func (jc *JSConversation) AddToolResult(toolID string, result string) (string, error)

AddToolResult adds a tool result message

func (*JSConversation) AddToolUse

func (jc *JSConversation) AddToolUse(toolID string, name string, input interface{}) (string, error)

AddToolUse adds a tool use message

func (*JSConversation) GetMessageView

func (jc *JSConversation) GetMessageView(messageID string) (string, error)

GetMessageView returns a formatted view of a specific message

func (*JSConversation) GetMessages

func (jc *JSConversation) GetMessages() conversation.Conversation

GetMessages returns all messages in the conversation

func (*JSConversation) GetSinglePrompt

func (jc *JSConversation) GetSinglePrompt() string

GetSinglePrompt returns the conversation as a single prompt string

func (*JSConversation) ToGoConversation

func (jc *JSConversation) ToGoConversation() conversation.Conversation

ToGoConversation returns the underlying Go conversation

func (*JSConversation) UpdateMetadata

func (jc *JSConversation) UpdateMetadata(messageID string, metadata map[string]interface{}) (bool, error)

UpdateMetadata updates a message's metadata

type JSEmbeddingsWrapper

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

type JSStepWrapper

type JSStepWrapper[T any, U any] struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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