title.go

 1package agent
 2
 3import (
 4	"context"
 5
 6	"github.com/cloudwego/eino/schema"
 7	"github.com/kujtimiihoxha/termai/internal/llm/models"
 8	"github.com/spf13/viper"
 9)
10
11func GenerateTitle(ctx context.Context, content string) (string, error) {
12	model, err := models.GetModel(ctx, models.ModelID(viper.GetString("models.small")))
13	if err != nil {
14		return "", err
15	}
16	out, err := model.Generate(
17		ctx,
18		[]*schema.Message{
19			schema.SystemMessage(`- you will generate a short title based on the first message a user begins a conversation with
20      - ensure it is not more than 80 characters long
21      - the title should be a summary of the user's message
22      - do not use quotes or colons
23      - the entire text you return will be used as the title`),
24			schema.UserMessage(content),
25		},
26	)
27	if err != nil {
28		return "", err
29	}
30	return out.Content, nil
31}