Refactor Knowledge struct into shared package
Moved the Knowledge struct and related types to the shared package, updating all references across the codebase. This improves modularity and enables better reuse of the Knowledge type across different components.
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.stevedudenhoeffer.com/steve/answer/pkg/agents"
|
||||
|
||||
gollm "gitea.stevedudenhoeffer.com/steve/go-llm"
|
||||
)
|
||||
|
||||
@@ -27,7 +25,7 @@ const DefaultPrompt = `Use the provided tools to answer the questions in your cu
|
||||
// source is the source of the knowledge, for example a URL.
|
||||
// Any tool call that returns a Knowledge object will be handled by this function in crafting the final Knowledge object.
|
||||
// Any other return type will be passed to the resultWorker function, if provided.
|
||||
func (w KnowledgeWorker) Answer(context context.Context, knowledge *agents.Knowledge, systemPrompt string, userInput string, source string, history []gollm.Message, resultWorker func(res gollm.ToolCallResponse)) (agents.Knowledge, error) {
|
||||
func (w KnowledgeWorker) Answer(context context.Context, knowledge *Knowledge, systemPrompt string, userInput string, source string, history []gollm.Message, resultWorker func(res gollm.ToolCallResponse)) (Knowledge, error) {
|
||||
var req gollm.Request
|
||||
|
||||
if systemPrompt != "" {
|
||||
@@ -80,7 +78,7 @@ func (w KnowledgeWorker) Answer(context context.Context, knowledge *agents.Knowl
|
||||
func(ctx *gollm.Context, args struct {
|
||||
NotesToSelf []string `description:"Notes to leave for yourself for later."`
|
||||
}) (any, error) {
|
||||
return agents.Knowledge{
|
||||
return Knowledge{
|
||||
NotesToSelf: args.NotesToSelf,
|
||||
}, nil
|
||||
}),
|
||||
@@ -90,7 +88,7 @@ func (w KnowledgeWorker) Answer(context context.Context, knowledge *agents.Knowl
|
||||
func(ctx *gollm.Context, args struct {
|
||||
Objectives []string `description:"The objectives to set for executions going forward."`
|
||||
}) (any, error) {
|
||||
return agents.Knowledge{
|
||||
return Knowledge{
|
||||
CurrentObjectives: args.Objectives,
|
||||
}, nil
|
||||
}),
|
||||
@@ -100,13 +98,13 @@ func (w KnowledgeWorker) Answer(context context.Context, knowledge *agents.Knowl
|
||||
func(ctx *gollm.Context, args struct {
|
||||
Info []string `description:"The information to learn from the input."`
|
||||
}) (any, error) {
|
||||
var k []agents.TidBit
|
||||
var k []TidBit
|
||||
|
||||
for _, i := range args.Info {
|
||||
k = append(k, agents.TidBit{Info: i, Source: source})
|
||||
k = append(k, TidBit{Info: i, Source: source})
|
||||
}
|
||||
|
||||
return agents.Knowledge{
|
||||
return Knowledge{
|
||||
Knowledge: k,
|
||||
}, nil
|
||||
})).
|
||||
@@ -120,17 +118,17 @@ func (w KnowledgeWorker) Answer(context context.Context, knowledge *agents.Knowl
|
||||
|
||||
resp, err := w.Model.ChatComplete(context, req)
|
||||
if err != nil {
|
||||
return agents.Knowledge{}, fmt.Errorf("error calling model: %w", err)
|
||||
return Knowledge{}, fmt.Errorf("error calling model: %w", err)
|
||||
}
|
||||
|
||||
if len(resp.Choices) == 0 {
|
||||
return agents.Knowledge{}, fmt.Errorf("no choices found")
|
||||
return Knowledge{}, fmt.Errorf("no choices found")
|
||||
}
|
||||
|
||||
choice := resp.Choices[0]
|
||||
|
||||
if len(choice.Calls) == 0 {
|
||||
return agents.Knowledge{}, fmt.Errorf("no calls found")
|
||||
return Knowledge{}, fmt.Errorf("no calls found")
|
||||
}
|
||||
|
||||
var callNames []string
|
||||
@@ -141,14 +139,14 @@ func (w KnowledgeWorker) Answer(context context.Context, knowledge *agents.Knowl
|
||||
results, err := w.ToolBox.ExecuteCallbacks(gollm.NewContext(context, req, &choice, nil), choice.Calls, w.OnNewFunction, w.OnFunctionFinished)
|
||||
|
||||
if err != nil {
|
||||
return agents.Knowledge{}, fmt.Errorf("error executing callbacks: %w", err)
|
||||
return Knowledge{}, fmt.Errorf("error executing callbacks: %w", err)
|
||||
}
|
||||
|
||||
var res = agents.Knowledge{}
|
||||
var res = Knowledge{}
|
||||
|
||||
for _, r := range results {
|
||||
switch v := r.Result.(type) {
|
||||
case agents.Knowledge:
|
||||
case Knowledge:
|
||||
res = res.Absorb(v)
|
||||
|
||||
default:
|
||||
|
Reference in New Issue
Block a user