36 lines
964 B
Go
36 lines
964 B
Go
package contentmodel
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"data-terminal-cloud/internal/callmemory"
|
||
|
|
"data-terminal-cloud/internal/extraction"
|
||
|
|
"encoding/json"
|
||
|
|
"errors"
|
||
|
|
"github.com/jackc/pgx/v5"
|
||
|
|
)
|
||
|
|
|
||
|
|
func (r *Registry) ExtractMemoryIntents(ctx context.Context, tenant string, turns []callmemory.SourceTurn, records []map[string]any) ([]callmemory.Intent, error) {
|
||
|
|
var generator extraction.Generator = r.fallback
|
||
|
|
item, e := r.active(ctx, tenant)
|
||
|
|
if e != nil && !errors.Is(e, pgx.ErrNoRows) {
|
||
|
|
return nil, e
|
||
|
|
}
|
||
|
|
if e == nil {
|
||
|
|
generator, e = r.generator(item)
|
||
|
|
if e != nil {
|
||
|
|
return nil, e
|
||
|
|
}
|
||
|
|
}
|
||
|
|
structured, ok := generator.(interface {
|
||
|
|
GenerateJSON(context.Context, string, string) (json.RawMessage, error)
|
||
|
|
})
|
||
|
|
if !ok {
|
||
|
|
return nil, errors.New("memory intent model is not configured")
|
||
|
|
}
|
||
|
|
raw, e := structured.GenerateJSON(ctx, callmemory.IntentInput(turns, records), callmemory.IntentPrompt)
|
||
|
|
if e != nil {
|
||
|
|
return nil, e
|
||
|
|
}
|
||
|
|
return callmemory.ParseIntents(raw)
|
||
|
|
}
|