refactor: use nil slices and preallocate where capacity is known
This commit is contained in:
parent
e8afd31b28
commit
9300e72e01
5 changed files with 10 additions and 9 deletions
|
|
@ -107,7 +107,7 @@ func (cb *ContextBuilder) buildToolsSection() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cb *ContextBuilder) BuildSystemPrompt() string {
|
func (cb *ContextBuilder) BuildSystemPrompt() string {
|
||||||
parts := []string{}
|
var parts []string
|
||||||
|
|
||||||
// Core identity section
|
// Core identity section
|
||||||
parts = append(parts, cb.getIdentity())
|
parts = append(parts, cb.getIdentity())
|
||||||
|
|
@ -158,8 +158,6 @@ func (cb *ContextBuilder) LoadBootstrapFiles() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary string, currentMessage string, media []string, channel, chatID string) []providers.Message {
|
func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary string, currentMessage string, media []string, channel, chatID string) []providers.Message {
|
||||||
messages := []providers.Message{}
|
|
||||||
|
|
||||||
systemPrompt := cb.BuildSystemPrompt()
|
systemPrompt := cb.BuildSystemPrompt()
|
||||||
|
|
||||||
// Add Current Session info if provided
|
// Add Current Session info if provided
|
||||||
|
|
@ -200,6 +198,8 @@ func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary str
|
||||||
//Diegox-17
|
//Diegox-17
|
||||||
// --- FIN DEL FIX ---
|
// --- FIN DEL FIX ---
|
||||||
|
|
||||||
|
messages := make([]providers.Message, 0, len(history)+2)
|
||||||
|
|
||||||
messages = append(messages, providers.Message{
|
messages = append(messages, providers.Message{
|
||||||
Role: "system",
|
Role: "system",
|
||||||
Content: systemPrompt,
|
Content: systemPrompt,
|
||||||
|
|
|
||||||
|
|
@ -307,7 +307,7 @@ func (c *LINEChannel) processEvent(event lineEvent) {
|
||||||
|
|
||||||
var content string
|
var content string
|
||||||
var mediaPaths []string
|
var mediaPaths []string
|
||||||
localFiles := []string{}
|
var localFiles []string
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, file := range localFiles {
|
for _, file := range localFiles {
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,7 @@ func (c *SlackChannel) handleMessageEvent(ev *slackevents.MessageEvent) {
|
||||||
content = c.stripBotMention(content)
|
content = c.stripBotMention(content)
|
||||||
|
|
||||||
var mediaPaths []string
|
var mediaPaths []string
|
||||||
localFiles := []string{} // 跟踪需要清理的本地文件
|
var localFiles []string // 跟踪需要清理的本地文件
|
||||||
|
|
||||||
// 确保临时文件在函数返回时被清理
|
// 确保临时文件在函数返回时被清理
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
||||||
|
|
@ -212,9 +212,9 @@ func (c *TelegramChannel) handleMessage(ctx context.Context, message *telego.Mes
|
||||||
chatID := message.Chat.ID
|
chatID := message.Chat.ID
|
||||||
c.chatIDs[senderID] = chatID
|
c.chatIDs[senderID] = chatID
|
||||||
|
|
||||||
content := ""
|
var content string
|
||||||
mediaPaths := []string{}
|
var mediaPaths []string
|
||||||
localFiles := []string{} // 跟踪需要清理的本地文件
|
var localFiles []string // 跟踪需要清理的本地文件
|
||||||
|
|
||||||
// 确保临时文件在函数返回时被清理
|
// 确保临时文件在函数返回时被清理
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,8 @@ func PrintPlan(actions []Action, warnings []string) {
|
||||||
|
|
||||||
func PrintSummary(result *Result) {
|
func PrintSummary(result *Result) {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
parts := []string{}
|
var parts []string
|
||||||
|
|
||||||
if result.FilesCopied > 0 {
|
if result.FilesCopied > 0 {
|
||||||
parts = append(parts, fmt.Sprintf("%d files copied", result.FilesCopied))
|
parts = append(parts, fmt.Sprintf("%d files copied", result.FilesCopied))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue