Files
eino-test/internal/tools/create_note.go
T

41 lines
1.2 KiB
Go

package tools
import (
"context"
"fmt"
"time"
"eino-test/internal/rag"
"eino-test/internal/store"
"github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/components/tool/utils"
)
type CreateNoteInput struct {
Title string `json:"title" jsonschema:"description=Note title,required"`
Content string `json:"content" jsonschema:"description=Markdown content of the note,required"`
Tags []string `json:"tags" jsonschema:"description=Tags for categorization"`
}
func NewCreateNoteTool(pipeline *rag.RAGPipeline) tool.InvokableTool {
t, _ := utils.InferTool("create_note", "Create a new note in the knowledge base.", func(ctx context.Context, input *CreateNoteInput) (string, error) {
note := &store.Note{
ID: input.Title,
Title: input.Title,
Content: input.Content,
Tags: input.Tags,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if err := pipeline.NoteStore().Create(ctx, note); err != nil {
return "", fmt.Errorf("create note: %w", err)
}
if err := pipeline.IndexNote(ctx, note); err != nil {
return "", fmt.Errorf("index note: %w", err)
}
return fmt.Sprintf("Note created: %s", note.ID), nil
})
return t
}