Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go/ai/embedder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type EmbedderOptions struct {

// embedder is an action with functions specific to converting documents to multidimensional vectors such as Embed().
type embedder struct {
core.ActionDef[*EmbedRequest, *EmbedResponse, struct{}]
core.Action[*EmbedRequest, *EmbedResponse, struct{}, struct{}]
}

// NewEmbedder creates a new [Embedder].
Expand Down Expand Up @@ -127,7 +127,7 @@ func NewEmbedder(name string, opts *EmbedderOptions, fn EmbedderFunc) Embedder {
}

return &embedder{
ActionDef: *core.NewAction(name, api.ActionTypeEmbedder, metadata, inputSchema, fn),
Action: *core.NewAction(name, api.ActionTypeEmbedder, metadata, inputSchema, fn),
}
}

Expand All @@ -143,12 +143,12 @@ func DefineEmbedder(r api.Registry, name string, opts *EmbedderOptions, fn Embed
// It will try to resolve the embedder dynamically if the embedder is not found.
// It returns nil if the embedder was not resolved.
func LookupEmbedder(r api.Registry, name string) Embedder {
action := core.ResolveActionFor[*EmbedRequest, *EmbedResponse, struct{}](r, api.ActionTypeEmbedder, name)
action := core.ResolveActionFor[*EmbedRequest, *EmbedResponse, struct{}, struct{}](r, api.ActionTypeEmbedder, name)
if action == nil {
return nil
}
return &embedder{
ActionDef: *action,
Action: *action,
}
}

Expand Down
10 changes: 5 additions & 5 deletions go/ai/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (e EvaluatorRef) Config() any {

// evaluator is an action with functions specific to evaluating a dataset.
type evaluator struct {
core.ActionDef[*EvaluatorRequest, *EvaluatorResponse, struct{}]
core.Action[*EvaluatorRequest, *EvaluatorResponse, struct{}, struct{}]
}

// Example is a single example that requires evaluation
Expand Down Expand Up @@ -190,7 +190,7 @@ func NewEvaluator(name string, opts *EvaluatorOptions, fn EvaluatorFunc) Evaluat
}

return &evaluator{
ActionDef: *core.NewAction(name, api.ActionTypeEvaluator, metadata, inputSchema, func(ctx context.Context, req *EvaluatorRequest) (output *EvaluatorResponse, err error) {
Action: *core.NewAction(name, api.ActionTypeEvaluator, metadata, inputSchema, func(ctx context.Context, req *EvaluatorRequest) (output *EvaluatorResponse, err error) {
var results []EvaluationResult
for _, datapoint := range req.Dataset {
if datapoint.TestCaseId == "" {
Expand Down Expand Up @@ -275,7 +275,7 @@ func NewBatchEvaluator(name string, opts *EvaluatorOptions, fn BatchEvaluatorFun
}

return &evaluator{
ActionDef: *core.NewAction(name, api.ActionTypeEvaluator, metadata, nil, fn),
Action: *core.NewAction(name, api.ActionTypeEvaluator, metadata, nil, fn),
}
}

Expand All @@ -291,12 +291,12 @@ func DefineBatchEvaluator(r api.Registry, name string, opts *EvaluatorOptions, f
// LookupEvaluator looks up an [Evaluator] registered by [DefineEvaluator].
// It returns nil if the evaluator was not defined.
func LookupEvaluator(r api.Registry, name string) Evaluator {
action := core.ResolveActionFor[*EvaluatorRequest, *EvaluatorResponse, struct{}](r, api.ActionTypeEvaluator, name)
action := core.ResolveActionFor[*EvaluatorRequest, *EvaluatorResponse, struct{}, struct{}](r, api.ActionTypeEvaluator, name)
if action == nil {
return nil
}
return &evaluator{
ActionDef: *action,
Action: *action,
}
}

Expand Down
12 changes: 6 additions & 6 deletions go/ai/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ type ModelMiddleware = core.Middleware[*ModelRequest, *ModelResponse, *ModelResp

// model is an action with functions specific to model generation such as Generate().
type model struct {
core.ActionDef[*ModelRequest, *ModelResponse, *ModelResponseChunk]
core.Action[*ModelRequest, *ModelResponse, *ModelResponseChunk, struct{}]
}

// generateAction is the type for a utility model generation action that takes in a GenerateActionOptions instead of a ModelRequest.
type generateAction = core.ActionDef[*GenerateActionOptions, *ModelResponse, *ModelResponseChunk]
type generateAction = core.Action[*GenerateActionOptions, *ModelResponse, *ModelResponseChunk, struct{}]

// result is a generic struct for parallel operation results with index, value, and error.
type result[T any] struct {
Expand Down Expand Up @@ -191,12 +191,12 @@ func DefineModel(r api.Registry, name string, opts *ModelOptions, fn ModelFunc)
// It will try to resolve the model dynamically if the model is not found.
// It returns nil if the model was not resolved.
func LookupModel(r api.Registry, name string) Model {
action := core.ResolveActionFor[*ModelRequest, *ModelResponse, *ModelResponseChunk](r, api.ActionTypeModel, name)
action := core.ResolveActionFor[*ModelRequest, *ModelResponse, *ModelResponseChunk, struct{}](r, api.ActionTypeModel, name)
if action == nil {
return nil
}
return &model{
ActionDef: *action,
Action: *action,
}
}

Expand Down Expand Up @@ -699,7 +699,7 @@ func (m *model) Generate(ctx context.Context, req *ModelRequest, cb ModelStreamC
return nil, core.NewError(core.INVALID_ARGUMENT, "Model.Generate: generate called on a nil model; check that all models are defined")
}

return m.ActionDef.Run(ctx, req, cb)
return m.Action.Run(ctx, req, cb)
}

// supportsConstrained returns whether the model supports constrained output.
Expand All @@ -708,7 +708,7 @@ func (m *model) supportsConstrained(hasTools bool) bool {
return false
}

metadata := m.ActionDef.Desc().Metadata
metadata := m.Action.Desc().Metadata
if metadata == nil {
return false
}
Expand Down
12 changes: 6 additions & 6 deletions go/ai/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Prompt interface {

// prompt is a prompt template that can be executed to generate a model response.
type prompt struct {
core.ActionDef[any, *GenerateActionOptions, struct{}]
core.Action[any, *GenerateActionOptions, struct{}, struct{}]
promptOptions
registry api.Registry
}
Expand Down Expand Up @@ -124,21 +124,21 @@ func DefinePrompt(r api.Registry, name string, opts ...PromptOption) Prompt {
metadata["prompt"] = promptMetadata
}

p.ActionDef = *core.DefineAction(r, name, api.ActionTypeExecutablePrompt, metadata, p.InputSchema, p.buildRequest)
p.Action = *core.DefineAction(r, name, api.ActionTypeExecutablePrompt, metadata, p.InputSchema, p.buildRequest)

return p
}

// LookupPrompt looks up a [Prompt] registered by [DefinePrompt].
// It returns nil if the prompt was not defined.
func LookupPrompt(r api.Registry, name string) Prompt {
action := core.ResolveActionFor[any, *GenerateActionOptions, struct{}](r, api.ActionTypeExecutablePrompt, name)
action := core.ResolveActionFor[any, *GenerateActionOptions, struct{}, struct{}](r, api.ActionTypeExecutablePrompt, name)
if action == nil {
return nil
}
return &prompt{
ActionDef: *action,
registry: r,
Action: *action,
registry: r,
}
}

Expand Down Expand Up @@ -312,7 +312,7 @@ func (p *prompt) Render(ctx context.Context, input any) (*GenerateActionOptions,

// Desc returns a descriptor of the prompt with resolved schema references.
func (p *prompt) Desc() api.ActionDesc {
desc := p.ActionDef.Desc()
desc := p.Action.Desc()
promptMeta := desc.Metadata["prompt"].(map[string]any)
if inputMeta, ok := promptMeta["input"].(map[string]any); ok {
if inputSchema, ok := inputMeta["schema"].(map[string]any); ok {
Expand Down
14 changes: 7 additions & 7 deletions go/ai/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type ResourceFunc = func(context.Context, *ResourceInput) (*ResourceOutput, erro
// It holds the underlying core action and allows looking up resources
// by name without knowing their specific input/output api.
type resource struct {
core.ActionDef[*ResourceInput, *ResourceOutput, struct{}]
core.Action[*ResourceInput, *ResourceOutput, struct{}, struct{}]
}

// Resource represents an instance of a resource.
Expand All @@ -129,15 +129,15 @@ type Resource interface {
// DefineResource creates a resource and registers it with the given Registry.
func DefineResource(r api.Registry, name string, opts *ResourceOptions, fn ResourceFunc) Resource {
metadata := resourceMetadata(name, opts)
return &resource{ActionDef: *core.DefineAction(r, name, api.ActionTypeResource, metadata, nil, fn)}
return &resource{Action: *core.DefineAction(r, name, api.ActionTypeResource, metadata, nil, fn)}
}

// NewResource creates a resource but does not register it in the registry.
// It can be registered later via the Register method.
func NewResource(name string, opts *ResourceOptions, fn ResourceFunc) Resource {
metadata := resourceMetadata(name, opts)
metadata["dynamic"] = true
return &resource{ActionDef: *core.NewAction(name, api.ActionTypeResource, metadata, nil, fn)}
return &resource{Action: *core.NewAction(name, api.ActionTypeResource, metadata, nil, fn)}
}

// resourceMetadata creates the metadata common to both DefineResource and NewResource.
Expand Down Expand Up @@ -227,8 +227,8 @@ func (r *resource) Execute(ctx context.Context, input *ResourceInput) (*Resource
// FindMatchingResource finds a resource that matches the given URI.
func FindMatchingResource(r api.Registry, uri string) (Resource, *ResourceInput, error) {
for _, a := range r.ListActions() {
if action, ok := a.(*core.ActionDef[*ResourceInput, *ResourceOutput, struct{}]); ok {
res := &resource{ActionDef: *action}
if action, ok := a.(*core.Action[*ResourceInput, *ResourceOutput, struct{}, struct{}]); ok {
res := &resource{Action: *action}
if res.Matches(uri) {
variables, err := res.ExtractVariables(uri)
if err != nil {
Expand All @@ -244,9 +244,9 @@ func FindMatchingResource(r api.Registry, uri string) (Resource, *ResourceInput,

// LookupResource looks up the resource in the registry by provided name and returns it.
func LookupResource(r api.Registry, name string) Resource {
action := core.ResolveActionFor[*ResourceInput, *ResourceOutput, struct{}](r, api.ActionTypeResource, name)
action := core.ResolveActionFor[*ResourceInput, *ResourceOutput, struct{}, struct{}](r, api.ActionTypeResource, name)
if action == nil {
return nil
}
return &resource{ActionDef: *action}
return &resource{Action: *action}
}
8 changes: 4 additions & 4 deletions go/ai/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Retriever interface {

// retriever is an action with functions specific to document retrieval such as Retrieve().
type retriever struct {
core.ActionDef[*RetrieverRequest, *RetrieverResponse, struct{}]
core.Action[*RetrieverRequest, *RetrieverResponse, struct{}, struct{}]
}

// RetrieverArg is the interface for retriever arguments. It can either be the retriever action itself or a reference to be looked up.
Expand Down Expand Up @@ -121,7 +121,7 @@ func NewRetriever(name string, opts *RetrieverOptions, fn RetrieverFunc) Retriev
}

return &retriever{
ActionDef: *core.NewAction(name, api.ActionTypeRetriever, metadata, inputSchema, fn),
Action: *core.NewAction(name, api.ActionTypeRetriever, metadata, inputSchema, fn),
}
}

Expand All @@ -136,12 +136,12 @@ func DefineRetriever(r api.Registry, name string, opts *RetrieverOptions, fn Ret
// It will try to resolve the retriever dynamically if the retriever is not found.
// It returns nil if the retriever was not resolved.
func LookupRetriever(r api.Registry, name string) Retriever {
action := core.ResolveActionFor[*RetrieverRequest, *RetrieverResponse, struct{}](r, api.ActionTypeRetriever, name)
action := core.ResolveActionFor[*RetrieverRequest, *RetrieverResponse, struct{}, struct{}](r, api.ActionTypeRetriever, name)
if action == nil {
return nil
}
return &retriever{
ActionDef: *action,
Action: *action,
}
}

Expand Down
Loading
Loading